Skip to content

Commit c811d5d

Browse files
author
Patrik Kopkan
committed
Merge remote-tracking branch 'upstream/master'
2 parents f9635ed + a7d8d56 commit c811d5d

38 files changed

+1325
-538
lines changed

.azure-pipelines/jobs/package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
inputs:
1616
versionSpec: '3'
1717

18-
- bash: pip install setuptools tox wheel invoke towncrier requests
18+
- bash: pip install tox nox setuptools wheel
1919
displayName: Install dependencies
2020

21-
- bash: invoke generate.authors
21+
- bash: nox -s generate_authors
2222
displayName: Generate AUTHORS.txt
2323

24-
- bash: invoke generate.news --yes
24+
- bash: nox -s generate_news -- --yes
2525
displayName: Generate NEWS.rst
2626

2727
- bash: tox -e packaging

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ docs/build/
1818
.mypy_cache/
1919

2020
# Unit test / coverage reports
21-
.tox/
21+
.[nt]ox/
2222
htmlcov/
2323
.coverage
2424
.coverage.*

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exclude .appveyor.yml
1717
exclude .travis.yml
1818
exclude .readthedocs.yml
1919
exclude tox.ini
20+
exclude noxfile.py
2021

2122
recursive-include src/pip/_vendor *.pem
2223
recursive-include docs Makefile *.rst *.py *.bat

docs/html/development/release-process.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ Creating a new release
8080
----------------------
8181

8282
#. Checkout the current pip ``master`` branch.
83-
#. Ensure you have the latest ``wheel``, ``setuptools``, ``twine``, ``invoke``
84-
and ``towncrier`` packages installed.
85-
#. Generate a new ``AUTHORS.txt`` (``invoke generate.authors``) and commit the
83+
#. Ensure you have the latest ``wheel``, ``setuptools``, ``twine`` and ``nox`` packages installed.
84+
#. Generate a new ``AUTHORS.txt`` (``nox -s generate_authors``) and commit the
8685
results.
8786
#. Bump the version in ``pip/__init__.py`` to the release version and commit
8887
the results. Usually this involves dropping just the ``.devN`` suffix on the
8988
version.
90-
#. Generate a new ``NEWS.rst`` (``invoke generate.news``) and commit the
89+
#. Generate a new ``NEWS.rst`` (``nox -s generate_news``) and commit the
9190
results.
9291
#. Create a tag at the current commit, of the form ``YY.N``
9392
(``git tag YY.N``).

news/6763.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Switch to new ``distlib`` wheel script template. This should be functionally
2+
equivalent for end users.

news/6924.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't fail installation using pip.exe on Windows when pip wouldn't be upgraded.

noxfile.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Release time helpers, executed using nox.
2+
"""
3+
4+
import io
5+
import subprocess
6+
7+
import nox
8+
9+
10+
def get_author_list():
11+
"""Get the list of authors from Git commits.
12+
"""
13+
# subprocess because session.run doesn't give us stdout
14+
result = subprocess.run(
15+
["git", "log", "--use-mailmap", "--format=%aN <%aE>"],
16+
capture_output=True,
17+
encoding="utf-8",
18+
)
19+
20+
# Create a unique list.
21+
authors = []
22+
seen_authors = set()
23+
for author in result.stdout.splitlines():
24+
author = author.strip()
25+
if author.lower() not in seen_authors:
26+
seen_authors.add(author.lower())
27+
authors.append(author)
28+
29+
# Sort our list of Authors by their case insensitive name
30+
return sorted(authors, key=lambda x: x.lower())
31+
32+
33+
# -----------------------------------------------------------------------------
34+
# Commands used during the release process
35+
# -----------------------------------------------------------------------------
36+
@nox.session
37+
def generate_authors(session):
38+
# Get our list of authors
39+
session.log("Collecting author names")
40+
authors = get_author_list()
41+
42+
# Write our authors to the AUTHORS file
43+
session.log("Writing AUTHORS")
44+
with io.open("AUTHORS.txt", "w", encoding="utf-8") as fp:
45+
fp.write(u"\n".join(authors))
46+
fp.write(u"\n")
47+
48+
49+
@nox.session
50+
def generate_news(session):
51+
session.log("Generating NEWS")
52+
session.install("towncrier")
53+
54+
# You can pass 2 possible arguments: --draft, --yes
55+
session.run("towncrier", *session.posargs)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[isort]
22
skip =
33
./build,
4+
.nox,
45
.tox,
56
.scratch,
67
_vendor,
@@ -17,6 +18,7 @@ include_trailing_comma = true
1718
[flake8]
1819
exclude =
1920
./build,
21+
.nox,
2022
.tox,
2123
.scratch,
2224
_vendor,

src/pip/_internal/cli/base_command.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import traceback
1212

1313
from pip._internal.cli import cmdoptions
14+
from pip._internal.cli.command_context import CommandContextMixIn
1415
from pip._internal.cli.parser import (
1516
ConfigOptionParser,
1617
UpdatingDefaultsHelpFormatter,
@@ -44,12 +45,13 @@
4445
logger = logging.getLogger(__name__)
4546

4647

47-
class Command(object):
48+
class Command(CommandContextMixIn):
4849
usage = None # type: str
4950
ignore_require_venv = False # type: bool
5051

5152
def __init__(self, name, summary, isolated=False):
5253
# type: (str, str, bool) -> None
54+
super(Command, self).__init__()
5355
parser_kw = {
5456
'usage': self.usage,
5557
'prog': '%s %s' % (get_prog(), name),
@@ -95,6 +97,14 @@ def parse_args(self, args):
9597
return self.parser.parse_args(args)
9698

9799
def main(self, args):
100+
# type: (List[str]) -> int
101+
try:
102+
with self.main_context():
103+
return self._main(args)
104+
finally:
105+
logging.shutdown()
106+
107+
def _main(self, args):
98108
# type: (List[str]) -> int
99109
options, args = self.parse_args(args)
100110

@@ -180,7 +190,4 @@ def main(self, args):
180190
finally:
181191
self.handle_pip_version_check(options)
182192

183-
# Shutdown the logging module
184-
logging.shutdown()
185-
186193
return SUCCESS
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from contextlib import contextmanager
2+
3+
from pip._vendor.contextlib2 import ExitStack
4+
5+
6+
class CommandContextMixIn(object):
7+
def __init__(self):
8+
super(CommandContextMixIn, self).__init__()
9+
self._in_main_context = False
10+
self._main_context = ExitStack()
11+
12+
@contextmanager
13+
def main_context(self):
14+
assert not self._in_main_context
15+
16+
self._in_main_context = True
17+
try:
18+
with self._main_context:
19+
yield
20+
finally:
21+
self._in_main_context = False
22+
23+
def enter_context(self, context_provider):
24+
assert self._in_main_context
25+
26+
return self._main_context.enter_context(context_provider)

src/pip/_internal/cli/req_command.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"""
77

