diff --git a/pipenv/core.py b/pipenv/core.py index bb7993e2..69bf0f82 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1007,6 +1007,8 @@ def do_lock( write=True, ): """Executes the freeze functionality.""" + from notpip._vendor.distlib.markers import Evaluator + allowed_marker_keys = ['markers'] + [k for k in Evaluator.allowed_values.keys()] cached_lockfile = {} if keep_outdated: if not project.lockfile_exists: @@ -1064,9 +1066,12 @@ def do_lock( # Add index metadata to lockfile. if 'index' in dep: lockfile['develop'][dep['name']]['index'] = dep['index'] - # Add PEP 508 specifier metadata to lockfile if dep isnt top level. - if 'markers' in dep and not any(dep['name'] in section for section in [dev_packages, project.packages]): - lockfile['develop'][dep['name']]['markers'] = dep['markers'] + # Add PEP 508 specifier metadata to lockfile if dep isnt top level + # or top level dep doesn't itself have markers + if 'markers' in dep: + if dep['name'] in dev_packages and not any(key in dev_packages[dep['name']] for key in allowed_marker_keys): + continue + lockfile['develop'][dep['name']]['markers'] = dep[marker_key] # Add refs for VCS installs. # TODO: be smarter about this. vcs_deps = convert_deps_to_pip(project.vcs_dev_packages, project, r=False) @@ -1120,8 +1125,11 @@ def do_lock( # Add index metadata to lockfile. if 'index' in dep: lockfile['default'][dep['name']]['index'] = dep['index'] - # Add PEP 508 specifier metadata to lockfile if dep isn't top level. - if 'markers' in dep and dep['name'] not in project.packages: + # Add PEP 508 specifier metadata to lockfile if dep isn't top level + # or top level dep has no specifiers itself + if 'markers' in dep: + if dep['name'] in project.packages and not any(key in project.packages[dep['name']] for key in allowed_marker_keys): + continue lockfile['default'][dep['name']]['markers'] = dep['markers'] # Add refs for VCS installs. # TODO: be smarter about this. diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index c6ae4110..012664e5 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -558,9 +558,9 @@ tpfd = "*" @pytest.mark.run @pytest.mark.markers @pytest.mark.install - def test_package_environment_markers(self): + def test_package_environment_markers(self, pypi): - with PipenvInstance() as p: + with PipenvInstance(pypi=pypi) as p: with open(p.pipfile_path, 'w') as f: contents = """ [packages] @@ -570,7 +570,6 @@ requests = {version = "*", markers="os_name=='splashwear'"} c = p.pipenv('install') assert c.return_code == 0 - assert 'Ignoring' in c.out assert 'markers' in p.lockfile['default']['requests']