Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_baseline_stubs: improve package detection #7283

Merged

Conversation

Rogdham
Copy link
Contributor

@Rogdham Rogdham commented Feb 19, 2022

In current version, the create_baseline_stubs.py script defaults to the project name as the package name. This is not always the best choice (e.g. PyYAML and yaml), and the --package can be used in that case.

In this PR, I'm improving the default package detection when there is no --package flag. Because this script is run manually, I feel like it is ok to display a message saying to use --package flag if the detected package is not the wanted one.

I checked with the following projects:

  • redis defaults to redis
  • python-nmap defaults to nmap
  • PyYAML defaults to yaml (note that PyYAML also exports a _yaml module)

The improvement relies on importlib.metadata module, and fallbacks to current default (i.e. project name) if that fails or for Python < 3.8 (where that module does not exist).

The code for package detection is slightly inspired by packages_distributions in Python >= 3.10.

@Rogdham Rogdham force-pushed the create_baseline_stubs-detect_package branch from b4c70e4 to 17945b3 Compare Feb 19, 2022
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Thanks!

@hauntsaninja hauntsaninja merged commit 6e0520a into python:master Feb 19, 2022
57 checks passed
@Rogdham Rogdham deleted the create_baseline_stubs-detect_package branch Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants