Skip to content

Commit

Permalink
Merge pull request #548 from linode/dev
Browse files Browse the repository at this point in the history
Release v5.45.2
  • Loading branch information
lgarber-akamai authored Nov 9, 2023
2 parents 506c011 + b9bba92 commit 9b43cf8
Show file tree
Hide file tree
Showing 44 changed files with 698 additions and 299 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/e2e-suite-pr-command.yml

This file was deleted.

13 changes: 6 additions & 7 deletions .github/workflows/e2e-suite-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
inputs:
test_path:
description: 'Test path to be tested: e.g. integration/cli'
description: "The path from 'test/integration' to the target to be tested, e.g. 'cli'"
required: false
sha:
description: 'The hash value of the commit.'
Expand All @@ -30,7 +30,7 @@ jobs:

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

Expand All @@ -56,13 +56,12 @@ jobs:
owner: ${{ github.event.repository.owner.login }}
repo: ${{ github.event.repository.name }}
pr_num: ${{ fromJSON(inputs.pull_request_number) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update system packages
run: sudo apt-get update -y

- name: Install system deps
run: sudo apt-get install -y build-essential

- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -124,7 +123,7 @@ jobs:

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

Expand Down Expand Up @@ -196,4 +195,4 @@ jobs:
status: 'completed',
conclusion: process.env.conclusion
});
return result;
return result;
16 changes: 13 additions & 3 deletions .github/workflows/e2e-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
integration-tests:
name: Run integration tests
runs-on: ubuntu-latest
env:
EXIT_STATUS: 0
steps:
- name: Clone Repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -39,9 +41,8 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_cli_test_report.xml"
status=0
if ! pytest tests/integration --disable-warnings --junitxml="${report_filename}"; then
echo "Tests failed, but attempting to upload results anyway"
echo "EXIT_STATUS=1" >> $GITHUB_ENV
fi
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN }}
Expand All @@ -67,4 +68,13 @@ jobs:
env:
LINODE_CLI_TOKEN: ${{ secrets.SHARED_DX_TOKEN }}
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

- name: Test Execution Status Handler
run: |
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Test execution contains failure(s)"
exit $EXIT_STATUS
else
echo "Tests passed!"
fi
5 changes: 5 additions & 0 deletions .github/workflows/remote-release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ jobs:
return "v" + cli_version_segments.join(".")
- name: Calculate the SHA of HEAD on the main branch
id: calculate_head_sha
run: echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- uses: rickstaa/action-create-tag@84c90e6ba79b47b5147dcb11ff25d6a0e06238ba # pin@v1
with:
tag: ${{ steps.calculate_version.outputs.result }}
commit_sha: ${{ steps.calculate_head_sha.outputs.commit_sha }}

- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # pin@v1
Expand Down
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ min-public-methods=2
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception


[FORMAT]
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ endif
install: check-prerequisites requirements build
pip3 install --force dist/*.whl

.PHONY: build
build: clean
.PHONY: bake
bake: clean
python3 -m linodecli bake ${SPEC} --skip-config
cp data-3 linodecli/

.PHONY: build
build: clean bake
python3 -m build --wheel --sdist

.PHONY: requirements
Expand Down
4 changes: 2 additions & 2 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import argparse
import os
import sys
from importlib.metadata import version
from sys import argv

import pkg_resources
from rich import print as rprint
from rich.table import Table

Expand All @@ -30,7 +30,7 @@

# this might not be installed at the time of building
try:
VERSION = pkg_resources.require("linode-cli")[0].version
VERSION = version("linode-cli")
except:
VERSION = "building"

Expand Down
5 changes: 4 additions & 1 deletion linodecli/arg_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ def action_help(cli, command, action):
if op.method in {"post", "put"} and arg.required
else ""
)
print(f" --{arg.path}: {is_required}{arg.description}")
nullable_fmt = " (nullable)" if arg.nullable else ""
print(
f" --{arg.path}: {is_required}{arg.description}{nullable_fmt}"
)


def bake_command(cli, spec_loc):
Expand Down
27 changes: 25 additions & 2 deletions linodecli/baked/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from os import environ, path
from typing import List, Tuple

from openapi3.paths import Operation

from linodecli.baked.request import OpenAPIFilteringRequest, OpenAPIRequest
from linodecli.baked.response import OpenAPIResponse
from linodecli.overrides import OUTPUT_OVERRIDES
Expand Down Expand Up @@ -76,6 +78,27 @@ def type_func(value):
return type_func


class ArrayAction(argparse.Action):
"""
This action is intended to be used only with array arguments.
This purpose of this action is to allow users to specify explicitly
empty lists using a singular "[]" argument value.
"""

def __call__(self, parser, namespace, values, option_string=None):
if getattr(namespace, self.dest) is None:
setattr(namespace, self.dest, [])

output_list = getattr(namespace, self.dest)

# If the output list is empty and the user specifies a []
# argument, keep the list empty
if values == "[]" and len(output_list) < 1:
return

output_list.append(values)


class ListArgumentAction(argparse.Action):
"""
This action is intended to be used only with list arguments.
Expand Down Expand Up @@ -212,7 +235,7 @@ class OpenAPIOperation:
This is the class that should be pickled when building the CLI.
"""

def __init__(self, command, operation, method, params):
def __init__(self, command, operation: Operation, method, params):
"""
Wraps an openapi3.Operation object and handles pulling out values relevant
to the Linode CLI.
Expand Down Expand Up @@ -380,7 +403,7 @@ def _add_args_post_put(self, parser) -> List[Tuple[str, str]]:
parser.add_argument(
"--" + arg.path,
metavar=arg.name,
action="append",
action=ArrayAction,
type=arg_type_handler,
)
elif arg.list_item:
Expand Down
53 changes: 33 additions & 20 deletions linodecli/baked/response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Converting the processed OpenAPI Responses into something the CLI can work with
"""
from openapi3.paths import MediaType

from .colors import colorize_string


Expand Down Expand Up @@ -159,26 +161,35 @@ def _parse_response_model(schema, prefix=None, nested_list_depth=0):
:returns: The list of parsed OpenAPIResponseAttr objects representing this schema
:rtype: List[OpenAPIResponseAttr]
"""
attrs = []

if schema.properties is not None:
for k, v in schema.properties.items():
pref = prefix + "." + k if prefix else k

if v.type == "object":
attrs += _parse_response_model(v, prefix=pref)
elif v.type == "array" and v.items.type == "object":
attrs += _parse_response_model(
v.items,
prefix=pref,
nested_list_depth=nested_list_depth + 1,
)
else:
attrs.append(
OpenAPIResponseAttr(
k, v, prefix=prefix, nested_list_depth=nested_list_depth
)
if schema.type == "array":
return _parse_response_model(
schema.items,
prefix=prefix,
nested_list_depth=nested_list_depth,
)

attrs = []
if schema.properties is None:
return attrs

for k, v in schema.properties.items():
pref = prefix + "." + k if prefix else k

if v.type == "object":
attrs += _parse_response_model(v, prefix=pref)
elif v.type == "array" and v.items.type == "object":
attrs += _parse_response_model(
v.items,
prefix=pref,
nested_list_depth=nested_list_depth + 1,
)
else:
attrs.append(
OpenAPIResponseAttr(
k, v, prefix=prefix, nested_list_depth=nested_list_depth
)
)

return attrs

Expand All @@ -189,7 +200,7 @@ class OpenAPIResponse:
responses section of an OpenAPI Operation
"""

def __init__(self, response):
def __init__(self, response: MediaType):
"""
:param response: The response's MediaType object in the OpenAPI spec,
corresponding to the application/json response type
Expand Down Expand Up @@ -228,7 +239,9 @@ def fix_json(self, json):
# Needs to go last to handle custom schemas
if "pages" in json:
return json["data"]
return [json]
if not isinstance(json, list):
json = [json]
return json

def _fix_json_rows(self, json):
"""
Expand Down
Loading

0 comments on commit 9b43cf8

Please sign in to comment.