88
import os
9+
from functools import partial
910

1011
from pip._internal.cli.base_command import Command
1112
from pip._internal.cli.cmdoptions import make_search_scope
13+
from pip._internal.cli.command_context import CommandContextMixIn
1214
from pip._internal.download import PipSession
1315
from pip._internal.exceptions import CommandError
1416
from pip._internal.index import PackageFinder
@@ -18,6 +20,7 @@
1820
from pip._internal.req.constructors import (
1921
install_req_from_editable,
2022
install_req_from_line,
23+
install_req_from_req_string,
2124
)
2225
from pip._internal.req.req_file import parse_requirements
2326
from pip._internal.utils.misc import normalize_path
@@ -34,11 +37,14 @@
3437
from pip._internal.utils.temp_dir import TempDirectory
3538

3639

37-
class SessionCommandMixin(object):
40+
class SessionCommandMixin(CommandContextMixIn):
3841

3942
"""
4043
A class mixin for command classes needing _build_session().
4144
"""
45+
def __init__(self):
46+
super(SessionCommandMixin, self).__init__()
47+
self._session = None # Optional[PipSession]
4248

4349
@classmethod
4450
def _get_index_urls(cls, options):
@@ -54,6 +60,13 @@ def _get_index_urls(cls, options):
5460
# Return None rather than an empty list
5561
return index_urls or None
5662

63+
def get_default_session(self, options):
64+
# type: (Values) -> PipSession
65+
"""Get a default-managed session."""
66+
if self._session is None:
67+
self._session = self.enter_context(self._build_session(options))
68+
return self._session
69+
5770
def _build_session(self, options, retries=None, timeout=None):
5871
# type: (Values, Optional[int], Optional[int]) -> PipSession
5972
session = PipSession(
@@ -93,7 +106,7 @@ def _build_session(self, options, retries=None, timeout=None):
93106
return session
94107

95108

96-
class IndexGroupCommand(SessionCommandMixin, Command):
109+
class IndexGroupCommand(Command, SessionCommandMixin):
97110

98111
"""
99112
Abstract base class for commands with the index_group options.
@@ -167,19 +180,23 @@ def make_resolver(
167180
"""
168181
Create a Resolver instance for the given parameters.
169182
"""
183+
make_install_req = partial(
184+
install_req_from_req_string,
185+
isolated=options.isolated_mode,
186+
wheel_cache=wheel_cache,
187+
use_pep517=use_pep517,
188+
)
170189
return Resolver(
171190
preparer=preparer,
172191
session=session,
173192
finder=finder,
174-
wheel_cache=wheel_cache,
193+
make_install_req=make_install_req,
175194
use_user_site=use_user_site,
176195
ignore_dependencies=options.ignore_dependencies,
177196
ignore_installed=ignore_installed,
178197
ignore_requires_python=ignore_requires_python,
179198
force_reinstall=force_reinstall,
180-
isolated=options.isolated_mode,
181199
upgrade_strategy=upgrade_strategy,
182-
use_pep517=use_pep517,
183200
py_version_info=py_version_info
184201
)
185202

0 commit comments

Comments
 (0)