Skip to content

Commit

Permalink
Include markers issue #5092 (#5114)
Browse files Browse the repository at this point in the history
* Include markers

* Change to marker flag and include test

* Flip markers flag to exclude by default

* Docs and newsfile

* Let default dependencies update dev dependencies
  • Loading branch information
ImreC authored Jun 25, 2022
1 parent d2365bb commit 37b1fb4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
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.

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:
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

0 comments on commit 37b1fb4

Please sign in to comment.