From 97693f6423e7026b563d826d9cf5e3bc78bfea5b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 28 May 2019 10:06:56 +0100 Subject: [PATCH 1/6] log which python version to use/was used Fixes #827 --- piptools/writer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/piptools/writer.py b/piptools/writer.py index 1d319f21a..14a764680 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -91,7 +91,9 @@ def _sort_key(self, ireq: InstallRequirement) -> Tuple[bool, str]: def write_header(self) -> Iterator[str]: if self.emit_header: yield comment("#") - yield comment("# This file is autogenerated by pip-compile") + yield comment("# This file is autogenerated by pip-compile on:") + for line in sys.version.split('\n'): + yield comment("# {}".format(line)) yield comment("# To update, run:") yield comment("#") compile_command = os.environ.get( From 5624c39fb1d4006c2990db75ace8a589dd49314d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Jun 2021 09:21:42 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- piptools/writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/piptools/writer.py b/piptools/writer.py index 14a764680..cacdc0dc8 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -92,8 +92,8 @@ def write_header(self) -> Iterator[str]: if self.emit_header: yield comment("#") yield comment("# This file is autogenerated by pip-compile on:") - for line in sys.version.split('\n'): - yield comment("# {}".format(line)) + for line in sys.version.split("\n"): + yield comment(f"# {line}") yield comment("# To update, run:") yield comment("#") compile_command = os.environ.get( From e5366334f176fc4d9e5599bbb236062afb325841 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sat, 5 Jun 2021 10:24:02 +0100 Subject: [PATCH 3/6] Update writer.py --- piptools/writer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/piptools/writer.py b/piptools/writer.py index cacdc0dc8..cdc9556c1 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -1,5 +1,6 @@ import os import re +import sys from itertools import chain from typing import BinaryIO, Dict, Iterable, Iterator, List, Optional, Set, Tuple From 8a9659c30117cd087b1b761677760b2c3a723ea0 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sat, 5 Jun 2021 10:32:18 +0100 Subject: [PATCH 4/6] Update writer.py --- piptools/writer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/piptools/writer.py b/piptools/writer.py index cdc9556c1..00bb03101 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -92,9 +92,9 @@ def _sort_key(self, ireq: InstallRequirement) -> Tuple[bool, str]: def write_header(self) -> Iterator[str]: if self.emit_header: yield comment("#") - yield comment("# This file is autogenerated by pip-compile on:") - for line in sys.version.split("\n"): - yield comment(f"# {line}") + yield comment( + "# This file is autogenerated by pip-compile with python " + f"{sys.version_info.major}.{sys.version_info.minor}") yield comment("# To update, run:") yield comment("#") compile_command = os.environ.get( From c3752e1665b61aba1d43a9dfc8085db1651daa69 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Jun 2021 09:32:33 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- piptools/writer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/piptools/writer.py b/piptools/writer.py index 00bb03101..d07ee677f 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -94,7 +94,8 @@ def write_header(self) -> Iterator[str]: yield comment("#") yield comment( "# This file is autogenerated by pip-compile with python " - f"{sys.version_info.major}.{sys.version_info.minor}") + f"{sys.version_info.major}.{sys.version_info.minor}" + ) yield comment("# To update, run:") yield comment("#") compile_command = os.environ.get( From cbee45632925b79577447d20426ec8a2d8084cb5 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 9 Jun 2021 15:08:32 +0100 Subject: [PATCH 6/6] Fix tests --- tests/test_cli_compile.py | 30 ++++++++++++++++++------------ tests/test_writer.py | 8 ++++++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 660552ea6..572de0d5d 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -808,9 +808,10 @@ def test_generate_hashes_with_annotations(runner): out = runner.invoke(cli, ["--generate-hashes"]) assert out.stderr == dedent( - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --generate-hashes @@ -835,9 +836,10 @@ def test_generate_hashes_with_long_annotations(runner): out = runner.invoke(cli, ["--generate-hashes"]) assert out.stderr == dedent( - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --generate-hashes @@ -976,9 +978,10 @@ def test_stdin(pip_conf, runner): ) assert out.stderr == dedent( - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --no-emit-find-links --output-file=requirements.txt - @@ -1013,9 +1016,10 @@ def test_multiple_input_files_without_output_file(runner): ( pytest.param( "--annotate", - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --no-emit-find-links @@ -1032,9 +1036,10 @@ def test_multiple_input_files_without_output_file(runner): ), pytest.param( "--no-annotate", - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --no-annotate --no-emit-find-links @@ -1278,9 +1283,10 @@ def test_upgrade_package_doesnt_remove_annotation(pip_conf, runner): runner.invoke(cli, ["-P", "small-fake-a", "--no-emit-find-links"]) with open("requirements.txt") as req_txt: assert req_txt.read() == dedent( - """\ + f"""\ # - # This file is autogenerated by pip-compile + # This file is autogenerated by pip-compile with python \ +{sys.version_info.major}.{sys.version_info.minor} # To update, run: # # pip-compile --no-emit-find-links diff --git a/tests/test_writer.py b/tests/test_writer.py index 7a3d82d2f..6b79ed4ff 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1,3 +1,5 @@ +import sys + import pytest from pip._internal.models.format_control import FormatControl @@ -184,7 +186,8 @@ def test_write_header(writer): comment, [ "#", - "# This file is autogenerated by pip-compile", + "# This file is autogenerated by pip-compile with python " + f"{sys.version_info.major}.{sys.version_info.minor}", "# To update, run:", "#", "# pip-compile --output-file={} src_file src_file2".format( @@ -202,7 +205,8 @@ def test_write_header_custom_compile_command(writer, monkeypatch): comment, [ "#", - "# This file is autogenerated by pip-compile", + "# This file is autogenerated by pip-compile with python " + f"{sys.version_info.major}.{sys.version_info.minor}", "# To update, run:", "#", "# ./pipcompilewrapper",