← 输入框|github.com|刷新
Skip to content

Documented direct wheel execution fails before the __main__ bootstrap runs #530

In review

Description

@SonicHedghog

Which version of Python is the problem with?

3.10

What semver version are you using?

3.2.0

What OS are you using? (Add more in the Environment section)

Linux

Situation

semver/__main__.py documents that a wheel can be run directly like this:

$ python3 semver-3*-py3-none-any.whl/semver -h

That invocation currently fails before the compatibility bootstrap in main() can run. The module imports from semver import cli at top level, but the wheel path is inserted into sys.path only later inside main().

How to reproduce

$ python3 -m pip download --no-deps semver==3.2.0
$ python3 semver-3.2.0-py3-none-any.whl/semver -h

Output:

Traceback (most recent call last):
  ...
  File ".../semver-3.2.0-py3-none-any.whl/semver/__main__.py", line 17, in <module>
    from semver import cli
ModuleNotFoundError: No module named 'semver'

For comparison, using the wheel as a normal sys.path entry works:

$ PYTHONPATH=semver-3.2.0-py3-none-any.whl python3 -m semver -h
usage: semver [-h] [--version] {compare,bump,check,nextver} ...

Expected behavior

The documented direct-wheel invocation should display the CLI help instead of raising ModuleNotFoundError.

A possible resolution would be to perform the __package__ == "" path adjustment before importing semver.cli, or to move the cli import inside main() after that adjustment. I would be happy to implement either approach with a regression test if you think this documented execution mode should continue to be supported.

Environment

Reproduced with the semver 3.2.0 wheel from PyPI on CPython 3.10/Linux. The same import order is present on current master.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    SIze

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions