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 2 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
26 changes: 26 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,29 @@ 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
def test_flit(runner):
atugushev marked this conversation as resolved.
Show resolved Hide resolved
path = os.path.join(PACKAGES_PATH, "flit_small_with_deps", "pyproject.toml")
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


@pytest.mark.network
def test_setup_cfg(runner):
orsinium marked this conversation as resolved.
Show resolved Hide resolved
path = os.path.join(PACKAGES_PATH, "setup_cfg_small_with_deps", "setup.cfg")
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Sample module
"""

__version__ = "0.1.1" # pragma: no cover
orsinium marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions tests/test_data/packages/flit_small_with_deps/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# This section makes the project installable using pip.
# https://www.python.org/dev/peps/pep-0517/
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "module"
dist-name = "small_fake_with_deps"
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"]
18 changes: 18 additions & 0 deletions tests/test_data/packages/setup_cfg_small_with_deps/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[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