pypa/build

`FileNotFoundError` not happening when passing an option of `--sdist` or `--wheel`

mbyrnepr2 opened this issue · 2 comments

Hi folks, I have a question regarding the default behaviour of python -m build vs. passing one of the options e.g. python -m --wheel in a particular situation.

Let's say there is a setup.py with the following content:

from setuptools import setup

with open('requirements.txt') as f:
    requirements = f.read().splitlines()

setup(
    name="tmp_project",
    version="1.0.0",
    install_requires=requirements,
)

The result of python -m build looks correct since there is no MANIFEST.in file which includes the requirements.txt:

Traceback (most recent call last):
  File "/Users/markbyrne/venv311/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
  File "/Users/markbyrne/venv311/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/markbyrne/venv311/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/xg/8_fbv0_n2zqb9zzrh2kv66wm0000gn/T/build-env-qrxj6ktn/lib/python3.11/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/folders/xg/8_fbv0_n2zqb9zzrh2kv66wm0000gn/T/build-env-qrxj6ktn/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
    self.run_setup()
  File "/private/var/folders/xg/8_fbv0_n2zqb9zzrh2kv66wm0000gn/T/build-env-qrxj6ktn/lib/python3.11/site-packages/setuptools/build_meta.py", line 507, in run_setup
    super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_script)
  File "/private/var/folders/xg/8_fbv0_n2zqb9zzrh2kv66wm0000gn/T/build-env-qrxj6ktn/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in run_setup
    exec(code, locals())
  File "<string>", line 3, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel

But if we do a python -m build --wheel there is no FileNotFoundError like above and both sdist and wheel files are created successfully. Should the error also be emitted in this latter case? Afterwards a pip install <sdist> will result in the FileNotFoundError being produced.

Thank you!

I believe this behaviour is intentional.

The general recommendation is indeed for the users to just run python -m build so that all wheels are generated from the sdist, which in turn helps to test that the package configuration is working as intended.

The CLI does however offer the option for users to bypass one step of this workflow. This might be wanted in the case of build speed, for example; but then since the user explicitly opted to add this option, this also means that the user has the onus of manually doing the test they choose to bypass.

Thanks for the rationale @abravalheri ❤️. I'm not sure about the etiquette but if someone wishes to close this please go ahead.