Skip to content

Commit

Permalink
refactor: remove unused spack.stage._get_mirrors() function
Browse files Browse the repository at this point in the history
  • Loading branch information
tldahlgren authored and tgamblin committed Jun 6, 2019
1 parent 8e3fd3f commit eb584d8
Showing 1 changed file with 24 additions and 37 deletions.
61 changes: 24 additions & 37 deletions lib/spack/spack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from spack.util.path import canonicalize_path
from spack.util.crypto import prefix_bits, bit_length

_source_path_subdir = 'src'
_stage_prefix = 'spack-stage-'


Expand All @@ -46,8 +47,9 @@ def _first_accessible_path(paths):
# return it if successful.
return path

except OSError:
tty.debug('OSError while checking temporary path: %s' % path)
except OSError as e:
tty.debug('OSError while checking temporary path %s: %s' % (
path, str(e)))
continue

return None
Expand Down Expand Up @@ -78,7 +80,7 @@ def get_tmp_root():
_use_tmp_stage = False
return None

# ensure that any temp path is unique per user, so users don't
# Ensure that any temp path is unique per user, so users don't
# fight over shared temporary space.
user = getpass.getuser()
if user not in path:
Expand Down Expand Up @@ -292,13 +294,18 @@ def _need_to_create_path(self):
def expected_archive_files(self):
"""Possible archive file paths."""
paths = []
if isinstance(self.default_fetcher, fs.URLFetchStrategy):
paths.append(os.path.join(
self.path, os.path.basename(self.default_fetcher.url)))
roots = [self.path]
if self.expanded:
roots.insert(0, self.source_path)

if self.mirror_path:
paths.append(os.path.join(
self.path, os.path.basename(self.mirror_path)))
for path in roots:
if isinstance(self.default_fetcher, fs.URLFetchStrategy):
paths.append(os.path.join(
path, os.path.basename(self.default_fetcher.url)))

if self.mirror_path:
paths.append(os.path.join(
path, os.path.basename(self.mirror_path)))

return paths

Expand All @@ -321,27 +328,14 @@ def archive_file(self):
return None

@property
def source_path(self):
"""Returns the path to the expanded/checked out source code.
To find the source code, this method searches for the first
subdirectory of the stage that it can find, and returns it.
This assumes nothing besides the archive file will be in the
stage path, but it has the advantage that we don't need to
know the name of the archive or its contents.
def expanded(self):
"""Returns True if source path expanded; else False."""
return os.path.exists(self.source_path)

If the fetch strategy is not supposed to expand the downloaded
file, it will just return the stage path. If the archive needs
to be expanded, it will return None when no archive is found.
"""
if isinstance(self.fetcher, fs.URLFetchStrategy):
if not self.fetcher.expand_archive:
return self.path

for p in [os.path.join(self.path, f) for f in os.listdir(self.path)]:
if os.path.isdir(p):
return p
return None
@property
def source_path(self):
"""Returns the well-known source directory path."""
return os.path.join(self.path, _source_path_subdir)

def fetch(self, mirror_only=False):
"""Downloads an archive or checks out code from a repository."""
Expand Down Expand Up @@ -441,8 +435,7 @@ def expand_archive(self):
"""Changes to the stage directory and attempt to expand the downloaded
archive. Fail if the stage is not set up or if the archive is not yet
downloaded."""
archive_dir = self.source_path
if not archive_dir:
if not self.expanded:
self.fetcher.expand()
tty.msg("Created stage in %s" % self.path)
else:
Expand Down Expand Up @@ -635,12 +628,6 @@ def cache_local(self):
tty.msg("Sources for DIY stages are not cached")


def _get_mirrors():
"""Get mirrors from spack configuration."""
config = spack.config.get('mirrors')
return [val for name, val in iteritems(config)]


def ensure_access(file=spack.paths.stage_path):
"""Ensure we can access a directory and die with an error if we can't."""
if not can_access(file):
Expand Down

0 comments on commit eb584d8

Please sign in to comment.