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

Include markers issue #5092 #5114

Merged
merged 9 commits into from
Jun 25, 2022
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
1 change: 1 addition & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ flag::
pytest==3.2.3

Adding the ``--hash`` flag will add package hashes to the output for extra security.
Adding the ``--exclude-markers`` flagwill exclude the markers from the output.
Copy link
Member

Choose a reason for hiding this comment

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

typo need space flag will -- I tried to edit this but I don't think I can directly without some hoop jumping.


The locked requirements are written to stdout, with shell output redirection
used to write them to a file::
Expand Down
1 change: 1 addition & 0 deletions news/5092.behavior.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adjust ``pipenv requirements`` to add markers and add an ``--exclude-markers`` option to allow the exclusion of markers
9 changes: 5 additions & 4 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,9 @@ def verify(state):
"--dev-only", is_flag=True, default=False, help="Only add development requirements."
)
@option("--hash", is_flag=True, default=False, help="Add package hashes.")
@option("--exclude-markers", is_flag=True, default=False, help="Exclude markers.")
@pass_state
def requirements(state, dev=False, dev_only=False, hash=False):
def requirements(state, dev=False, dev_only=False, hash=False, exclude_markers=False):

from pipenv.utils.dependencies import convert_deps_to_pip

Expand All @@ -776,18 +777,18 @@ def requirements(state, dev=False, dev_only=False, hash=False):

deps = {}

if not dev_only:
deps.update(lockfile["default"])
if dev or dev_only:
deps.update(lockfile["develop"])
if not dev_only:
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for flipping the ordering here!

deps.update(lockfile["default"])

pip_deps = convert_deps_to_pip(
deps,
project=None,
r=False,
include_index=False,
include_hashes=hash,
include_markers=False,
include_markers=not exclude_markers,
)

for d in pip_deps:
Expand Down
54 changes: 54 additions & 0 deletions tests/integration/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_requirements_generates_requirements_from_lockfile_multiple_sources(Pipe
assert '-i https://pypi.org/simple' in c.stdout
assert '--extra-index-url https://some_other_source.org' in c.stdout


@pytest.mark.requirements
def test_requirements_with_git_requirements(PipenvInstance):
req_name, req_hash = 'example-repo', 'cc858e89f19bc0dbd70983f86b811ab625dc9292'
Expand All @@ -97,6 +98,59 @@ def test_requirements_with_git_requirements(PipenvInstance):


@pytest.mark.requirements
def test_requirements_markers_get_included(PipenvInstance):
package, version, markers = "werkzeug", "==2.1.2", "python_version >= '3.7'"
lockfile = {
"_meta": {"sources": []},
"default": {
package: {
"hashes": [
"sha256:1ce08e8093ed67d638d63879fd1ba3735817f7a80de3674d293f5984f25fb6e6",
"sha256:72a4b735692dd3135217911cbeaa1be5fa3f62bffb8745c5215420a03dc55255"
],
"markers": markers,
"version": version
}
},
"develop": {}
}

with PipenvInstance(chdir=True) as p:
with open(p.lockfile_path, 'w') as f:
json.dump(lockfile, f)

c = p.pipenv('requirements')
assert c.returncode == 0
assert f'{package}{version}; {markers}' in c.stdout


@pytest.mark.requirements
def test_requirements_markers_get_excluded(PipenvInstance):
package, version, markers = "werkzeug", "==2.1.2", "python_version >= '3.7'"
lockfile = {
"_meta": {"sources": []},
"default": {
package: {
"hashes": [
"sha256:1ce08e8093ed67d638d63879fd1ba3735817f7a80de3674d293f5984f25fb6e6",
"sha256:72a4b735692dd3135217911cbeaa1be5fa3f62bffb8745c5215420a03dc55255"
],
"markers": markers,
"version": version
}
},
"develop": {}
}

with PipenvInstance(chdir=True) as p:
with open(p.lockfile_path, 'w') as f:
json.dump(lockfile, f)

c = p.pipenv('requirements --exclude-markers')
assert c.returncode == 0
assert markers not in c.stdout


def test_requirements_generates_requirements_from_lockfile_without_env_var_expansion(
PipenvInstance,
):
Expand Down