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

PEP-517 support #1356

Merged
merged 6 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ build
dist
*.egg-info
.coverage
.coverage.*
coverage.xml
.cache

# IDE
Expand Down
5 changes: 3 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

DEFAULT_REQUIREMENTS_FILE = "requirements.in"
DEFAULT_REQUIREMENTS_OUTPUT_FILE = "requirements.txt"
METADATA_FILENAMES = frozenset({"setup.py", "setup.cfg", "pyproject.toml"})


def _get_default_option(option_name: str) -> Any:
Expand Down Expand Up @@ -247,7 +248,7 @@ def cli(
if src_files == ("-",):
raise click.BadParameter("--output-file is required if input is from stdin")
# Use default requirements output file if there is a setup.py the source file
elif os.path.basename(src_files[0]) == "setup.py":
elif os.path.basename(src_files[0]) in METADATA_FILENAMES:
file_name = os.path.join(
os.path.dirname(src_files[0]), DEFAULT_REQUIREMENTS_OUTPUT_FILE
)
Expand Down Expand Up @@ -335,7 +336,7 @@ def cli(

constraints = []
for src_file in src_files:
is_setup_file = os.path.basename(src_file) == "setup.py"
is_setup_file = os.path.basename(src_file) in METADATA_FILENAMES
if src_file == "-":
# pip requires filenames and not files. Since we want to support
# piping from stdin, we need to briefly save the input from stdin
Expand Down
116 changes: 116 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,119 @@ def test_triple_equal_pinned_dependency_is_used(
assert out.exit_code == 0, out
for line in out_expected_content:
assert line in out.stderr


@pytest.mark.network
@pytest.mark.parametrize(
("fname", "content"),
(
pytest.param(
"setup.cfg",
"""
[metadata]
name = sample_lib
author = Vincent Driessen
author_email = [email protected]

[options]
packages = find:
install_requires =
small-fake-a==0.1
small-fake-b==0.2

[options.extras_require]
dev =
small-fake-c==0.3
small-fake-d==0.4
test =
small-fake-e==0.5
small-fake-f==0.6
""",
atugushev marked this conversation as resolved.
Show resolved Hide resolved
id="setup.cfg",
),
pytest.param(
"setup.py",
"""
from setuptools import setup

setup(
name="sample_lib",
version=0.1,
install_requires=["small-fake-a==0.1", "small-fake-b==0.2"],
extras_require={
"dev": ["small-fake-c==0.3", "small-fake-d==0.4"],
"test": ["small-fake-e==0.5", "small-fake-f==0.6"],
},
)
""",
id="setup.py",
),
pytest.param(
"pyproject.toml",
"""
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "sample_lib"
author = "Vincent Driessen"
author-email = "[email protected]"

requires = ["small-fake-a==0.1", "small-fake-b==0.2"]

[tool.flit.metadata.requires-extra]
dev = ["small-fake-c==0.3", "small-fake-d==0.4"]
test = ["small-fake-e==0.5", "small-fake-f==0.6"]
""",
id="flit",
),
pytest.param(
"pyproject.toml",
"""
[build-system]
requires = ["poetry_core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "sample_lib"
version = "0.1.0"
description = ""
authors = ["Vincent Driessen <[email protected]>"]

[tool.poetry.dependencies]
python = "*"
small-fake-a = "0.1"
small-fake-b = "0.2"

small-fake-c = "0.3"
small-fake-d = "0.4"
small-fake-e = "0.5"
small-fake-f = "0.6"

[tool.poetry.extras]
dev = ["small-fake-c", "small-fake-d"]
test = ["small-fake-e", "small-fake-f"]
""",
id="poetry",
),
),
)
def test_input_formats(runner, tmpdir, fname, content):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmpdir is sorta deprecated (well, at least there's a mention of it being replaced). It's always better to use tmp_path which does the same except it injects pathlib.Path objects instead of py.path which are nicer to work with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I know. But all other tests in this file use tmpdir. I think it's better to keep it consistent and migrate all at once.

path = os.path.join(tmpdir, "sample_lib")
os.mkdir(path)
path = os.path.join(tmpdir, "sample_lib", "__init__.py")
with open(path, "w") as stream:
stream.write("'example module'\n__version__ = '1.2.3'")
path = os.path.join(tmpdir, fname)
with open(path, "w") as stream:
stream.write(dedent(content))

out = runner.invoke(cli, ["-n", path])
assert out.exit_code == 0, out.stderr
assert "small-fake-a==0.1" in out.stderr
assert "small-fake-b==0.2" in out.stderr
assert "small-fake-c" not in out.stderr
assert "small-fake-d" not in out.stderr
assert "small-fake-e" not in out.stderr
assert "small-fake-f" not in out.stderr