Skip to content

Commit

Permalink
feat: if caller folder is a buildable package folder, look for metada…
Browse files Browse the repository at this point in the history
…ta also within the caller folder
  • Loading branch information
mbdevpl committed Feb 16, 2025
1 parent 617dc54 commit c71d793
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion version_query/py_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Check warning on line 38 in version_query/py_query.py

View check run for this annotation

Codecov / codecov/patch

version_query/py_query.py#L38

Added line #L38 was not covered by tests
if not metadata_json_paths and len(pkg_info_paths) == 1:
return query_pkg_info(pkg_info_paths[0])

Check warning on line 40 in version_query/py_query.py

View check run for this annotation

Codecov / codecov/patch

version_query/py_query.py#L40

Added line #L40 was not covered by tests
_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'))
Expand Down

0 comments on commit c71d793

Please sign in to comment.