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

Fix pants_requirement by allowing Python 3 #6391

Merged
merged 5 commits into from Aug 28, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion build-support/known_py3_failures.txt
Expand Up @@ -5,7 +5,6 @@ tests/python/pants_test/backend/jvm/tasks:jar_publish
tests/python/pants_test/backend/jvm/tasks:junit_run
tests/python/pants_test/backend/jvm/tasks:resources_task
tests/python/pants_test/backend/python/tasks:tasks
tests/python/pants_test/backend/python:pants_requirement
tests/python/pants_test/binaries:binaries
tests/python/pants_test/build_graph:build_file_parser
tests/python/pants_test/build_graph:build_graph
Expand Down
4 changes: 1 addition & 3 deletions src/python/pants/backend/python/pants_requirement.py
Expand Up @@ -50,9 +50,7 @@ def __call__(self, name=None, dist=None):
msg='The {} target only works for pantsbuild.pants '
'distributions, given {}'.format(self.alias, dist))

# TODO(John Sirois): Modify to constraint to >=3.5,<4 as part of
# https://github.com/pantsbuild/pants/issues/6062
env_marker = "python_version>='2.7' and python_version<'3'"
env_marker = "python_version>='3.4' or (python_version>='2.7' and python_version<'3')"

requirement = PythonRequirement(requirement="{key}=={version} ; {env_marker}"
.format(key=dist,
Expand Down
11 changes: 8 additions & 3 deletions tests/python/pants_test/backend/python/test_pants_requirement.py
Expand Up @@ -35,9 +35,14 @@ def key(python_requirement):
self.assertIsNotNone(req.requirement.marker)
self.assertTrue(req.requirement.marker.evaluate(),
'pants_requirement() should always work in the current test environment')
self.assertFalse(req.requirement.marker.evaluate({'python_version': '3.5'}))
self.assertFalse(req.requirement.marker.evaluate({'python_version': '2.6'}))
self.assertTrue(req.requirement.marker.evaluate({'python_version': '2.7'}))

def evaluate_version(version):
return req.requirement.marker.evaluate({'python_version': version})

allowed_versions = {'2.7', '3.4', '3.5', '3.6', '3.7'}

self.assertFalse(evaluate_version('2.6'))
self.assertTrue(all(evaluate_version(v) for v in allowed_versions))

def test_default_name(self):
self.add_to_build_file('3rdparty/python/pants', 'pants_requirement()')
Expand Down