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

Unsafe requirements are no longer included in the requirements.txt generated by pip-compile #1786

Closed
VagueAndroid opened this issue Dec 19, 2022 · 9 comments · Fixed by #1788
Labels
bug Something is not working writer Related to results output writer component

Comments

@VagueAndroid
Copy link

After v6.12.0 the unsafe packages pip and setuptools are no longer included in the requirements.txt when --allow-unsafe is used in pip-compile.

There was a change made in writer.py (#1766)
I think this line should be using unsafe_packages if the user has specified allow_unsafe rather than if they have not:

unsafe_packages = unsafe_packages if not self.allow_unsafe else set()
I think this should be:
unsafe_packages = unsafe_packages if self.allow_unsafe else set()

Environment Versions

  1. Ubuntu 18
  2. Python version: 3.7.11
  3. pip version: 22.3.1
  4. pip-tools version: 6.12.1

Steps to replicate

Ensure requirements.in file includes pip and then run:
pip-compile --verbose --allow-unsafe --output-file requirements.txt requirements.in

Expected result

requirements.txt should end with this:

The following packages are considered to be unsafe in a requirements file:

pip==22.3.1
# via -r requirements.in

Actual result

The unsafe packages are not listed in the requirements.txt at all

@webknjaz
Copy link
Member

If you don't mind sending a PR with a failing test, it'd be highly appreciated.

@q0w
Copy link
Contributor

q0w commented Dec 20, 2022

requirements.in

pip

requirements.txt

#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe requirements.in
#
pip==22.3.1
    # via -r requirements.in

@atugushev atugushev added the needs reproduce Need to reproduce an issue label Dec 20, 2022
@georgipopovhs
Copy link

I noticed that in previous versions of pip-tools (e.g. 6.6.2) the output would contain "unsafe packages" message at the end:

#
# This file is autogenerated by pip-compile with python 3.7
# To update, run:
#
#    pip-compile --allow-unsafe
#

# The following packages are considered to be unsafe in a requirements file:
setuptools==65.6.3
    # via -r requirements.in

What happened in a larger Python project we have at work, is that after upgrading pip-tools, the unsafe message at the bottom disappeared and setuptools moved "up" among the list of regular packages.
Was that an intended change @atugushev?

@VagueAndroid could it be that instead of not listing the package at all, it was still included but got moved elsewhere in the output?

@q0w
Copy link
Contributor

q0w commented Dec 22, 2022

@georgipopovhs could you share your minimal reproducer?

@georgipopovhs
Copy link

requirements.in

setuptools

Old version & format:

pip install pip-tools==6.11.0
pip-compile --allow-unsafe

requirements.txt

#
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
#    pip-compile --allow-unsafe
#

# The following packages are considered to be unsafe in a requirements file:
setuptools==65.6.3
    # via -r requirements.in

New version & format:

pip install pip-tools==6.12.0
pip-compile --allow-unsafe

requirements.txt

#
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
#    pip-compile --allow-unsafe
#
setuptools==65.6.3
    # via -r requirements.in

@q0w
Copy link
Contributor

q0w commented Dec 22, 2022

Proposed change fails in tests/test_cli_compile.py::test_allow_unsafe_option

@atugushev
Copy link
Member

atugushev commented Dec 24, 2022

Was that an intended change?

@georgipopovhs No, that's a regression.

@atugushev atugushev added bug Something is not working writer Related to results output writer component and removed needs reproduce Need to reproduce an issue labels Dec 24, 2022
@q0w
Copy link
Contributor

q0w commented Dec 24, 2022

This test is wrong, is not it?

pytest.param(
"--allow-unsafe",
dedent(
"""\
small-fake-a==0.1
small-fake-b==0.3
small-fake-with-deps==0.1
"""
),
id="allow all packages",
),

Considering UNSAFE_PACKAGES={"small-fake-with-deps"}
it should be

small-fake-a==0.1
small-fake-b==0.3

# The following packages are considered to be unsafe in a requirements file:
small-fake-with-deps==0.1

And why was it patching UNSAFE_PACKAGES only in resolver.py and not in writer.py too

monkeypatch.setattr("piptools.resolver.UNSAFE_PACKAGES", {"small-fake-with-deps"})

@atugushev
Copy link
Member

And why was it patching UNSAFE_PACKAGES only in resolver.py and not in writer.py too

@q0w that was an oversight I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working writer Related to results output writer component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants