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

Add support for pip>=22.0, drop support for Python 3.6 #1567

Merged
merged 11 commits into from
Feb 4, 2022
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ jobs:
- macOS
python-version:
- "3.10"
- 3.9
- 3.6
- 3.7
- 3.8
- "3.9"
- "3.8"
- "3.7"
pip-version:
- "latest"
- "previous"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- Windows
- MacOS
python-version:
- 3.9
- 3.6
- 3.7
- 3.8
- "3.10"
- "3.9"
- "3.8"
- "3.7"
pip-version:
- main
env:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
rev: v2.29.0
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
Expand Down
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,15 @@ then yes, you should commit both ``requirements.in`` and ``requirements.txt`` to
Note that if you are deploying on multiple Python environments (read the section below),
then you must commit a seperate output file for each Python environment.
We suggest to use the ``{env}-requirements.txt`` format
(ex: ``win32-py3.7-requirements.txt``, ``macos-py3.6-requirements.txt``, etc.).
(ex: ``win32-py3.7-requirements.txt``, ``macos-py3.10-requirements.txt``, etc.).


Cross-environment usage of ``requirements.in``/``requirements.txt`` and ``pip-compile``
=======================================================================================

The dependencies of a package can change depending on the Python environment in which it
is installed. Here, we define a Python environment as the combination of Operating
System, Python version (3.6, 3.7, etc.), and Python implementation (CPython, PyPy,
System, Python version (3.7, 3.8, etc.), and Python implementation (CPython, PyPy,
etc.). For an exact definition, refer to the possible combinations of `PEP 508
environment markers`_.

Expand Down Expand Up @@ -527,5 +527,7 @@ versions as the required ``pip`` versions.
+---------------+----------------+----------------+
| 6.0.0 - 6.3.1 | 20.3 - 21.2.* | 3.6 - 3.9 |
+---------------+----------------+----------------+
| 6.4.0+ | 21.2+ | 3.6 - 3.10 |
| 6.4.0 | 21.2 - 21.3.* | 3.6 - 3.10 |
+---------------+----------------+----------------+
| 6.5.0+ | 21.2+ | 3.7 - 3.10 |
+---------------+----------------+----------------+
31 changes: 0 additions & 31 deletions piptools/_compat/contextlib.py

This file was deleted.

9 changes: 6 additions & 3 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import hashlib
import itertools
import logging
Expand Down Expand Up @@ -39,7 +40,7 @@
from pip._vendor.packaging.version import _BaseVersion
from pip._vendor.requests import RequestException, Session

from .._compat import contextlib
from .._compat import PIP_VERSION
from ..exceptions import NoCandidateFound
from ..logging import log
from ..utils import (
Expand Down Expand Up @@ -103,7 +104,8 @@ def __init__(self, pip_args: List[str], cache_dir: str):
self._cache_dir = normalize_path(str(cache_dir))
self._download_dir = os.path.join(self._cache_dir, "pkgs")

self._setup_logging()
if PIP_VERSION[0] < 22:
self._setup_logging()

def clear_caches(self) -> None:
rmtree(self._download_dir, ignore_errors=True)
Expand Down Expand Up @@ -439,7 +441,8 @@ def _wheel_support_index_min(self: Wheel, tags: List[Tag]) -> int:
def _setup_logging(self) -> None:
"""
Setup pip's logger. Ensure pip is verbose same as pip-tools and sync
pip's log stream with LogContext.stream.
pip's log stream with LogContext.stream. This is only necessary for
pip<22.0.
"""
# Default pip's logger is noisy, so decrease it's verbosity
setup_logging(
Expand Down
8 changes: 7 additions & 1 deletion piptools/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
import copy
import itertools
import json
import os
Expand Down Expand Up @@ -26,6 +27,7 @@
from pip._internal.vcs import is_url
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.specifiers import SpecifierSet
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging.version import Version
from pip._vendor.pkg_resources import Distribution, Requirement, get_distribution

Expand Down Expand Up @@ -121,7 +123,11 @@ def format_requirement(
elif is_url_requirement(ireq):
line = _build_direct_reference_best_efforts(ireq)
else:
line = str(ireq.req).lower()
# Canonicalize the requirement name
# https://packaging.pypa.io/en/latest/utils.html#packaging.utils.canonicalize_name
req = copy.copy(ireq.req)
req.name = canonicalize_name(req.name)
line = str(req)
di marked this conversation as resolved.
Show resolved Hide resolved

if marker:
line = f"{line} ; {marker}"
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -25,7 +24,7 @@ classifiers =
Topic :: System :: Systems Administration

[options]
python_requires = >=3.6
python_requires = >=3.7
setup_requires = setuptools_scm
packages = find:
zip_safe = false
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def test_url_package(runner, line, dependency, generate_hashes):
),
pytest.param(
path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_subdir"))
+ "#subdirectory=subdir&egg=small_fake_a",
+ "#subdirectory=subdir&egg=small-fake-a",
"small-fake-a @ "
+ path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_subdir"))
+ "#subdirectory=subdir",
Expand Down
5 changes: 3 additions & 2 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def test_write_find_links(writer, find_links, expected_lines):

def test_write_order(writer, from_line):
"""
Order of packages should match that of `pip freeze`.
Order of packages should match that of `pip freeze`, with the exception
that requirement names should be canonicalized.
"""
writer.emit_header = False

Expand All @@ -393,7 +394,7 @@ def test_write_order(writer, from_line):
]
expected_lines = [
"package==5.6",
"package_a==0.1",
"package-a==0.1",
"package-b==2.3.4",
"package2==7.8.9",
]
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
# NOTE: keep this in sync with the env list in .github/workflows/ci.yml.
py{36,37,38,39,310,311,py3}-pip{previous,latest,main}-coverage
py{37,38,39,310,311,py3}-pip{previous,latest,main}-coverage
checkqa
readme
skip_missing_interpreters = True
Expand All @@ -11,7 +11,7 @@ extras =
testing
coverage: coverage
deps =
pipprevious: pip==21.2.*
pipprevious: pip==21.3.*
piplatest: pip
pipmain: -e git+https://github.com/pypa/pip.git@main#egg=pip
setenv =
Expand Down