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

Check for entry points correctness? #40

Open
wimglenn opened this issue May 15, 2024 · 0 comments
Open

Check for entry points correctness? #40

wimglenn opened this issue May 15, 2024 · 0 comments

Comments

@wimglenn
Copy link

I put a wheel at https://test.pypi.org/project/issue40/#files which build was happy to build, twine was happy to push, and check-wheel-contents is happy with:

$ pip download issue40 --index-url=https://test.pypi.org/simple
...
$ check-wheel-contents issue40-0.0.1-py3-none-any.whl 
issue40-0.0.1-py3-none-any.whl: OK

Pip is happy to install it and create its console script entrypoint

$ pip install ./issue40-0.0.1-py3-none-any.whl
Processing ./issue40-0.0.1-py3-none-any.whl
Installing collected packages: issue40
Successfully installed issue40-0.0.1
$ cat .venv/lib/python3.12/site-packages/issue40-0.0.1.dist-info/entry_points.txt 
[console_scripts]
hello = mypkg:hello_world
$ cat .venv/lib/python3.12/site-packages/mypkg/__init__.py 
def helloworld():
    print("hello, world!!")

But it has a problem - typo in the entrypoint, or maybe a function was renamed and forgetting to also rename the metadata in the toml at the same time:

$ hello
Traceback (most recent call last):
  File "/private/tmp/i/.venv/bin/hello", line 5, in <module>
    from mypkg import hello_world
ImportError: cannot import name 'hello_world' from 'mypkg' (/private/tmp/i/.venv/lib/python3.12/site-packages/mypkg/__init__.py). Did you mean: 'helloworld'?

Do you think this is something in scope for check-wheel-contents? Some warning or info if they don't appear to resolve somewhere sensible within the package? It could use some static analysis (ast) so that it doesn't need to import any code to look for that.

Here is a source tree to create this wheel

.
├── mypkg
│   └── __init__.py
└── pyproject.toml

mypkg/__init__.py

def helloworld():
    print("hello, world!!")

pyproject.toml

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "issue40"
version = "0.0.1"

[tool.setuptools]
packages = ["mypkg"]

[project.scripts]
hello = "mypkg:hello_world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant