Skip to content

Commit

Permalink
Merge pull request #6 from jan-rycko/master
Browse files Browse the repository at this point in the history
package_versions_command.
  • Loading branch information
m-j authored Apr 13, 2022
2 parents 9515cd6 + b64a142 commit 40e1ab3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
9 changes: 0 additions & 9 deletions commands/package_version_command.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import json
from distutils.version import LooseVersion
from os import getcwd
from pathlib import Path

from commands.publish_command import get_api_key
from error_handling.exceptions import ZipperoClientException
from packages.api_client import ApiClient
from packages.package_utils import get_newest_package_from_package_info
from utils.args_utils import get_directory_or_cwd
from utils.constants import zpspec_file_name
from utils.zpspec_utils import load_zpspec

def common_format(s: str):
return s.strip().lower()
Expand Down
22 changes: 22 additions & 0 deletions commands/package_versions_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from commands.publish_command import get_api_key
from packages.api_client import ApiClient
from packages.package_utils import get_package_versions

def common_format(s: str):
return s.strip().lower()


def package_versions_command(args):
package = args.package

repository = args.repository

api_key = get_api_key(args)
api_client = ApiClient(repository, api_key)

response_json = api_client.get_package_info(package)

versions = get_package_versions(response_json)

for version in versions:
print(version)
9 changes: 8 additions & 1 deletion commands/publish_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from error_handling.error_handlers import is_error_response, throw_response_error
from packages.api_client import ApiClient
from error_handling.exceptions import ZipperoClientException
from utils.constants import api_key_header, api_key_environment_variable


Expand All @@ -25,6 +26,12 @@ def publish_command(args):
api_client = ApiClient(repository, api_key)

with open(file_path, 'rb') as file:
api_client.post_package(file)
try:
api_client.post_package(file)
except Exception as ex:
if not issubclass(type(ex), ZipperoClientException):
raise ZipperoClientException(f'Failed to post package from {file_path}')
else:
raise ZipperoClientException(f'Failed to post package from {file_path} with message {ex.message}')

print(f'Package {file_path} published')
7 changes: 7 additions & 0 deletions commands/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from commands.publish_command import publish_command
from commands.version_check_command import version_check_command
from commands.package_version_command import package_version_command
from commands.package_versions_command import package_versions_command
from error_handling.exceptions import ZipperoClientException
from utils.constants import api_key_environment_variable
from commands.version_check_command import up_to_date_string, outdated_string
Expand Down Expand Up @@ -53,6 +54,12 @@ def configure_argparser() -> argparse.ArgumentParser:
package_version_parser.add_argument('--repository', '-r', type=str, help='url to target repository')
package_version_parser.add_argument('--key', '-k', type=str, help=f'api key to use if not provided will use {api_key_environment_variable}')

package_versions_parser = subparsers.add_parser('package-versions', help=f'checks package latest version.')
package_versions_parser.set_defaults(handler=package_versions_command)
package_versions_parser.add_argument('package', type=str, help='name of package')
package_versions_parser.add_argument('--repository', '-r', type=str, help='url to target repository')
package_versions_parser.add_argument('--key', '-k', type=str, help=f'api key to use if not provided will use {api_key_environment_variable}')

install_parser = subparsers.add_parser('prefetch', help='prefetches package to local cache')
install_parser.set_defaults(handler=prefetch_command)
install_parser.add_argument('package', type=str, help='name of package or name@version e.g. [email protected]')
Expand Down
13 changes: 12 additions & 1 deletion packages/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ def get_newest_package_from_package_info(package_info: Dict):
versions.sort(key=LooseVersion)

newest_version = versions[-1]
return newest_version
return newest_version


def get_package_versions(package_info: Dict):
versions = package_info['data']['versions'].copy()

if len(versions) == 0:
raise ZipperoClientException(f'No versions of {zpspec_name} found')

versions.sort(key=LooseVersion)

return versions

0 comments on commit 40e1ab3

Please sign in to comment.