Metadata-Version: 2.4
Name: packagediscovery
Version: 0.2.0
Summary: Package discovery based on Setuptools.
Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Yukihiko Shinoda
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/yukihiko-shinoda/package-discovery
Project-URL: repository, https://github.com/yukihiko-shinoda/package-discovery
Keywords: setuptools,package,discovery
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Debuggers
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Software Distribution
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: setuptools>=61.0.0
Dynamic: license-file

# Package Discovery

[![Test](https://github.com/yukihiko-shinoda/package-discovery/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/package-discovery/actions?query=workflow%3ATest)
[![CodeQL](https://github.com/yukihiko-shinoda/package-discovery/workflows/CodeQL/badge.svg)](https://github.com/yukihiko-shinoda/package-discovery/actions?query=workflow%3ACodeQL)
[![Code Coverage](https://qlty.sh/gh/yukihiko-shinoda/projects/package-discovery/coverage.svg)](https://qlty.sh/gh/yukihiko-shinoda/projects/package-discovery)
[![Maintainability](https://qlty.sh/gh/yukihiko-shinoda/projects/package-discovery/maintainability.svg)](https://qlty.sh/gh/yukihiko-shinoda/projects/package-discovery)
[![Dependabot](https://flat.badgen.net/github/dependabot/yukihiko-shinoda/package-discovery?icon=dependabot)](https://github.com/yukihiko-shinoda/package-discovery/security/dependabot)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/packagediscovery)](https://pypi.org/project/packagediscovery)
[![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fpackage-discovery)](http://twitter.com/share?text=Package%20Discovery&url=https://pypi.org/project/packagediscovery/&hashtags=python)

Package discovery based on Setuptools.

## Advantage

1. Debug packages that Setuptools discovered
2. Easy to filter packages to root packages only

### 1. Debug packages that Setuptools discovered

You can check the discovered packages by running the following Python code.

print_packages.py:

```python
from packagediscovery import Setuptools

print(Setuptools().packages)
```

```bash
$ python print_packages.py
['packagediscovery']
```

Since Package Discovery settings of Setuptools is a bit complicated so that we may want to know what packages Setuptools are discovering now.

cf. [Package Discovery and Namespace Packages - setuptools documentation]

### 2. Easy to filter packages to root packages only

You can filter the discovered packages to only include root packages by using the `root_packages` property.

filter_packages.py:

```python
from packagediscovery import Packages, Setuptools

setuptools = Setuptools()
print(f"Packages = {setuptools.packages}")
print(f"Root packages = {Packages(setuptools.packages).list_roots_only}")
```

```bash
$ python filter_packages.py
Packages = ['pyvelocity', 'pyvelocity.checks', 'pyvelocity.configurations', 'pyvelocity.configurations.files', 'pyvelocity.configurations.files.sections', 'pyvelocity.configurations.files.sections.pylint', 'pyvelocity.configurations.tools', 'pyvelocity.configurations.files.sections.pylint', 'pyvelocity.configurations.files.sections', 'pyvelocity.configurations.files', 'pyvelocity.checks', 'pyvelocity.configurations.tools', 'pyvelocity.configurations']
Root packages = ['pyvelocity']
```

## Quickstart

Install the package

```bash
$ pip install packagediscovery
```

<!-- markdownlint-disable no-trailing-punctuation -->
## How do I...
<!-- markdownlint-enable no-trailing-punctuation -->

### Discover packages

```python
from packagediscovery import Setuptools

setuptools = Setuptools()
print(f"Packages = {setuptools.packages}")
```

### Discover py modules

```python
from packagediscovery import Setuptools

setuptools = Setuptools()
print(f"Py modules = {setuptools.py_modules}")
```

### Discover project root

```python
from packagediscovery import Setuptools

setuptools = Setuptools()
print(f"Project root = {setuptools.project_root}")
```

### Filter packages to root packages only

```python
from packagediscovery import Setuptools

setuptools = Setuptools()
print(f"Packages = {setuptools.packages}")
print(f"Root packages = {Packages(setuptools.packages).list_roots_only}")
```

## Credits

This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.

[Cookiecutter]: https://github.com/audreyr/cookiecutter
[yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
[Package Discovery and Namespace Packages - setuptools documentation]: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
