Skip to content

Commit c71d793

Browse files
committed
feat: if caller folder is a buildable package folder, look for metadata also within the caller folder
1 parent 617dc54 commit c71d793

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

version_query/py_query.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,26 @@ def query_pkg_info(path: pathlib.Path) -> Version:
2929

3030
def query_package_folder(path: pathlib.Path, search_parent_directories: bool = False) -> Version:
3131
"""Get version from Python package folder."""
32+
global_metadata_json_paths, global_pkg_info_paths = [], []
33+
if path.joinpath('pyproject.toml').exists() or path.joinpath('setup.py').exists():
34+
metadata_json_paths = list(path.glob('*.dist-info/metadata.json'))
35+
pkg_info_paths = list(path.glob('*.egg-info/PKG-INFO'))
36+
pkg_info_paths += list(path.glob('*.dist-info/METADATA'))
37+
if len(metadata_json_paths) == 1 and not pkg_info_paths:
38+
return query_metadata_json(metadata_json_paths[0])
39+
if not metadata_json_paths and len(pkg_info_paths) == 1:
40+
return query_pkg_info(pkg_info_paths[0])
41+
_LOG.debug(
42+
'in %s found pyproject.toml or setup.py, as well as'
43+
' %i JSON metadata: %s and %i PKG-INFO metadata: %s'
44+
' - unable to infer package metadata, continuing search',
45+
path, len(metadata_json_paths), metadata_json_paths, len(pkg_info_paths),
46+
pkg_info_paths)
47+
global_metadata_json_paths.extend(metadata_json_paths)
48+
global_pkg_info_paths.extend(pkg_info_paths)
3249
paths = [path]
3350
if search_parent_directories:
3451
paths += path.parents
35-
global_metadata_json_paths, global_pkg_info_paths = [], []
3652
for pth in paths:
3753
metadata_json_paths = list(pth.parent.glob(f'{pth.name}*.dist-info/metadata.json'))
3854
pkg_info_paths = list(pth.parent.glob(f'{pth.name}*.egg-info/PKG-INFO'))

0 commit comments

Comments
 (0)