We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Move slow check_manifest out of .pre-commit-config.yaml
The check-manifest pre-commit hook is by far the slowest of the checks, in particular when committing a few files.

When pre-commit is installed locally as a pre-commit hook, it tends to slow down the development flow significantly.

Could we move it out of the default pre-commit config to a regular CI check ?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `noxfile.py`
Content:
```
1 """Automation using nox.
2 """
3 
4 # The following comment should be removed at some point in the future.
5 # mypy: disallow-untyped-defs=False
6 
7 import glob
8 import os
9 import shutil
10 import sys
11 from pathlib import Path
12 
13 import nox
14 
15 sys.path.append(".")
16 from tools.automation import release  # isort:skip  # noqa
17 sys.path.pop()
18 
19 nox.options.reuse_existing_virtualenvs = True
20 nox.options.sessions = ["lint"]
21 
22 LOCATIONS = {
23     "common-wheels": "tests/data/common_wheels",
24     "protected-pip": "tools/tox_pip.py",
25 }
26 REQUIREMENTS = {
27     "docs": "tools/requirements/docs.txt",
28     "tests": "tools/requirements/tests.txt",
29     "common-wheels": "tools/requirements/tests-common_wheels.txt",
30 }
31 
32 AUTHORS_FILE = "AUTHORS.txt"
33 VERSION_FILE = "src/pip/__init__.py"
34 
35 
36 def run_with_protected_pip(session, *arguments):
37     """Do a session.run("pip", *arguments), using a "protected" pip.
38 
39     This invokes a wrapper script, that forwards calls to original virtualenv
40     (stable) version, and not the code being tested. This ensures pip being
41     used is not the code being tested.
42     """
43     env = {"VIRTUAL_ENV": session.virtualenv.location}
44 
45     command = ("python", LOCATIONS["protected-pip"]) + arguments
46     kwargs = {"env": env, "silent": True}
47     session.run(*command, **kwargs)
48 
49 
50 def should_update_common_wheels():
51     # If the cache hasn't been created, create it.
52     if not os.path.exists(LOCATIONS["common-wheels"]):
53         return True
54 
55     # If the requirements was updated after cache, we'll repopulate it.
56     cache_last_populated_at = os.path.getmtime(LOCATIONS["common-wheels"])
57     requirements_updated_at = os.path.getmtime(REQUIREMENTS["common-wheels"])
58     need_to_repopulate = requirements_updated_at > cache_last_populated_at
59 
60     # Clear the stale cache.
61     if need_to_repopulate:
62         shutil.rmtree(LOCATIONS["common-wheels"], ignore_errors=True)
63 
64     return need_to_repopulate
65 
66 
67 # -----------------------------------------------------------------------------
68 # Development Commands
69 #   These are currently prototypes to evaluate whether we want to switch over
70 #   completely to nox for all our automation. Contributors should prefer using
71 #   `tox -e ...` until this note is removed.
72 # -----------------------------------------------------------------------------
73 @nox.session(python=["3.6", "3.7", "3.8", "3.9", "pypy3"])
74 def test(session):
75     # Get the common wheels.
76     if should_update_common_wheels():
77         run_with_protected_pip(
78             session,
79             "wheel",
80             "-w", LOCATIONS["common-wheels"],
81             "-r", REQUIREMENTS["common-wheels"],
82         )
83     else:
84         msg = (
85             "Re-using existing common-wheels at {}."
86             .format(LOCATIONS["common-wheels"])
87         )
88         session.log(msg)
89 
90     # Build source distribution
91     sdist_dir = os.path.join(session.virtualenv.location, "sdist")
92     if os.path.exists(sdist_dir):
93         shutil.rmtree(sdist_dir, ignore_errors=True)
94     session.run(
95         "python", "setup.py", "sdist",
96         "--formats=zip", "--dist-dir", sdist_dir,
97         silent=True,
98     )
99     generated_files = os.listdir(sdist_dir)
100     assert len(generated_files) == 1
101     generated_sdist = os.path.join(sdist_dir, generated_files[0])
102 
103     # Install source distribution
104     run_with_protected_pip(session, "install", generated_sdist)
105 
106     # Install test dependencies
107     run_with_protected_pip(session, "install", "-r", REQUIREMENTS["tests"])
108 
109     # Parallelize tests as much as possible, by default.
110     arguments = session.posargs or ["-n", "auto"]
111 
112     # Run the tests
113     #   LC_CTYPE is set to get UTF-8 output inside of the subprocesses that our
114     #   tests use.
115     session.run("pytest", *arguments, env={"LC_CTYPE": "en_US.UTF-8"})
116 
117 
118 @nox.session
119 def docs(session):
120     session.install("-e", ".")
121     session.install("-r", REQUIREMENTS["docs"])
122 
123     def get_sphinx_build_command(kind):
124         # Having the conf.py in the docs/html is weird but needed because we
125         # can not use a different configuration directory vs source directory
126         # on RTD currently. So, we'll pass "-c docs/html" here.
127         # See https://github.com/rtfd/readthedocs.org/issues/1543.
128         return [
129             "sphinx-build",
130             "-W",
131             "-c", "docs/html",  # see note above
132             "-d", "docs/build/doctrees/" + kind,
133             "-b", kind,
134             "docs/" + kind,
135             "docs/build/" + kind,
136         ]
137 
138     session.run(*get_sphinx_build_command("html"))
139     session.run(*get_sphinx_build_command("man"))
140 
141 
142 @nox.session
143 def lint(session):
144     session.install("pre-commit")
145 
146     if session.posargs:
147         args = session.posargs + ["--all-files"]
148     else:
149         args = ["--all-files", "--show-diff-on-failure"]
150 
151     session.run("pre-commit", "run", *args)
152 
153 
154 @nox.session
155 def vendoring(session):
156     session.install("vendoring>=0.3.0")
157 
158     if "--upgrade" not in session.posargs:
159         session.run("vendoring", "sync", ".", "-v")
160         return
161 
162     def pinned_requirements(path):
163         for line in path.read_text().splitlines():
164             one, two = line.split("==", 1)
165             name = one.strip()
166             version = two.split("#")[0].strip()
167             yield name, version
168 
169     vendor_txt = Path("src/pip/_vendor/vendor.txt")
170     for name, old_version in pinned_requirements(vendor_txt):
171         if name == "setuptools":
172             continue
173 
174         # update requirements.txt
175         session.run("vendoring", "update", ".", name)
176 
177         # get the updated version
178         new_version = old_version
179         for inner_name, inner_version in pinned_requirements(vendor_txt):
180             if inner_name == name:
181                 # this is a dedicated assignment, to make flake8 happy
182                 new_version = inner_version
183                 break
184         else:
185             session.error(f"Could not find {name} in {vendor_txt}")
186 
187         # check if the version changed.
188         if new_version == old_version:
189             continue  # no change, nothing more to do here.
190 
191         # synchronize the contents
192         session.run("vendoring", "sync", ".")
193 
194         # Determine the correct message
195         message = f"Upgrade {name} to {new_version}"
196 
197         # Write our news fragment
198         news_file = Path("news") / (name + ".vendor.rst")
199         news_file.write_text(message + "\n")  # "\n" appeases end-of-line-fixer
200 
201         # Commit the changes
202         release.commit_file(session, ".", message=message)
203 
204 
205 # -----------------------------------------------------------------------------
206 # Release Commands
207 # -----------------------------------------------------------------------------
208 @nox.session(name="prepare-release")
209 def prepare_release(session):
210     version = release.get_version_from_arguments(session)
211     if not version:
212         session.error("Usage: nox -s prepare-release -- <version>")
213 
214     session.log("# Ensure nothing is staged")
215     if release.modified_files_in_git("--staged"):
216         session.error("There are files staged in git")
217 
218     session.log(f"# Updating {AUTHORS_FILE}")
219     release.generate_authors(AUTHORS_FILE)
220     if release.modified_files_in_git():
221         release.commit_file(
222             session, AUTHORS_FILE, message=f"Update {AUTHORS_FILE}",
223         )
224     else:
225         session.log(f"# No changes to {AUTHORS_FILE}")
226 
227     session.log("# Generating NEWS")
228     release.generate_news(session, version)
229 
230     session.log(f"# Bumping for release {version}")
231     release.update_version_file(version, VERSION_FILE)
232     release.commit_file(session, VERSION_FILE, message="Bump for release")
233 
234     session.log("# Tagging release")
235     release.create_git_tag(session, version, message=f"Release {version}")
236 
237     session.log("# Bumping for development")
238     next_dev_version = release.get_next_development_version(version)
239     release.update_version_file(next_dev_version, VERSION_FILE)
240     release.commit_file(session, VERSION_FILE, message="Bump for development")
241 
242 
243 @nox.session(name="build-release")
244 def build_release(session):
245     version = release.get_version_from_arguments(session)
246     if not version:
247         session.error("Usage: nox -s build-release -- YY.N[.P]")
248 
249     session.log("# Ensure no files in dist/")
250     if release.have_files_in_folder("dist"):
251         session.error(
252             "There are files in dist/. Remove them and try again. "
253             "You can use `git clean -fxdi -- dist` command to do this"
254         )
255 
256     session.log("# Install dependencies")
257     session.install("setuptools", "wheel", "twine")
258 
259     with release.isolated_temporary_checkout(session, version) as build_dir:
260         session.log(
261             "# Start the build in an isolated, "
262             f"temporary Git checkout at {build_dir!s}",
263         )
264         with release.workdir(session, build_dir):
265             tmp_dists = build_dists(session)
266 
267         tmp_dist_paths = (build_dir / p for p in tmp_dists)
268         session.log(f"# Copying dists from {build_dir}")
269         os.makedirs('dist', exist_ok=True)
270         for dist, final in zip(tmp_dist_paths, tmp_dists):
271             session.log(f"# Copying {dist} to {final}")
272             shutil.copy(dist, final)
273 
274 
275 def build_dists(session):
276     """Return dists with valid metadata."""
277     session.log(
278         "# Check if there's any Git-untracked files before building the wheel",
279     )
280 
281     has_forbidden_git_untracked_files = any(
282         # Don't report the environment this session is running in
283         not untracked_file.startswith('.nox/build-release/')
284         for untracked_file in release.get_git_untracked_files()
285     )
286     if has_forbidden_git_untracked_files:
287         session.error(
288             "There are untracked files in the working directory. "
289             "Remove them and try again",
290         )
291 
292     session.log("# Build distributions")
293     session.run("python", "setup.py", "sdist", "bdist_wheel", silent=True)
294     produced_dists = glob.glob("dist/*")
295 
296     session.log(f"# Verify distributions: {', '.join(produced_dists)}")
297     session.run("twine", "check", *produced_dists, silent=True)
298 
299     return produced_dists
300 
301 
302 @nox.session(name="upload-release")
303 def upload_release(session):
304     version = release.get_version_from_arguments(session)
305     if not version:
306         session.error("Usage: nox -s upload-release -- YY.N[.P]")
307 
308     session.log("# Install dependencies")
309     session.install("twine")
310 
311     distribution_files = glob.glob("dist/*")
312     session.log(f"# Distribution files: {distribution_files}")
313 
314     # Sanity check: Make sure there's 2 distribution files.
315     count = len(distribution_files)
316     if count != 2:
317         session.error(
318             f"Expected 2 distribution files for upload, got {count}. "
319             f"Remove dist/ and run 'nox -s build-release -- {version}'"
320         )
321     # Sanity check: Make sure the files are correctly named.
322     distfile_names = map(os.path.basename, distribution_files)
323     expected_distribution_files = [
324         f"pip-{version}-py2.py3-none-any.whl",
325         f"pip-{version}.tar.gz",
326     ]
327     if sorted(distfile_names) != sorted(expected_distribution_files):
328         session.error(
329             f"Distribution files do not seem to be for {version} release."
330         )
331 
332     session.log("# Upload distributions")
333     session.run("twine", "upload", *distribution_files)
334
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/noxfile.py b/noxfile.py
--- a/noxfile.py
+++ b/noxfile.py
@@ -149,6 +149,9 @@
         args = ["--all-files", "--show-diff-on-failure"]
 
     session.run("pre-commit", "run", *args)
+    session.run(
+        "pre-commit", "run", "-c", ".pre-commit-config-slow.yaml", *args
+    )
 
 
 @nox.session

{"golden_diff": "diff --git a/noxfile.py b/noxfile.py\n--- a/noxfile.py\n+++ b/noxfile.py\n@@ -149,6 +149,9 @@\n         args = [\"--all-files\", \"--show-diff-on-failure\"]\n \n     session.run(\"pre-commit\", \"run\", *args)\n+    session.run(\n+        \"pre-commit\", \"run\", \"-c\", \".pre-commit-config-slow.yaml\", *args\n+    )\n \n \n @nox.session\n", "issue": "Move slow check_manifest out of .pre-commit-config.yaml\nThe check-manifest pre-commit hook is by far the slowest of the checks, in particular when committing a few files.\r\n\r\nWhen pre-commit is installed locally as a pre-commit hook, it tends to slow down the development flow significantly.\r\n\r\nCould we move it out of the default pre-commit config to a regular CI check ?\r\n\n", "before_files": [{"content": "\"\"\"Automation using nox.\n\"\"\"\n\n# The following comment should be removed at some point in the future.\n# mypy: disallow-untyped-defs=False\n\nimport glob\nimport os\nimport shutil\nimport sys\nfrom pathlib import Path\n\nimport nox\n\nsys.path.append(\".\")\nfrom tools.automation import release  # isort:skip  # noqa\nsys.path.pop()\n\nnox.options.reuse_existing_virtualenvs = True\nnox.options.sessions = [\"lint\"]\n\nLOCATIONS = {\n    \"common-wheels\": \"tests/data/common_wheels\",\n    \"protected-pip\": \"tools/tox_pip.py\",\n}\nREQUIREMENTS = {\n    \"docs\": \"tools/requirements/docs.txt\",\n    \"tests\": \"tools/requirements/tests.txt\",\n    \"common-wheels\": \"tools/requirements/tests-common_wheels.txt\",\n}\n\nAUTHORS_FILE = \"AUTHORS.txt\"\nVERSION_FILE = \"src/pip/__init__.py\"\n\n\ndef run_with_protected_pip(session, *arguments):\n    \"\"\"Do a session.run(\"pip\", *arguments), using a \"protected\" pip.\n\n    This invokes a wrapper script, that forwards calls to original virtualenv\n    (stable) version, and not the code being tested. This ensures pip being\n    used is not the code being tested.\n    \"\"\"\n    env = {\"VIRTUAL_ENV\": session.virtualenv.location}\n\n    command = (\"python\", LOCATIONS[\"protected-pip\"]) + arguments\n    kwargs = {\"env\": env, \"silent\": True}\n    session.run(*command, **kwargs)\n\n\ndef should_update_common_wheels():\n    # If the cache hasn't been created, create it.\n    if not os.path.exists(LOCATIONS[\"common-wheels\"]):\n        return True\n\n    # If the requirements was updated after cache, we'll repopulate it.\n    cache_last_populated_at = os.path.getmtime(LOCATIONS[\"common-wheels\"])\n    requirements_updated_at = os.path.getmtime(REQUIREMENTS[\"common-wheels\"])\n    need_to_repopulate = requirements_updated_at > cache_last_populated_at\n\n    # Clear the stale cache.\n    if need_to_repopulate:\n        shutil.rmtree(LOCATIONS[\"common-wheels\"], ignore_errors=True)\n\n    return need_to_repopulate\n\n\n# -----------------------------------------------------------------------------\n# Development Commands\n#   These are currently prototypes to evaluate whether we want to switch over\n#   completely to nox for all our automation. Contributors should prefer using\n#   `tox -e ...` until this note is removed.\n# -----------------------------------------------------------------------------\n@nox.session(python=[\"3.6\", \"3.7\", \"3.8\", \"3.9\", \"pypy3\"])\ndef test(session):\n    # Get the common wheels.\n    if should_update_common_wheels():\n        run_with_protected_pip(\n            session,\n            \"wheel\",\n            \"-w\", LOCATIONS[\"common-wheels\"],\n            \"-r\", REQUIREMENTS[\"common-wheels\"],\n        )\n    else:\n        msg = (\n            \"Re-using existing common-wheels at {}.\"\n            .format(LOCATIONS[\"common-wheels\"])\n        )\n        session.log(msg)\n\n    # Build source distribution\n    sdist_dir = os.path.join(session.virtualenv.location, \"sdist\")\n    if os.path.exists(sdist_dir):\n        shutil.rmtree(sdist_dir, ignore_errors=True)\n    session.run(\n        \"python\", \"setup.py\", \"sdist\",\n        \"--formats=zip\", \"--dist-dir\", sdist_dir,\n        silent=True,\n    )\n    generated_files = os.listdir(sdist_dir)\n    assert len(generated_files) == 1\n    generated_sdist = os.path.join(sdist_dir, generated_files[0])\n\n    # Install source distribution\n    run_with_protected_pip(session, \"install\", generated_sdist)\n\n    # Install test dependencies\n    run_with_protected_pip(session, \"install\", \"-r\", REQUIREMENTS[\"tests\"])\n\n    # Parallelize tests as much as possible, by default.\n    arguments = session.posargs or [\"-n\", \"auto\"]\n\n    # Run the tests\n    #   LC_CTYPE is set to get UTF-8 output inside of the subprocesses that our\n    #   tests use.\n    session.run(\"pytest\", *arguments, env={\"LC_CTYPE\": \"en_US.UTF-8\"})\n\n\n@nox.session\ndef docs(session):\n    session.install(\"-e\", \".\")\n    session.install(\"-r\", REQUIREMENTS[\"docs\"])\n\n    def get_sphinx_build_command(kind):\n        # Having the conf.py in the docs/html is weird but needed because we\n        # can not use a different configuration directory vs source directory\n        # on RTD currently. So, we'll pass \"-c docs/html\" here.\n        # See https://github.com/rtfd/readthedocs.org/issues/1543.\n        return [\n            \"sphinx-build\",\n            \"-W\",\n            \"-c\", \"docs/html\",  # see note above\n            \"-d\", \"docs/build/doctrees/\" + kind,\n            \"-b\", kind,\n            \"docs/\" + kind,\n            \"docs/build/\" + kind,\n        ]\n\n    session.run(*get_sphinx_build_command(\"html\"))\n    session.run(*get_sphinx_build_command(\"man\"))\n\n\n@nox.session\ndef lint(session):\n    session.install(\"pre-commit\")\n\n    if session.posargs:\n        args = session.posargs + [\"--all-files\"]\n    else:\n        args = [\"--all-files\", \"--show-diff-on-failure\"]\n\n    session.run(\"pre-commit\", \"run\", *args)\n\n\n@nox.session\ndef vendoring(session):\n    session.install(\"vendoring>=0.3.0\")\n\n    if \"--upgrade\" not in session.posargs:\n        session.run(\"vendoring\", \"sync\", \".\", \"-v\")\n        return\n\n    def pinned_requirements(path):\n        for line in path.read_text().splitlines():\n            one, two = line.split(\"==\", 1)\n            name = one.strip()\n            version = two.split(\"#\")[0].strip()\n            yield name, version\n\n    vendor_txt = Path(\"src/pip/_vendor/vendor.txt\")\n    for name, old_version in pinned_requirements(vendor_txt):\n        if name == \"setuptools\":\n            continue\n\n        # update requirements.txt\n        session.run(\"vendoring\", \"update\", \".\", name)\n\n        # get the updated version\n        new_version = old_version\n        for inner_name, inner_version in pinned_requirements(vendor_txt):\n            if inner_name == name:\n                # this is a dedicated assignment, to make flake8 happy\n                new_version = inner_version\n                break\n        else:\n            session.error(f\"Could not find {name} in {vendor_txt}\")\n\n        # check if the version changed.\n        if new_version == old_version:\n            continue  # no change, nothing more to do here.\n\n        # synchronize the contents\n        session.run(\"vendoring\", \"sync\", \".\")\n\n        # Determine the correct message\n        message = f\"Upgrade {name} to {new_version}\"\n\n        # Write our news fragment\n        news_file = Path(\"news\") / (name + \".vendor.rst\")\n        news_file.write_text(message + \"\\n\")  # \"\\n\" appeases end-of-line-fixer\n\n        # Commit the changes\n        release.commit_file(session, \".\", message=message)\n\n\n# -----------------------------------------------------------------------------\n# Release Commands\n# -----------------------------------------------------------------------------\n@nox.session(name=\"prepare-release\")\ndef prepare_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s prepare-release -- <version>\")\n\n    session.log(\"# Ensure nothing is staged\")\n    if release.modified_files_in_git(\"--staged\"):\n        session.error(\"There are files staged in git\")\n\n    session.log(f\"# Updating {AUTHORS_FILE}\")\n    release.generate_authors(AUTHORS_FILE)\n    if release.modified_files_in_git():\n        release.commit_file(\n            session, AUTHORS_FILE, message=f\"Update {AUTHORS_FILE}\",\n        )\n    else:\n        session.log(f\"# No changes to {AUTHORS_FILE}\")\n\n    session.log(\"# Generating NEWS\")\n    release.generate_news(session, version)\n\n    session.log(f\"# Bumping for release {version}\")\n    release.update_version_file(version, VERSION_FILE)\n    release.commit_file(session, VERSION_FILE, message=\"Bump for release\")\n\n    session.log(\"# Tagging release\")\n    release.create_git_tag(session, version, message=f\"Release {version}\")\n\n    session.log(\"# Bumping for development\")\n    next_dev_version = release.get_next_development_version(version)\n    release.update_version_file(next_dev_version, VERSION_FILE)\n    release.commit_file(session, VERSION_FILE, message=\"Bump for development\")\n\n\n@nox.session(name=\"build-release\")\ndef build_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s build-release -- YY.N[.P]\")\n\n    session.log(\"# Ensure no files in dist/\")\n    if release.have_files_in_folder(\"dist\"):\n        session.error(\n            \"There are files in dist/. Remove them and try again. \"\n            \"You can use `git clean -fxdi -- dist` command to do this\"\n        )\n\n    session.log(\"# Install dependencies\")\n    session.install(\"setuptools\", \"wheel\", \"twine\")\n\n    with release.isolated_temporary_checkout(session, version) as build_dir:\n        session.log(\n            \"# Start the build in an isolated, \"\n            f\"temporary Git checkout at {build_dir!s}\",\n        )\n        with release.workdir(session, build_dir):\n            tmp_dists = build_dists(session)\n\n        tmp_dist_paths = (build_dir / p for p in tmp_dists)\n        session.log(f\"# Copying dists from {build_dir}\")\n        os.makedirs('dist', exist_ok=True)\n        for dist, final in zip(tmp_dist_paths, tmp_dists):\n            session.log(f\"# Copying {dist} to {final}\")\n            shutil.copy(dist, final)\n\n\ndef build_dists(session):\n    \"\"\"Return dists with valid metadata.\"\"\"\n    session.log(\n        \"# Check if there's any Git-untracked files before building the wheel\",\n    )\n\n    has_forbidden_git_untracked_files = any(\n        # Don't report the environment this session is running in\n        not untracked_file.startswith('.nox/build-release/')\n        for untracked_file in release.get_git_untracked_files()\n    )\n    if has_forbidden_git_untracked_files:\n        session.error(\n            \"There are untracked files in the working directory. \"\n            \"Remove them and try again\",\n        )\n\n    session.log(\"# Build distributions\")\n    session.run(\"python\", \"setup.py\", \"sdist\", \"bdist_wheel\", silent=True)\n    produced_dists = glob.glob(\"dist/*\")\n\n    session.log(f\"# Verify distributions: {', '.join(produced_dists)}\")\n    session.run(\"twine\", \"check\", *produced_dists, silent=True)\n\n    return produced_dists\n\n\n@nox.session(name=\"upload-release\")\ndef upload_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s upload-release -- YY.N[.P]\")\n\n    session.log(\"# Install dependencies\")\n    session.install(\"twine\")\n\n    distribution_files = glob.glob(\"dist/*\")\n    session.log(f\"# Distribution files: {distribution_files}\")\n\n    # Sanity check: Make sure there's 2 distribution files.\n    count = len(distribution_files)\n    if count != 2:\n        session.error(\n            f\"Expected 2 distribution files for upload, got {count}. \"\n            f\"Remove dist/ and run 'nox -s build-release -- {version}'\"\n        )\n    # Sanity check: Make sure the files are correctly named.\n    distfile_names = map(os.path.basename, distribution_files)\n    expected_distribution_files = [\n        f\"pip-{version}-py2.py3-none-any.whl\",\n        f\"pip-{version}.tar.gz\",\n    ]\n    if sorted(distfile_names) != sorted(expected_distribution_files):\n        session.error(\n            f\"Distribution files do not seem to be for {version} release.\"\n        )\n\n    session.log(\"# Upload distributions\")\n    session.run(\"twine\", \"upload\", *distribution_files)\n", "path": "noxfile.py"}], "after_files": [{"content": "\"\"\"Automation using nox.\n\"\"\"\n\n# The following comment should be removed at some point in the future.\n# mypy: disallow-untyped-defs=False\n\nimport glob\nimport os\nimport shutil\nimport sys\nfrom pathlib import Path\n\nimport nox\n\nsys.path.append(\".\")\nfrom tools.automation import release  # isort:skip  # noqa\nsys.path.pop()\n\nnox.options.reuse_existing_virtualenvs = True\nnox.options.sessions = [\"lint\"]\n\nLOCATIONS = {\n    \"common-wheels\": \"tests/data/common_wheels\",\n    \"protected-pip\": \"tools/tox_pip.py\",\n}\nREQUIREMENTS = {\n    \"docs\": \"tools/requirements/docs.txt\",\n    \"tests\": \"tools/requirements/tests.txt\",\n    \"common-wheels\": \"tools/requirements/tests-common_wheels.txt\",\n}\n\nAUTHORS_FILE = \"AUTHORS.txt\"\nVERSION_FILE = \"src/pip/__init__.py\"\n\n\ndef run_with_protected_pip(session, *arguments):\n    \"\"\"Do a session.run(\"pip\", *arguments), using a \"protected\" pip.\n\n    This invokes a wrapper script, that forwards calls to original virtualenv\n    (stable) version, and not the code being tested. This ensures pip being\n    used is not the code being tested.\n    \"\"\"\n    env = {\"VIRTUAL_ENV\": session.virtualenv.location}\n\n    command = (\"python\", LOCATIONS[\"protected-pip\"]) + arguments\n    kwargs = {\"env\": env, \"silent\": True}\n    session.run(*command, **kwargs)\n\n\ndef should_update_common_wheels():\n    # If the cache hasn't been created, create it.\n    if not os.path.exists(LOCATIONS[\"common-wheels\"]):\n        return True\n\n    # If the requirements was updated after cache, we'll repopulate it.\n    cache_last_populated_at = os.path.getmtime(LOCATIONS[\"common-wheels\"])\n    requirements_updated_at = os.path.getmtime(REQUIREMENTS[\"common-wheels\"])\n    need_to_repopulate = requirements_updated_at > cache_last_populated_at\n\n    # Clear the stale cache.\n    if need_to_repopulate:\n        shutil.rmtree(LOCATIONS[\"common-wheels\"], ignore_errors=True)\n\n    return need_to_repopulate\n\n\n# -----------------------------------------------------------------------------\n# Development Commands\n#   These are currently prototypes to evaluate whether we want to switch over\n#   completely to nox for all our automation. Contributors should prefer using\n#   `tox -e ...` until this note is removed.\n# -----------------------------------------------------------------------------\n@nox.session(python=[\"2.7\", \"3.5\", \"3.6\", \"3.7\", \"3.8\", \"3.9\", \"pypy\", \"pypy3\"])\ndef test(session):\n    # Get the common wheels.\n    if should_update_common_wheels():\n        run_with_protected_pip(\n            session,\n            \"wheel\",\n            \"-w\", LOCATIONS[\"common-wheels\"],\n            \"-r\", REQUIREMENTS[\"common-wheels\"],\n        )\n    else:\n        msg = (\n            \"Re-using existing common-wheels at {}.\"\n            .format(LOCATIONS[\"common-wheels\"])\n        )\n        session.log(msg)\n\n    # Build source distribution\n    sdist_dir = os.path.join(session.virtualenv.location, \"sdist\")\n    if os.path.exists(sdist_dir):\n        shutil.rmtree(sdist_dir, ignore_errors=True)\n    session.run(\n        \"python\", \"setup.py\", \"sdist\",\n        \"--formats=zip\", \"--dist-dir\", sdist_dir,\n        silent=True,\n    )\n    generated_files = os.listdir(sdist_dir)\n    assert len(generated_files) == 1\n    generated_sdist = os.path.join(sdist_dir, generated_files[0])\n\n    # Install source distribution\n    run_with_protected_pip(session, \"install\", generated_sdist)\n\n    # Install test dependencies\n    run_with_protected_pip(session, \"install\", \"-r\", REQUIREMENTS[\"tests\"])\n\n    # Parallelize tests as much as possible, by default.\n    arguments = session.posargs or [\"-n\", \"auto\"]\n\n    # Run the tests\n    #   LC_CTYPE is set to get UTF-8 output inside of the subprocesses that our\n    #   tests use.\n    session.run(\"pytest\", *arguments, env={\"LC_CTYPE\": \"en_US.UTF-8\"})\n\n\n@nox.session\ndef docs(session):\n    session.install(\"-e\", \".\")\n    session.install(\"-r\", REQUIREMENTS[\"docs\"])\n\n    def get_sphinx_build_command(kind):\n        # Having the conf.py in the docs/html is weird but needed because we\n        # can not use a different configuration directory vs source directory\n        # on RTD currently. So, we'll pass \"-c docs/html\" here.\n        # See https://github.com/rtfd/readthedocs.org/issues/1543.\n        return [\n            \"sphinx-build\",\n            \"-W\",\n            \"-c\", \"docs/html\",  # see note above\n            \"-d\", \"docs/build/doctrees/\" + kind,\n            \"-b\", kind,\n            \"docs/\" + kind,\n            \"docs/build/\" + kind,\n        ]\n\n    session.run(*get_sphinx_build_command(\"html\"))\n    session.run(*get_sphinx_build_command(\"man\"))\n\n\n@nox.session\ndef lint(session):\n    session.install(\"pre-commit\")\n\n    if session.posargs:\n        args = session.posargs + [\"--all-files\"]\n    else:\n        args = [\"--all-files\", \"--show-diff-on-failure\"]\n\n    session.run(\"pre-commit\", \"run\", *args)\n    session.run(\n        \"pre-commit\", \"run\", \"-c\", \".pre-commit-config-slow.yaml\", *args\n    )\n\n\n@nox.session\ndef vendoring(session):\n    session.install(\"vendoring>=0.3.0\")\n\n    if \"--upgrade\" not in session.posargs:\n        session.run(\"vendoring\", \"sync\", \".\", \"-v\")\n        return\n\n    def pinned_requirements(path):\n        for line in path.read_text().splitlines():\n            one, two = line.split(\"==\", 1)\n            name = one.strip()\n            version = two.split(\"#\")[0].strip()\n            yield name, version\n\n    vendor_txt = Path(\"src/pip/_vendor/vendor.txt\")\n    for name, old_version in pinned_requirements(vendor_txt):\n        if name == \"setuptools\":\n            continue\n\n        # update requirements.txt\n        session.run(\"vendoring\", \"update\", \".\", name)\n\n        # get the updated version\n        new_version = old_version\n        for inner_name, inner_version in pinned_requirements(vendor_txt):\n            if inner_name == name:\n                # this is a dedicated assignment, to make flake8 happy\n                new_version = inner_version\n                break\n        else:\n            session.error(f\"Could not find {name} in {vendor_txt}\")\n\n        # check if the version changed.\n        if new_version == old_version:\n            continue  # no change, nothing more to do here.\n\n        # synchronize the contents\n        session.run(\"vendoring\", \"sync\", \".\")\n\n        # Determine the correct message\n        message = f\"Upgrade {name} to {new_version}\"\n\n        # Write our news fragment\n        news_file = Path(\"news\") / (name + \".vendor.rst\")\n        news_file.write_text(message + \"\\n\")  # \"\\n\" appeases end-of-line-fixer\n\n        # Commit the changes\n        release.commit_file(session, \".\", message=message)\n\n\n# -----------------------------------------------------------------------------\n# Release Commands\n# -----------------------------------------------------------------------------\n@nox.session(name=\"prepare-release\")\ndef prepare_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s prepare-release -- <version>\")\n\n    session.log(\"# Ensure nothing is staged\")\n    if release.modified_files_in_git(\"--staged\"):\n        session.error(\"There are files staged in git\")\n\n    session.log(f\"# Updating {AUTHORS_FILE}\")\n    release.generate_authors(AUTHORS_FILE)\n    if release.modified_files_in_git():\n        release.commit_file(\n            session, AUTHORS_FILE, message=f\"Update {AUTHORS_FILE}\",\n        )\n    else:\n        session.log(f\"# No changes to {AUTHORS_FILE}\")\n\n    session.log(\"# Generating NEWS\")\n    release.generate_news(session, version)\n\n    session.log(f\"# Bumping for release {version}\")\n    release.update_version_file(version, VERSION_FILE)\n    release.commit_file(session, VERSION_FILE, message=\"Bump for release\")\n\n    session.log(\"# Tagging release\")\n    release.create_git_tag(session, version, message=f\"Release {version}\")\n\n    session.log(\"# Bumping for development\")\n    next_dev_version = release.get_next_development_version(version)\n    release.update_version_file(next_dev_version, VERSION_FILE)\n    release.commit_file(session, VERSION_FILE, message=\"Bump for development\")\n\n\n@nox.session(name=\"build-release\")\ndef build_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s build-release -- YY.N[.P]\")\n\n    session.log(\"# Ensure no files in dist/\")\n    if release.have_files_in_folder(\"dist\"):\n        session.error(\n            \"There are files in dist/. Remove them and try again. \"\n            \"You can use `git clean -fxdi -- dist` command to do this\"\n        )\n\n    session.log(\"# Install dependencies\")\n    session.install(\"setuptools\", \"wheel\", \"twine\")\n\n    with release.isolated_temporary_checkout(session, version) as build_dir:\n        session.log(\n            \"# Start the build in an isolated, \"\n            f\"temporary Git checkout at {build_dir!s}\",\n        )\n        with release.workdir(session, build_dir):\n            tmp_dists = build_dists(session)\n\n        tmp_dist_paths = (build_dir / p for p in tmp_dists)\n        session.log(f\"# Copying dists from {build_dir}\")\n        os.makedirs('dist', exist_ok=True)\n        for dist, final in zip(tmp_dist_paths, tmp_dists):\n            session.log(f\"# Copying {dist} to {final}\")\n            shutil.copy(dist, final)\n\n\ndef build_dists(session):\n    \"\"\"Return dists with valid metadata.\"\"\"\n    session.log(\n        \"# Check if there's any Git-untracked files before building the wheel\",\n    )\n\n    has_forbidden_git_untracked_files = any(\n        # Don't report the environment this session is running in\n        not untracked_file.startswith('.nox/build-release/')\n        for untracked_file in release.get_git_untracked_files()\n    )\n    if has_forbidden_git_untracked_files:\n        session.error(\n            \"There are untracked files in the working directory. \"\n            \"Remove them and try again\",\n        )\n\n    session.log(\"# Build distributions\")\n    session.run(\"python\", \"setup.py\", \"sdist\", \"bdist_wheel\", silent=True)\n    produced_dists = glob.glob(\"dist/*\")\n\n    session.log(f\"# Verify distributions: {', '.join(produced_dists)}\")\n    session.run(\"twine\", \"check\", *produced_dists, silent=True)\n\n    return produced_dists\n\n\n@nox.session(name=\"upload-release\")\ndef upload_release(session):\n    version = release.get_version_from_arguments(session)\n    if not version:\n        session.error(\"Usage: nox -s upload-release -- YY.N[.P]\")\n\n    session.log(\"# Install dependencies\")\n    session.install(\"twine\")\n\n    distribution_files = glob.glob(\"dist/*\")\n    session.log(f\"# Distribution files: {distribution_files}\")\n\n    # Sanity check: Make sure there's 2 distribution files.\n    count = len(distribution_files)\n    if count != 2:\n        session.error(\n            f\"Expected 2 distribution files for upload, got {count}. \"\n            f\"Remove dist/ and run 'nox -s build-release -- {version}'\"\n        )\n    # Sanity check: Make sure the files are correctly named.\n    distfile_names = map(os.path.basename, distribution_files)\n    expected_distribution_files = [\n        f\"pip-{version}-py2.py3-none-any.whl\",\n        f\"pip-{version}.tar.gz\",\n    ]\n    if sorted(distfile_names) != sorted(expected_distribution_files):\n        session.error(\n            f\"Distribution files do not seem to be for {version} release.\"\n        )\n\n    session.log(\"# Upload distributions\")\n    session.run(\"twine\", \"upload\", *distribution_files)\n", "path": "noxfile.py"}]}