Skip to content

Conversation

claui
Copy link

@claui claui commented May 21, 2024

Installing the wheel and then running the polymidiexport executable leads to a ModuleNotFound error:

$ cd "$(mktemp -d)"
$ python -m venv .venv
$ . .venv/bin/activate
$ pip install polyendtracker-midi-export==0.3.2
$ polymidiexport
Traceback (most recent call last):
  File "/tmp/tmp.HDmTtQbmHc/.venv/bin/polymidiexport", line 5, in <module>
    from polytracker2midi import main
ModuleNotFoundError: No module named 'polytracker2midi'

The root cause of this error is a feature mismatch in the build system.
While setuptools is built around Python packages, the polytracker2midi.py file is actually just a Python script (and module) but not a package. Therefore, setuptools ignores that file and its sibling, polytracker2text.py. The wheel is then published to PyPI without those modules.

To work around the issue, convert both files to packages. That way, they can still be invoked via python (you just have to drop the .py), and setuptools will pick them up as packages and include them in the wheel.

(Note: an alternative solution would have been to switch to a different build system, e.g. Poetry, which supports single-file scripts and includes them in wheels as if they were packages. However, switching to Poetry would involve converting setup.py to a pyproject.toml file, an effort probably not worth the hassle, given that setuptools has worked just fine for this project so far.)

Installing the wheel and then running the `polymidiexport` executable
leads to a `ModuleNotFound` error:

```sh
$ cd "$(mktemp -d)"
$ python -m venv .venv
$ . .venv/bin/activate
$ pip install polyendtracker-midi-export==0.3.2
$ polymidiexport
Traceback (most recent call last):
  File "/tmp/tmp.HDmTtQbmHc/.venv/bin/polymidiexport", line 5, in <module>
    from polytracker2midi import main
ModuleNotFoundError: No module named 'polytracker2midi'
```

The root cause of this error is a feature mismatch in the build system.
While setuptools is built around Python packages, the
`polytracker2midi.py` file is actually just a Python script (and module)
but not a package. Therefore, `setuptools` ignores that file and its
sibling, `polytracker2text.py`. The wheel is then published to PyPI
without those modules.

To work around the issue, convert both files to packages. That way, they
can still be invoked via `python` (you just have to drop the `.py`), and
setuptools will pick them up as packages and include them in the wheel.

(Note: an alternative solution would have been to switch to a different
build system, e.g. Poetry, which supports single-file scripts and
includes them in wheels as if they were packages. However, switching to
Poetry would involve converting `setup.py` to a `pyproject.toml` file,
an effort probably not worth the hassle, given that setuptools has
worked just fine for this project so far.)
@claui
Copy link
Author

claui commented Feb 25, 2025

@DataGreed What can I do to help get this merged?

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

Successfully merging this pull request may close these issues.

1 participant