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 all 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
122 changes: 122 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,125 @@ 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(make_package, make_wheel, runner, tmpdir, fname, content):
dists_path = os.path.join(tmpdir, "dists")
pkg = make_package("small-fake-a", version="0.1")
make_wheel(pkg, dists_path)
pkg = make_package("small-fake-b", version="0.2")
make_wheel(pkg, dists_path)

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", "--find-links", dists_path, 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