Last active
February 8, 2021 18:20
-
-
Save tgamblin/11b6279efa0e49cc0572f23c5bf163ef to your computer and use it in GitHub Desktop.
Use spack to download some source code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env spack-python | |
import os | |
import tempfile | |
from spack.spec import Spec | |
from spack.stage import DIYStage | |
import llnl.util.filesystem as fs | |
# concrtize a spec of what you want to build. | |
spec = Spec("hdf5 @1.10.2").concretized() | |
# the package instance, instantiate with spec, is essentially a class for | |
# "building" the spec with the package.py recipe. | |
pkg = spec.package | |
# set the staging path (this makes all stages download to a new path) | |
# note that there are potentially many stages for a package -- for the | |
# archive, patches, and any resources (extra tarballs) that need to be | |
# downloaded -- those are in pkg.stage[0], pkg.stage[1], etc. | |
pkg.path = os.path.abspath("foo") | |
# omit this contextmanager and call pkg.stage.destroy() manually if you | |
# don't want the stage automatically destroyed. | |
with pkg.stage: | |
# this fetches (if not fetched already) and expands the source into a | |
# stage directory. You may want to call do_patch() instead (or later) | |
# if you want patches applied to the source. | |
pkg.do_stage() | |
# this contextmanager does a chdir into the directory and | |
# automatically chdirs back out. | |
with fs.working_dir(pkg.stage.source_path) as path: | |
# do stuff in the checked out source path | |
print(path) | |
print(os.getcwd()) | |
print(os.listdir()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment