Python functions to get top-level importables names
0

Configure Feed

Select the types of activity you want to include in your feed.

Rename project

Juan Luis Cano Rodríguez (Dec 4, 2023, 10:09 PM +0100) d79b5509 0a450dc9

+32 -32
+1 -1
.github/workflows/rtd-preview.yml
··· 13 13 steps: 14 14 - uses: readthedocs/actions/preview@v1 15 15 with: 16 - project-slug: "pygetpackages" 16 + project-slug: "pygetimportables"
+1 -1
CONTRIBUTING.md
··· 2 2 3 3 ## Before contributing 4 4 5 - Welcome to pygetpackages! Before contributing to the project, 5 + Welcome to pygetimportables! Before contributing to the project, 6 6 make sure that you **read our code of conduct** (`CODE_OF_CONDUCT.md`). 7 7 8 8 ## Contributing code
+13 -13
README.md
··· 1 - # pygetpackages 1 + # pygetimportables 2 2 3 - [![Documentation Status](https://readthedocs.org/projects/pygetpackages/badge/?version=latest)](https://pygetpackages.readthedocs.io/en/latest/?badge=latest) 3 + [![Documentation Status](https://readthedocs.org/projects/pygetimportables/badge/?version=latest)](https://pygetimportables.readthedocs.io/en/latest/?badge=latest) 4 4 [![Code style: ruff-format](https://img.shields.io/badge/code%20style-ruff_format-6340ac.svg)](https://github.com/astral-sh/ruff) 5 - [![PyPI](https://img.shields.io/pypi/v/pygetpackages)](https://pypi.org/project/pygetpackages) 5 + [![PyPI](https://img.shields.io/pypi/v/pygetimportables)](https://pypi.org/project/pygetimportables) 6 6 7 - Python functions to get packages from a source tree and an already built wheel. 7 + Python functions to get top-level importable names from a source tree or an already built wheel. 8 8 9 9 See https://discuss.python.org/t/script-to-get-top-level-packages-from-source-tree/40232?u=astrojuanlu 10 10 ··· 13 13 To install, run 14 14 15 15 ``` 16 - (.venv) $ pip install pygetpackages 16 + (.venv) $ pip install pygetimportables 17 17 ``` 18 18 19 19 ## Usage 20 20 21 - To get the packages directly from a source tree: 21 + To get the top-level importable names directly from a source tree: 22 22 23 23 ``` 24 - >>> from pygetpackages import get_packages 25 - >>> get_packages(".") # Wait a few seconds, requires working `pip install` 26 - {'pygetpackages'} 24 + >>> from pygetimportables import get_top_importables 25 + >>> get_top_importables(".") # Wait a few seconds, requires working `pip install` 26 + {'pygetimportables'} 27 27 ``` 28 28 29 - To get packages from an already built wheel: 29 + To get the top-level importable names from an already built wheel: 30 30 31 31 ``` 32 32 (.venv) $ python -m build 33 33 ... 34 34 (.venv) $ python -q 35 - >>> from pygetpackages import get_packages_from_wheel 36 - >>> get_packages_from_wheel("dist/pygetpackages-0.1.0+d20231204-py3-none-any.whl") # Fast 37 - {'pygetpackages'} 35 + >>> from pygetimportables import get_top_importables_from_wheel 36 + >>> get_top_importables_from_wheel("dist/pygetimportables-0.1.0+d20231204-py3-none-any.whl") # Fast 37 + {'pygetimportables'} 38 38 ``` 39 39 40 40 ## Development
+1 -1
docs/source/conf.py
··· 4 4 5 5 # -- Project information 6 6 7 - _metadata = metadata("pygetpackages") 7 + _metadata = metadata("pygetimportables") 8 8 9 9 project = _metadata["Name"] 10 10 author = _metadata["Author-email"].split("<", 1)[0].strip()
+6 -6
pyproject.toml
··· 3 3 build-backend = "pdm.backend" 4 4 5 5 [project] 6 - name = "pygetpackages" 6 + name = "pygetimportables" 7 7 readme = "README.md" 8 8 requires-python = ">=3.8" 9 9 license = {file = "LICENSE"} 10 - description = "Python function that gets packages from a source tree" 10 + description = "Python functions to get top-level importable names" 11 11 dependencies = [ 12 12 "build", 13 13 "installer", ··· 34 34 dynamic = ["version"] 35 35 36 36 [project.urls] 37 - source = "https://github.com/astrojuanlu/pygetpackages" 38 - tracker = "https://github.com/astrojuanlu/pygetpackages/issues" 39 - documentation = "https://pygetpackages.readthedocs.io" 37 + source = "https://github.com/astrojuanlu/pygetimportables" 38 + tracker = "https://github.com/astrojuanlu/pygetimportables/issues" 39 + documentation = "https://pygetimportables.readthedocs.io" 40 40 41 41 [project.optional-dependencies] 42 42 test = [ ··· 95 95 96 96 # More strict checks for library code 97 97 [[tool.mypy.overrides]] 98 - module = "pygetpackages" 98 + module = "pygetimportables" 99 99 disallow_untyped_defs = true 100 100 101 101 # Ignore certain missing imports
+9 -9
src/pygetpackages/__init__.py src/pygetimportables/__init__.py
··· 1 - """Get the top-level packages of a Python project.""" 1 + """Get the top-level importable names of a Python project.""" 2 2 # The good parts come from https://gist.github.com/pradyunsg/22ca089b48ca55d75ca843a5946b2691 3 3 # Licensed under the MIT license. 4 4 # ··· 103 103 return importable_components 104 104 105 105 106 - def get_packages_from_wheel(wheel_path: str | Path) -> set[str]: 107 - """Get the top-level packages of a Python project from a wheel file.""" 106 + def get_top_importables_from_wheel(wheel_path: str | Path) -> set[str]: 107 + """Get the top-level importable names of a Python project from a wheel file.""" 108 108 with zipfile.ZipFile(wheel_path, "r") as zf: 109 109 wheel_file = WheelFile(zf) 110 110 importable_components = _get_importable_components_from_wheel(wheel_file) 111 - top_packages = _determine_major_import_names(importable_components) 111 + top_importables = _determine_major_import_names(importable_components) 112 112 113 - return top_packages 113 + return top_importables 114 114 115 115 116 - def get_packages( 116 + def get_top_importables( 117 117 source_dir: str | Path, *, build_config_settings: ConfigSettingsType | None = None 118 118 ) -> set[str]: 119 - """Get the top-level packages of a Python source tree.""" 119 + """Get the top-level importable names of a Python source tree.""" 120 120 pyproject_toml_path = Path(source_dir) / "pyproject.toml" 121 121 if not pyproject_toml_path.is_file(): 122 122 raise ValueError( ··· 141 141 wheel_path = _simple_build_wheel( 142 142 source_dir, outdir, build_config_settings=build_config_settings 143 143 ) 144 - top_packages = get_packages_from_wheel(wheel_path) 144 + top_importables = get_top_importables_from_wheel(wheel_path) 145 145 146 - return top_packages 146 + return top_importables
+1 -1
tox.ini
··· 51 51 [testenv:docs] 52 52 description = build HTML docs 53 53 setenv = 54 - READTHEDOCS_PROJECT = pygetpackages 54 + READTHEDOCS_PROJECT = pygetimportables 55 55 READTHEDOCS_VERSION = latest 56 56 extras = 57 57 doc