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

By default, use pip for fetching and installing python packages. #1821

Merged
merged 4 commits into from
Nov 10, 2021

Conversation

jordansissel
Copy link
Owner

This adds a new flag, --python-internal-pip, which is enabled by default.

"internal pip" means using 'python -m pip' to invoke pip. Ideally this will make fpm more correctly use pip.

Tested on python 2.7.17 and 3.6.9 on Ubuntu 18.04

All python tests passing 👍👍

Fixes #1820

@jordansissel
Copy link
Owner Author

A cool thing is that some python tests were failing before and this helped fix things. One of the tests was using python3 and specifying "pip" which, on my workstation, was python2's pip. This made for amusing clashes as pip downloaded an ancient version of Django and python3 failed trying to install it.

@jordansissel
Copy link
Owner Author

pip now complains about being invoked.

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see pypa/pip#5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

@jordansissel
Copy link
Owner Author

% bundle exec rspec spec/fpm/package/python_spec.rb
.............

Finished in 12.2 seconds (files took 0.22577 seconds to load)
13 examples, 0 failures

With the last commit, the test suite now passes. 👍

@jordansissel
Copy link
Owner Author

% bundle exec bin/fpm -s python -t deb --python-bin python3 django
Debian packaging tools generally labels all files in /etc as config files, as mandated by policy, so fpm defaults to this behavior for deb packages. You can disable this default behavior with --deb-no-default-config-files flag {:level=>:warn}
Created package {:path=>"python-django_3.2.9_all.deb"}

Django seems to be packaging ok.

This adds a new flag, --python-internal-pip, which is enabled by default.

"internal pip" means using 'python -m pip' to invoke pip. Ideally this will make fpm more correctly use pip.

Tested on python 2.7.17 and 3.6.9 on Ubuntu 18.04

All python tests passing 👍👍

Fixes #1820
* https://bugs.python.org/issue22295

At time of writing, the python 3 installation docs mention:

https://docs.python.org/3/installing/index.html

> The following command will install the latest version of a module and its dependencies from the Python Package Index:
>
> python -m pip install SomePackage
…all anymore.

As part of making "internal pip" the default (#1820), the test suite
needed two main changes:
1) Don't check for easy_install anymore
2) Try to find the right python executable.

On my Ubuntu 20.04 system, installing Python gives Python v3 which only
makes the "python3" executable available. To compensate, the test suite
now tries to find any of "python", "python2", or "python3" to use with
the test suite. When found, it will set the appropriate `--python-bin`
flag in fpm for each test.

For #1820
Prior to this change, pip would download Python packages to $PWD which
leaves files hanging around.

The build_path is automatically removed when fpm exits.
@jordansissel
Copy link
Owner Author

I'm nervous about merging this, but I gain confidence with passing rspec tests as well as manual tests.

Two manual tests:

Running using the new default, internal pip aka "python -m pip":

% bundle exec bin/fpm -s python -t deb --python-bin python3 requests
Created package {:path=>"python-requests_2.26.0_all.deb"}

Running with internal pip disabled. This should fall back to easy_install by default, which isn't present on my system:

% bundle exec bin/fpm -s python -t deb --python-bin python3 --no-python-internal-pip requests
Need executable 'easy_install' to convert python to deb {:level=>:error}

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.

Use pip by default, if possible.
1 participant