Skip to content

Commit

Permalink
Working caching under vt.results dir. Moving to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Livingston committed Jan 30, 2018
1 parent edf110d commit dacd672
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from pants.backend.python.tasks2.setup_py import SetupPyRunner
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.fingerprint_strategy import DefaultFingerprintStrategy
from pants.task.task import Task
from pants.util.dirutil import safe_mkdir
from pants.util.dirutil import safe_mkdir, safe_mkdir_for


class PythonCreateDistributions(Task):
Expand All @@ -36,37 +37,37 @@ def is_distribution(target):
return isinstance(target, PythonDistribution)

@property
def _local_dists_work_dir(self):
def local_dists_workdir(self):
return os.path.join(self.workdir, 'local_dists')

@property
def cache_target_dirs(self):
return True

def execute(self):
dist_targets = self.context.targets(self.is_distribution)
built_dists = set()

if dist_targets:
local_dists_workdir = self._local_dists_work_dir
if not os.path.exists(self._local_dists_workdir):
local_dists_workdir = self.local_dists_workdir
if not os.path.exists(self.local_dists_workdir):
safe_mkdir(local_dists_workdir)

targets = self.context.targets(predicate=lambda t: is_local_python_dist(t))
with self.invalidated(targets,
with self.invalidated(dist_targets,
fingerprint_strategy=DefaultFingerprintStrategy(),
invalidate_dependents=True) as invalidation_check:
for vt in invalidation_check.all_vts:
if vt.valid:
install_dir = os.path.join(local_dists_workdir, vt.fingerprint, "dist")
built_dists.add(self._get_whl_from_dir(install_dir))
built_dists.add(self._get_whl_from_dir(os.path.join(vt.results_dir, 'dist')))
else:
built_dists.add(self._create_dist(vt.target))
built_dists.add(self._create_dist(vt.target, vt.results_dir))

self.context.products.register_data(self.PYTHON_DISTS, built_dists)

def _create_dist(self, dist_tgt):
def _create_dist(self, dist_tgt, dist_target_dir):
"""Create a .whl file for the specified python_distribution target."""

interpreter = self.context.products.get_data(PythonInterpreter)
dist_target_dir = os.path.join(self._local_dists_workdir, dist_tgt.fingerprint)
log.debug('Creating working directory for target %s with fingerprint %s',
dist_tgt.name, dist_tgt.fingerprint)
safe_mkdir(dist_target_dir)

# Copy sources and setup.py over for packaging.
Expand All @@ -78,14 +79,20 @@ def _create_dist(self, dist_tgt):
sources = zip(sources_rel_to_buildroot, sources_rel_to_target_base)
for source_relative_to_build_root, source_relative_to_target_base in sources:
source_rel_to_dist_dir = os.path.join(dist_target_dir, source_relative_to_target_base)
os.makedirs(os.path.dirname(source_rel_to_dist_dir))
safe_mkdir(os.path.dirname(source_rel_to_dist_dir))
shutil.copyfile(os.path.join(get_buildroot(), source_relative_to_build_root),
source_rel_to_dist_dir)


#for source in dist_tgt.sources_relative_to_source_root():
# dest_source = os.path.join(dist_target_dir, source)
#safe_mkdir_for(dest_source)
#shutil.copyfile(os.path.join(dist_tgt.target_base, source), dest_source)


# Build the whl from pex API using tempdir and get its location.
install_dir = os.path.join(dist_target_dir, 'dist')
safe_mkdir(install_dir)

setup_runner = SetupPyRunner(dist_target_dir, 'bdist_wheel', interpreter=interpreter, install_dir=install_dir)
setup_runner.run()
return self._get_whl_from_dir(install_dir)
Expand All @@ -98,4 +105,4 @@ def _get_whl_from_dir(self, install_dir):
elif len(dists) > 1:
raise TaskError('Ambiguous whls found: %s' % (' '.join(dists)))
else:
return os.path.join(install_dir, dists[0])
return os.path.join(os.path.abspath(install_dir), dists[0])

0 comments on commit dacd672

Please sign in to comment.