From 554fb3d17046e6e4427ea4fe9ed08814c16626ef Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Sun, 16 Feb 2025 18:15:52 +0900 Subject: [PATCH 1/4] feat: add more output related to debugging issues with finding metadata --- version_query/py_query.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/version_query/py_query.py b/version_query/py_query.py index 967e086..9232993 100644 --- a/version_query/py_query.py +++ b/version_query/py_query.py @@ -32,7 +32,7 @@ def query_package_folder(path: pathlib.Path, search_parent_directories: bool = F paths = [path] if search_parent_directories: paths += path.parents - metadata_json_paths, pkg_info_paths = None, None + global_metadata_json_paths, global_pkg_info_paths = [], [] for pth in paths: metadata_json_paths = list(pth.parent.glob(f'{pth.name}*.dist-info/metadata.json')) pkg_info_paths = list(pth.parent.glob(f'{pth.name}*.egg-info/PKG-INFO')) @@ -41,4 +41,13 @@ def query_package_folder(path: pathlib.Path, search_parent_directories: bool = F return query_metadata_json(metadata_json_paths[0]) if not metadata_json_paths and len(pkg_info_paths) == 1: return query_pkg_info(pkg_info_paths[0]) - raise ValueError(paths, metadata_json_paths, pkg_info_paths) + _LOG.debug( + 'in %s found %i JSON metadata: %s and %i PKG-INFO metadata: %s' + ' - unable to infer package metadata, continuing search', + pth, len(metadata_json_paths), metadata_json_paths, len(pkg_info_paths), pkg_info_paths) + global_metadata_json_paths.extend(metadata_json_paths) + global_pkg_info_paths.extend(pkg_info_paths) + raise ValueError( + f'unable to infer package metadata from the following paths {paths} ' + f'- found {len(global_metadata_json_paths)} JSON metadata: {global_metadata_json_paths}' + f' and {len(global_pkg_info_paths)} PKG-INFO metadata: {global_pkg_info_paths}') From 617dc54b6083ef8b7f805453af1c865ea882a7fe Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Sun, 16 Feb 2025 18:44:16 +0900 Subject: [PATCH 2/4] fix: handle case when calling code is determined to be a "" instead of a file --- version_query/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_query/query.py b/version_query/query.py index fe6d8ae..253c3bb 100644 --- a/version_query/query.py +++ b/version_query/query.py @@ -19,7 +19,7 @@ def _caller_folder(stack_level: int = 1) -> pathlib.Path: caller_path = frame_info[1] # frame_info.filename here = pathlib.Path(caller_path).absolute().resolve() - assert here.is_file(), here + assert here.is_file() or here.name == '', here here = here.parent assert here.is_dir(), here _LOG.debug('found directory "%s"', here) From c71d7930cd9e48044c00f062785ee3910ce3438d Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Sun, 16 Feb 2025 18:58:19 +0900 Subject: [PATCH 3/4] feat: if caller folder is a buildable package folder, look for metadata also within the caller folder --- version_query/py_query.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/version_query/py_query.py b/version_query/py_query.py index 9232993..e4a8dcf 100644 --- a/version_query/py_query.py +++ b/version_query/py_query.py @@ -29,10 +29,26 @@ def query_pkg_info(path: pathlib.Path) -> Version: def query_package_folder(path: pathlib.Path, search_parent_directories: bool = False) -> Version: """Get version from Python package folder.""" + global_metadata_json_paths, global_pkg_info_paths = [], [] + if path.joinpath('pyproject.toml').exists() or path.joinpath('setup.py').exists(): + metadata_json_paths = list(path.glob('*.dist-info/metadata.json')) + pkg_info_paths = list(path.glob('*.egg-info/PKG-INFO')) + pkg_info_paths += list(path.glob('*.dist-info/METADATA')) + if len(metadata_json_paths) == 1 and not pkg_info_paths: + return query_metadata_json(metadata_json_paths[0]) + if not metadata_json_paths and len(pkg_info_paths) == 1: + return query_pkg_info(pkg_info_paths[0]) + _LOG.debug( + 'in %s found pyproject.toml or setup.py, as well as' + ' %i JSON metadata: %s and %i PKG-INFO metadata: %s' + ' - unable to infer package metadata, continuing search', + path, len(metadata_json_paths), metadata_json_paths, len(pkg_info_paths), + pkg_info_paths) + global_metadata_json_paths.extend(metadata_json_paths) + global_pkg_info_paths.extend(pkg_info_paths) paths = [path] if search_parent_directories: paths += path.parents - global_metadata_json_paths, global_pkg_info_paths = [], [] for pth in paths: metadata_json_paths = list(pth.parent.glob(f'{pth.name}*.dist-info/metadata.json')) pkg_info_paths = list(pth.parent.glob(f'{pth.name}*.egg-info/PKG-INFO')) From 4b2e6e0f66af2cafbb68de6c8d68a4e0ee7f73ec Mon Sep 17 00:00:00 2001 From: Mateusz Bysiek Date: Sun, 16 Feb 2025 22:35:51 +0900 Subject: [PATCH 4/4] test: add a test for latest added feature --- .github/workflows/python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 647d244..4ec148a 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -51,6 +51,8 @@ jobs: - run: python -m coverage run --append --branch --source . -m unittest -v test.test_version env: LOGGING_LEVEL: critical + - run: python -m pip install -e . + - run: python -m coverage run --append --branch --source . -m pip install --no-build-isolation --no-binary ebrains-drive ebrains-drive==0.6.0 - run: python -m coverage report --show-missing - run: codecov publish: