Skip to content
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

Packages should generate versioned dependencies on python #312

Open
fizbin opened this issue Oct 29, 2020 · 8 comments
Open

Packages should generate versioned dependencies on python #312

fizbin opened this issue Oct 29, 2020 · 8 comments

Comments

@fizbin
Copy link

fizbin commented Oct 29, 2020

I invoke dh_virtualenv in my package rule file with:

override_dh_virtualenv:
	dh_virtualenv --builtin-venv --python /usr/bin/python3 --skip-install --use-system-packages --upgrade-pip

This produces a package that works well on machines that have the same major version of python3 installed as the machine I built it on, but does not work on machines that have a different version of python3 installed. (i.e., build on a machine with python3.5, try to run on a machine with python3.8 -> failure)

The reason is that all my dependent packages end up installed inside a directory named something like /opt/venvs/mypackagename/lib/python3.8 where the last component is the python version.

In a case like this, the binary package that is produced should have a versioned dependency on python3 (>= 3.8), python3 (<< 3.9).

@jhermann
Copy link
Contributor

You are the author of your control file, i.e. yes, do that. dh-virtualenv packages are by nature release-dependent.
What could be an improvement to the project is documenting this.

@fizbin
Copy link
Author

fizbin commented Oct 29, 2020

But the exact same source built on different machines will produce different packages.

E.g., if I build my package on an Ubuntu 16.04 LTS machine (xenial) I will get a package that will only work on a machine with python3 installed that is python3 (>= 3.5), python3 (<< 3.6).

If I build the exact same source on an Ubuntu 18.04 LTS (bionic) machine, I will get a package that will only work on a machine with python3 installed that is python3 (>= 3.6), python3 (<< 3.7).

If I build the exact same source on an Ubuntu 20.04 LTS (focal) machine, I will get a package that will only work on a machine with python3 installed that is python3 (>= 3.8), python3 (<< 3.9).

This is analogous to how building C programs on different hosts will produce dependencies on different versions of shared libraries.

At the very least dh_virtualenv should define a substvar that gives the bounds of acceptable python versions for the created virtual environment, so that I can add something like ${virtualenv:PyDepends} to my Depends line.

@fizbin
Copy link
Author

fizbin commented Oct 29, 2020

For the record, here's the workaround I've developed at the moment:

override_dh_virtualenv:
	dh_virtualenv --builtin-venv --python /usr/bin/python3 --skip-install --use-system-packages --upgrade-pip
	# dh_virtualenv should tie us tightly to a specific python version, but it doesn't
	ls $(CURDIR)/debian/$(PACKAGE)$${DH_VIRTUALENV_INSTALL_ROOT}/$(PACKAGE)/lib | \
		perl -nle '/python((\d+)\.)((\d+\.)*)(\d+)$$/ && do {print "internal:PyDepends= python$$2 (>= $$1$$3$$5), python$$2 (<< $$1$$3",$$5+1,")"}' >> $(CURDIR)/debian/$(PACKAGE).substvars

And then I use ${internal:PyDepends} in my control file.

@nailor
Copy link
Collaborator

nailor commented Nov 2, 2020

Thanks for reporting the issue.

First off, not working across Python versions is universally a known thing with virtualenv, not specific for a dh-virtualenv. This could of course be documented better. In general, when it comes to Debian and its derivates like Ubuntu, I would highly recommend building the packages on same OS as where those are going to be used to avoid issues

I like the idea of substvars being defined during installation, so definitely open for merging a PR if someone implements it.

Since the issue is not really an issue with dh-virtualenv, but a feature of virtualenvs in general, I'll be closing this issue.

@nailor nailor closed this as completed Nov 2, 2020
@jhermann
Copy link
Contributor

jhermann commented Nov 3, 2020

Regarding "build where you install", here's the hint again to use the contained Dockerfile to avoid polluting your build machines.

@fizbin
Copy link
Author

fizbin commented Nov 3, 2020

For the record, the bug is not "the generated package doesn't work across python versions" but rather "because the generated package won't work across python versions, dh_virtualenv should generate versioned dependencies on python".

I'm not complaining that I can't take a package built on xenial and install and run it on a focal machine. I'm complaining that I can take a package built on xenial and dpkg is perfectly happy installing it on a focal machine. It should fail at the "package installation" phase, not at at the "run packaged program" phase.

@nailor
Copy link
Collaborator

nailor commented Nov 4, 2020 via email

@nailor nailor reopened this Nov 4, 2020
@WGH-
Copy link

WGH- commented Jul 22, 2022

Just for the record, how Synapse handles this problem:

https://github.com/matrix-org/synapse/blob/c7c84b81e3ec3d66f3a57a8d6ba3e58dd4c81ecc/debian/build_virtualenv#L117-L119

SNAKE=$(readlink -e /usr/bin/python3)
# add a dependency on the right version of python to substvars.
PYPKG=$(basename "$SNAKE")
echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars

So the generated dependency is simply e.g. python3.9, not something complicated like python3 (>= 3.9), python3 (<< 3.10)

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

No branches or pull requests

4 participants