Skip to content

Fix building package with venv #112

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rstam-exs
Copy link

@rstam-exs rstam-exs commented Oct 20, 2021

Hi
I tried creating a package on my system and found that the build process fails:

* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for sdist...
running egg_info
writing checksec.py.egg-info/PKG-INFO
writing dependency_links to checksec.py.egg-info/dependency_links.txt
writing entry points to checksec.py.egg-info/entry_points.txt
writing requirements to checksec.py.egg-info/requires.txt
writing top-level names to checksec.py.egg-info/top_level.txt
reading manifest file 'checksec.py.egg-info/SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'checksec.py.egg-info/SOURCES.txt'
* Building sdist...
running sdist
running egg_info
writing checksec.py.egg-info/PKG-INFO
writing dependency_links to checksec.py.egg-info/dependency_links.txt
writing entry points to checksec.py.egg-info/entry_points.txt
writing requirements to checksec.py.egg-info/requires.txt
writing top-level names to checksec.py.egg-info/top_level.txt
reading manifest file 'checksec.py.egg-info/SOURCES.txt'
adding license file 'LICENSE'
writing manifest file 'checksec.py.egg-info/SOURCES.txt'
running check
creating checksec.py-0.6.2
creating checksec.py-0.6.2/checksec
creating checksec.py-0.6.2/checksec.py.egg-info
copying files to checksec.py-0.6.2...
copying LICENSE -> checksec.py-0.6.2
copying README.md -> checksec.py-0.6.2
copying setup.cfg -> checksec.py-0.6.2
copying setup.py -> checksec.py-0.6.2
copying checksec/__init__.py -> checksec.py-0.6.2/checksec
copying checksec/__main__.py -> checksec.py-0.6.2/checksec
copying checksec/binary.py -> checksec.py-0.6.2/checksec
copying checksec/elf.py -> checksec.py-0.6.2/checksec
copying checksec/errors.py -> checksec.py-0.6.2/checksec
copying checksec/output.py -> checksec.py-0.6.2/checksec
copying checksec/pe.py -> checksec.py-0.6.2/checksec
copying checksec/utils.py -> checksec.py-0.6.2/checksec
copying checksec.py.egg-info/PKG-INFO -> checksec.py-0.6.2/checksec.py.egg-info
copying checksec.py.egg-info/SOURCES.txt -> checksec.py-0.6.2/checksec.py.egg-info
copying checksec.py.egg-info/dependency_links.txt -> checksec.py-0.6.2/checksec.py.egg-info
copying checksec.py.egg-info/entry_points.txt -> checksec.py-0.6.2/checksec.py.egg-info
copying checksec.py.egg-info/requires.txt -> checksec.py-0.6.2/checksec.py.egg-info
copying checksec.py.egg-info/top_level.txt -> checksec.py-0.6.2/checksec.py.egg-info
Writing checksec.py-0.6.2/setup.cfg
Creating tar archive
removing 'checksec.py-0.6.2' (and everything under it)
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for wheel...
Traceback (most recent call last):
  File "/home/rogier.stam/.local/lib/python3.6/site-packages/pep517/in_process/_in_process.py", line 363, in <module>
    main()
  File "/home/rogier.stam/.local/lib/python3.6/site-packages/pep517/in_process/_in_process.py", line 345, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/home/rogier.stam/.local/lib/python3.6/site-packages/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
    return hook(config_settings)
  File "/tmp/build-env-d83ikglo/lib/python3.6/site-packages/setuptools/build_meta.py", line 155, in get_requires_for_build_wheel
    config_settings, requirements=['wheel'])
  File "/tmp/build-env-d83ikglo/lib/python3.6/site-packages/setuptools/build_meta.py", line 135, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-d83ikglo/lib/python3.6/site-packages/setuptools/build_meta.py", line 259, in run_setup
    self).run_setup(setup_script=setup_script)
  File "/tmp/build-env-d83ikglo/lib/python3.6/site-packages/setuptools/build_meta.py", line 150, in run_setup
    exec(compile(code, __file__, 'exec'), locals())
  File "setup.py", line 6, in <module>
    with open("requirements.txt") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

ERROR Backend subproccess exited when trying to invoke get_requires_for_build_wheel

This is caused by requirements.txt not being part of the package. Adding it to the package caused problems when installing as it appears one directory lower than the package directory (checksec). To fix this I moved the requirements into the setup.py.

Hope this is considered to be merged.

Thanks

Rogier

When building the package, the build fails as it cannot find
requirements.txt in the package. Fixed this by moving the
requirements into setup.py
@Wenzel
Copy link
Owner

Wenzel commented Oct 20, 2021

Hi
thanks for your PR.

how did you invoke setup.py ? because my release process in Github Actions works as expected.

Also, I'd like to keep the requirements separate from setup.py, so either I'll find a solution for this issue, or make a switch to Poetry and pyproject.toml

@rstam-exs
Copy link
Author

Hi
i clone the repo locally. Then python3 -m build in the directory. that' s it
Regards
Rogier

@rstam-exs
Copy link
Author

I suspected you wanted to keep requirements.txt. Problem is, I could not get setuptools to include it in the generated tarball but not have it be part of the package. Thats why the current solution

@Wenzel
Copy link
Owner

Wenzel commented Oct 20, 2021

Hi
i clone the repo locally. Then python3 -m build in the directory. that' s it

What build module are you refering to ?

(venv)  wenzel@Strix  ~/local/checksec.py   master  python3 -m build
/home/wenzel/local/checksec.py/venv/bin/python3: No module named build

@rstam-exs
Copy link
Author

rstam-exs commented Oct 20, 2021

I'm using the instructions as detailed here: https://packaging.python.org/tutorials/packaging-projects/
specifically the Generating distribution archives paragraph:

Generating distribution archives

The next step is to generate distribution packages for the package. These are archives that are uploaded to the Python Package Index and can be installed by pip.

Make sure you have the latest version of PyPA’s build installed:
Unix/macOS

python3 -m pip install --upgrade build

Tip

If you have trouble installing these, see the Installing Packages tutorial.

Now run this command from the same directory where pyproject.toml is located:
Unix/macOS

python3 -m build

This command should output a lot of text and once completed should generate two files in the dist directory:

dist/
  example_package_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl
  example_package_YOUR_USERNAME_HERE-0.0.1.tar.gz

The tar.gz file is a source archive whereas the .whl file is a built distribution. Newer pip versions preferentially install built distributions, but will fall back to source archives if needed. You should always upload a source archive and provide built archives for the platforms your project is compatible with. In this case, our example package is compatible with Python on any platform so only one built distribution is needed.

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.

3 participants