Skip to content

Commit

Permalink
Work around (?) pantsbuild#6282.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Aug 8, 2018
1 parent 8c1b411 commit e6a2995
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
36 changes: 20 additions & 16 deletions tests/python/pants_test/backend/python/tasks/test_gather_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pants.build_graph.files import Files
from pants.build_graph.resources import Resources
from pants.source.source_root import SourceRootConfig
from pants.util.contextutil import temporary_dir
from pants_test.task_test_base import TaskTestBase


Expand Down Expand Up @@ -106,19 +107,22 @@ def test_gather_files(self):
self._assert_content_not_in_pex(pex, self.resources)

def _gather_sources(self, target_roots):
context = self.context(target_roots=target_roots, for_subsystems=[PythonSetup, PythonRepos])

# We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly,
# to ensure that the interpreter has setuptools and wheel support.
interpreter = PythonInterpreter.get()
interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(),
PythonRepos.global_instance(),
logger=context.log.debug)
interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)],
filters=[str(interpreter.identity.requirement)])
context.products.get_data(PythonInterpreter, lambda: interpreters[0])

task = self.create_task(context)
task.execute()

return context.products.get_data(GatherSources.PYTHON_SOURCES)
with temporary_dir() as cache_dir:
context = self.context(target_roots=target_roots,
for_subsystems=[PythonSetup, PythonRepos],
options={PythonSetup.options_scope: {'interpreter_cache_dir': cache_dir}})

# We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly,
# to ensure that the interpreter has setuptools and wheel support.
interpreter = PythonInterpreter.get()
interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(),
PythonRepos.global_instance(),
logger=context.log.debug)
interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)],
filters=[str(interpreter.identity.requirement)])
context.products.get_data(PythonInterpreter, lambda: interpreters[0])

task = self.create_task(context)
task.execute()

return context.products.get_data(GatherSources.PYTHON_SOURCES)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.backend.python.tasks.resolve_requirements import ResolveRequirements
from pants.base.build_environment import get_buildroot
from pants.util.contextutil import temporary_file
from pants.util.contextutil import temporary_dir, temporary_file
from pants.util.process_handler import subprocess
from pants_test.task_test_base import TaskTestBase

Expand Down Expand Up @@ -114,23 +114,26 @@ def _fake_target(self, spec, requirement_strs):
requirements=requirements)

def _resolve_requirements(self, target_roots, options=None):
context = self.context(target_roots=target_roots, options=options,
for_subsystems=[PythonSetup, PythonRepos])

# We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly,
# to ensure that the interpreter has setuptools and wheel support.
interpreter = PythonInterpreter.get()
interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(),
PythonRepos.global_instance(),
logger=context.log.debug)
interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)],
filters=[str(interpreter.identity.requirement)])
context.products.get_data(PythonInterpreter, lambda: interpreters[0])

task = self.create_task(context)
task.execute()

return context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX)
with temporary_dir() as cache_dir:
options = options or {}
options.setdefault(PythonSetup.options_scope, {})['interpreter_cache_dir'] = cache_dir
context = self.context(target_roots=target_roots, options=options,
for_subsystems=[PythonSetup, PythonRepos])

# We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly,
# to ensure that the interpreter has setuptools and wheel support.
interpreter = PythonInterpreter.get()
interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(),
PythonRepos.global_instance(),
logger=context.log.debug)
interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)],
filters=[str(interpreter.identity.requirement)])
context.products.get_data(PythonInterpreter, lambda: interpreters[0])

task = self.create_task(context)
task.execute()

return context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX)

def _exercise_module(self, pex, expected_module):
with temporary_file() as f:
Expand Down

0 comments on commit e6a2995

Please sign in to comment.