From dcba3c23031d13f8b54833c2d34c62cfabdb9f3b Mon Sep 17 00:00:00 2001 From: Isaac Milarsky Date: Sun, 27 Oct 2024 14:02:21 -0400 Subject: [PATCH] fix libyear parse Signed-off-by: Isaac Milarsky --- .../libyear_util/pypi_parser.py | 6 +- .../libyear_util/util.py | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/augur/tasks/git/dependency_libyear_tasks/libyear_util/pypi_parser.py b/augur/tasks/git/dependency_libyear_tasks/libyear_util/pypi_parser.py index dab06b1a09..1824322f48 100644 --- a/augur/tasks/git/dependency_libyear_tasks/libyear_util/pypi_parser.py +++ b/augur/tasks/git/dependency_libyear_tasks/libyear_util/pypi_parser.py @@ -140,12 +140,12 @@ def parse_poetry_lock(file_handle): group = 'runtime' for package in manifest['package']: req = None - if package['category'] == 'main': + if package.get('category') == 'main': group = 'runtime' - if package['category'] == 'dev': + if package.get('category') == 'dev': group = 'develop' if 'version' in package: - req = package['version'] + req = package.get('version') elif 'git' in package: req = package['git']+'#'+package['ref'] Dict = {'name': package['name'], 'requirement': req, 'type': group, 'package': 'PYPI'} diff --git a/augur/tasks/git/dependency_libyear_tasks/libyear_util/util.py b/augur/tasks/git/dependency_libyear_tasks/libyear_util/util.py index 111d3fc631..ffa2d4a84a 100644 --- a/augur/tasks/git/dependency_libyear_tasks/libyear_util/util.py +++ b/augur/tasks/git/dependency_libyear_tasks/libyear_util/util.py @@ -32,54 +32,56 @@ def get_parsed_deps(path,logger): deps_file = None dependency_list = list() - for f in file_list: deps_file = find(f, path) - if not deps_file: + + if not deps_file or not f: continue file_handle= open(deps_file) - if f == 'Requirement.txt': - dependency_list = parse_requirement_txt(file_handle) + short_file_name = os.path.split(deps_file)[-1] + + if short_file_name == 'Requirement.txt': + dependency_list.extend(parse_requirement_txt(file_handle)) - elif f == 'requirements.txt': - dependency_list = parse_requirement_txt(file_handle) + if short_file_name == 'requirements.txt': + dependency_list.extend(parse_requirement_txt(file_handle)) - elif f == 'setup.py': - dependency_list = parse_setup_py(file_handle) + if short_file_name == 'setup.py': + dependency_list.extend(parse_setup_py(file_handle)) - elif f == 'Pipfile': - dependency_list = parse_pipfile(file_handle) + if short_file_name == 'Pipfile': + dependency_list.extend(parse_pipfile(file_handle)) - elif f == 'Pipfile.lock': - dependency_list = parse_pipfile_lock(file_handle) + if short_file_name == 'Pipfile.lock': + dependency_list.extend(parse_pipfile_lock(file_handle)) - elif f == 'pyproject.toml': - dependency_list = parse_poetry(file_handle) + if short_file_name == 'pyproject.toml': + dependency_list.extend(parse_poetry(file_handle)) - elif f == 'poetry.lock': - dependency_list = parse_poetry_lock(file_handle) + if short_file_name == 'poetry.lock': + dependency_list.extend(parse_poetry_lock(file_handle)) - elif f == 'environment.yml': - dependency_list = parse_conda(file_handle) + if short_file_name == 'environment.yml': + dependency_list.extend(parse_conda(file_handle)) - elif f == 'environment.yaml': - dependency_list = parse_conda(file_handle) + if short_file_name == 'environment.yaml': + dependency_list.extend(parse_conda(file_handle)) - elif f == 'environment.yml.lock': - dependency_list = parse_conda(file_handle) + if f == 'environment.yml.lock': + dependency_list.extend(parse_conda(file_handle)) - elif f == 'environment.yaml.lock': - dependency_list = parse_conda(file_handle) + if short_file_name == 'environment.yaml.lock': + dependency_list.extend(parse_conda(file_handle)) - elif f == 'package.json': + if short_file_name == 'package.json': try: - dependency_list = parse_package_json(file_handle) + dependency_list.extend(parse_package_json(file_handle)) except KeyError as e: logger.error(f"package.json for repo at path {path} is missing required key: {e}\n Skipping file...") - return dependency_list + return dependency_list def get_libyear(current_version, current_release_date, latest_version, latest_release_date):