Skip to content

Commit

Permalink
Log which python version was used during compile (#828)
Browse files Browse the repository at this point in the history
* log which python version to use/was used Fixes #827

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update writer.py

* Update writer.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix tests

Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
  • Loading branch information
graingert and ssbarnea authored Jun 9, 2021
1 parent 32a8834 commit c7e6d84
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
6 changes: 5 additions & 1 deletion piptools/writer.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -91,7 +92,10 @@ 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 with python "
f"{sys.version_info.major}.{sys.version_info.minor}"
)
yield comment("# To update, run:")
yield comment("#")
compile_command = os.environ.get(
Expand Down
30 changes: 18 additions & 12 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 -
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import pytest
from pip._internal.models.format_control import FormatControl

Expand Down Expand Up @@ -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(
Expand All @@ -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",
Expand Down

0 comments on commit c7e6d84

Please sign in to comment.