Skip to content

Commit 355be96

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

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

version_query/py_query.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@ 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+
global_metadata_json_paths.extend(metadata_json_paths)
42+
global_pkg_info_paths.extend(pkg_info_paths)
3243
paths = [path]
3344
if search_parent_directories:
3445
paths += path.parents
35-
global_metadata_json_paths, global_pkg_info_paths = [], []
3646
for pth in paths:
3747
metadata_json_paths = list(pth.parent.glob(f'{pth.name}*.dist-info/metadata.json'))
3848
pkg_info_paths = list(pth.parent.glob(f'{pth.name}*.egg-info/PKG-INFO'))

0 commit comments

Comments
 (0)