packit / rpm-shim

Python RPM shim module for use in virtualenvs
MIT License
2 stars 4 forks source link

Test installation and import also on local system #4

Closed nforro closed 1 year ago

nforro commented 1 year ago

Note that python3 -m build doesn't work with rootless podman, I can't figure out why :frowning_face:

nforro commented 1 year ago

On openSUSE and Ubuntu pip tries to install to default system sitepackages dir, overwriting installed RPM bindings, and the installation fails. That's good, because it prevents breaking anything, I'm just wondering if there is a way to do it more cleanly.

TomasTomecek commented 1 year ago

Note that python3 -m build doesn't work with rootless podman, I can't figure out why :frowning_face:

Worked for me fine:

diff --git a/Makefile b/Makefile
index 1f38712..3e707ac 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 TEST_IMAGE = rpm-shim-tests
-BASE_IMAGE ?=
-INSTALL_DEPS_CMD ?=
+BASE_IMAGE ?= fedora:38
+INSTALL_DEPS_CMD ?= dnf install -y python3-pip git-core

 CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker)

test run:

* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools>=45, setuptools_scm[toml], setuptools_scm_git_archive)           
* Getting build dependencies for wheel...              
running egg_info             
writing rpm.egg-info/PKG-INFO                             
writing dependency_links to rpm.egg-info/dependency_links.txt
writing requirements to rpm.egg-info/requires.txt         
writing top-level names to rpm.egg-info/top_level.txt                                                                         
adding license file 'LICENSE'
writing manifest file 'rpm.egg-info/SOURCES.txt'             
* Installing packages in isolated environment... (wheel)
* Building wheel...                                                                                                           
running bdist_wheel                                                                                                           
running build                                                                                                                                                                                                                                                
running build_py
copying rpm/__init__.py -> build/lib/rpm
running egg_info
writing rpm.egg-info/PKG-INFO
writing dependency_links to rpm.egg-info/dependency_links.txt
writing requirements to rpm.egg-info/requires.txt
writing top-level names to rpm.egg-info/top_level.txt
adding license file 'LICENSE'
writing manifest file 'rpm.egg-info/SOURCES.txt'
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/rpm
copying build/lib/rpm/__init__.py -> build/bdist.linux-x86_64/wheel/rpm
running install_egg_info
Copying rpm.egg-info to build/bdist.linux-x86_64/wheel/rpm-0.0.post13+g3e79092.d20230214-py3.11.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/rpm-0.0.post13+g3e79092.d20230214.dist-info/WHEEL
creating '/rpm-shim/dist/.tmp-y21xfmzy/rpm-0.0.post13+g3e79092.d20230214-py3-none-any.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'rpm/__init__.py'
adding 'rpm-0.0.post13+g3e79092.d20230214.dist-info/LICENSE'
adding 'rpm-0.0.post13+g3e79092.d20230214.dist-info/METADATA'
adding 'rpm-0.0.post13+g3e79092.d20230214.dist-info/WHEEL'
adding 'rpm-0.0.post13+g3e79092.d20230214.dist-info/top_level.txt'
adding 'rpm-0.0.post13+g3e79092.d20230214.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel
Successfully built rpm-0.0.post13+g3e79092.d20230214-py3-none-any.whl
Processing /rpm-shim/dist/rpm-0.0.post13+g3e79092.d20230214-py3-none-any.whl
Installing collected packages: rpm
Successfully installed rpm-0.0.post13+g3e79092.d20230214
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
DEBUG:rpm-shim:Collected sitepackages for /usr/bin/python3:
/usr/local/lib64/python3.11/site-packages
/usr/local/lib/python3.11/site-packages
/usr/lib64/python3.11/site-packages
/usr/lib/python3.11/site-packages
DEBUG:rpm-shim:Trying /usr/local/lib64/python3.11/site-packages 
DEBUG:rpm-shim:Trying /usr/local/lib/python3.11/site-packages
DEBUG:rpm-shim:Trying /usr/lib64/python3.11/site-packages
DEBUG:rpm-shim:Import successfull
No broken requirements found.
nforro commented 1 year ago

Worked for me fine:

It still fails here with fedora:38 :thinking:

running install_egg_info
Copying rpm.egg-info to build/bdist.linux-x86_64/wheel/rpm-0.0.post13+g9bb3282-py3.11.egg-info
error: [Errno 13] Permission denied: 'build/bdist.linux-x86_64/wheel/rpm-0.0.post13+g9bb3282-py3.11.egg-info/PKG-INFO'

ERROR Backend subprocess exited when trying to invoke build_wheel
make: *** [Makefile:16: test] Error 1
TomasTomecek commented 1 year ago

could the permision denied be selinux? are you mounting something inside? does simple touch build/foo-bar work?

nforro commented 1 year ago

could the permision denied be selinux? are you mounting something inside? does simple touch build/foo-bar work?

I'm not mounting anything (so I don't think selinux is involved in any way), touch works just fine.

nforro commented 1 year ago

I've moved test-related files to a subdirectory and added a sanity check so even if the shim fails to install on a local system we verify that rpm can be imported and used.

nforro commented 1 year ago

Thanks. Merging manually.