Skip to content

Commit

Permalink
Cleanups for 3bdd550 that I forgot to push before merging. (pantsbuil…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjyw authored Feb 28, 2018
1 parent 1cee589 commit 4d28172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ def goroot(self):
:returns: The Go distribution $GOROOT.
:rtype: string
"""
#go_distribution = self.select()
# distribution_workdir = os.path.dirname(go_distribution)
# outdir = os.path.join(distribution_workdir, 'unpacked')
# if not os.path.exists(outdir):
# with temporary_dir(root_dir=distribution_workdir) as tmp_dist:
# TGZ.extract(go_distribution, tmp_dist)
# os.rename(tmp_dist, outdir)
return os.path.join(self.select(), 'go')

def go_env(self, gopath=None):
Expand All @@ -61,7 +54,7 @@ class GoCommand(namedtuple('GoCommand', ['cmdline', 'env'])):
"""Encapsulates a go command that can be executed."""

@classmethod
def create(cls, goroot, cmd, go_env, args=None):
def _create(cls, goroot, cmd, go_env, args=None):
return cls([os.path.join(goroot, 'bin', 'go'), cmd] + (args or []), env=go_env)

def spawn(self, env=None, **kwargs):
Expand Down Expand Up @@ -104,7 +97,7 @@ def create_go_cmd(self, cmd, gopath=None, args=None):
:returns: A go command that can be executed later.
:rtype: :class:`GoDistribution.GoCommand`
"""
return self.GoCommand.create(self.goroot, cmd, go_env=self.go_env(gopath=gopath), args=args)
return self.GoCommand._create(self.goroot, cmd, go_env=self.go_env(gopath=gopath), args=args)

def execute_go_cmd(self, cmd, gopath=None, args=None, env=None,
workunit_factory=None, workunit_name=None, workunit_labels=None, **kwargs):
Expand All @@ -125,7 +118,7 @@ def execute_go_cmd(self, cmd, gopath=None, args=None, env=None,
:returns: A tuple of the exit code and the go command that was run.
:rtype: (int, :class:`GoDistribution.GoCommand`)
"""
go_cmd = self.GoCommand.create(self.goroot, cmd, go_env=self.go_env(gopath=gopath), args=args)
go_cmd = self.GoCommand._create(self.goroot, cmd, go_env=self.go_env(gopath=gopath), args=args)
if workunit_factory is None:
return go_cmd.spawn(**kwargs).wait()
else:
Expand Down
12 changes: 5 additions & 7 deletions src/python/pants/binaries/binary_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from pants.fs.archive import archiver as create_archiver
from pants.net.http.fetcher import Fetcher
from pants.subsystem.subsystem import Subsystem
from pants.util.contextutil import temporary_dir, temporary_file
from pants.util.dirutil import chmod_plus_x, safe_mkdir_for, safe_open
from pants.util.contextutil import temporary_file
from pants.util.dirutil import chmod_plus_x, safe_concurrent_creation, safe_open
from pants.util.osutil import get_os_id


Expand Down Expand Up @@ -176,7 +176,7 @@ def _select_archive(self, supportdir, version, name, platform_dependent, archive
"""
full_name = '{}.{}'.format(name, archiver.extension)
downloaded_file = self._select_file(supportdir, version, full_name, platform_dependent)
# use filename without rightmost extension as the directory name.
# Use filename without rightmost extension as the directory name.
unpacked_dirname, _ = os.path.splitext(downloaded_file)
if not os.path.exists(unpacked_dirname):
archiver.extract(downloaded_file, unpacked_dirname)
Expand Down Expand Up @@ -238,9 +238,7 @@ def _fetch_binary(self, name, binary_path):
bootstrap_dir = os.path.realpath(os.path.expanduser(self._pants_bootstrapdir))
bootstrapped_binary_path = os.path.join(bootstrap_dir, binary_path)
if not os.path.exists(bootstrapped_binary_path):
safe_mkdir_for(bootstrapped_binary_path)
with temporary_dir(root_dir=os.path.dirname(bootstrapped_binary_path)) as tmpdir:
downloadpath = os.path.join(tmpdir, 'download')
with safe_concurrent_creation(bootstrapped_binary_path) as downloadpath:
with self._select_binary_stream(name, binary_path) as stream:
with safe_open(downloadpath, 'wb') as bootstrapped_binary:
bootstrapped_binary.write(stream())
Expand All @@ -260,7 +258,7 @@ def _compare_file_checksums(filepath, checksum=None, digest=None):

return os.path.isfile(filepath)

def is_bin_valid(self, basepath, binary_file_specs=tuple()):
def is_bin_valid(self, basepath, binary_file_specs=()):
"""Check if this bin path is valid.
:param string basepath: The absolute path where the binaries are stored under.
Expand Down

0 comments on commit 4d28172

Please sign in to comment.