-
Notifications
You must be signed in to change notification settings - Fork 7
Add py-tools variant and set $ISSM_DIR Environment Variable #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f4e3ec9
Add +py variant and set ISSM_DIR env variable
lawrenceabird e9ca453
Replace install_tree() with os.walk to copy subset
lawrenceabird d8a1ca5
Rename variant & include lib/ in PYTHONPATH
lawrenceabird 3cdc903
Update comments to address ruff failure
lawrenceabird b195f58
Address suggestions from @aidanheerdegen
lawrenceabird 07bf77a
Fix Ruff failure
lawrenceabird b6181a7
Update comment for PYTHONPATH addition condition
lawrenceabird 525288c
Update to use native spack functions
lawrenceabird 7dc3b48
Add version for access-release branch
lawrenceabird cffafe6
Address comments from @harshula
lawrenceabird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
|
|
||
| from spack.package import * | ||
| import os | ||
| import zipfile | ||
|
|
||
|
|
||
| class Issm(AutotoolsPackage): | ||
|
|
@@ -61,6 +63,12 @@ class Issm(AutotoolsPackage): | |
| description="Propagate OpenMP flags so threaded deps link cleanly", | ||
| ) | ||
|
|
||
| variant( | ||
| "py-tools", | ||
| default=False, | ||
| description="Install ISSM python files under <prefix>/python-tools", | ||
| ) | ||
|
|
||
| # -------------------------------------------------------------------- | ||
| # Dependencies | ||
| # -------------------------------------------------------------------- | ||
|
|
@@ -94,10 +102,20 @@ class Issm(AutotoolsPackage): | |
| depends_on("access-triangle", when="+wrappers") | ||
| depends_on("[email protected]:", when="+wrappers", type=("build", "run")) | ||
| depends_on("py-numpy", when="+wrappers", type=("build", "run")) | ||
|
|
||
| # -------------------------------------------------------------------- | ||
| # Conflicts | ||
| # -------------------------------------------------------------------- | ||
|
|
||
| # GCC 14 breaks on several C++17 constructs used in ISSM | ||
| conflicts("%gcc@14:", msg="ISSM cannot be built with GCC versions above 13") | ||
|
|
||
| # +wrappers requires +py-tools to access the wrappers | ||
| conflicts("+wrappers", when="~py-tools", msg="The +wrappers variant requires +py-tools") | ||
|
lawrenceabird marked this conversation as resolved.
|
||
|
|
||
| # +py-tools requires +wrappers for full Python functionality | ||
| conflicts("+py-tools", when="~wrappers", msg="The +py-tools variant requires +wrappers for full functionality") | ||
|
|
||
| # -------------------------------------------------------------------- | ||
| # Helper functions | ||
| # -------------------------------------------------------------------- | ||
|
|
@@ -198,7 +216,44 @@ def configure_args(self): | |
| def install(self, spec, prefix): | ||
| make("install", parallel=False) | ||
|
|
||
| # Optionally install examples directory | ||
| if "+examples" in self.spec: | ||
| examples_src = join_path(self.stage.source_path, "examples") | ||
| examples_dst = join_path(prefix, "examples") | ||
| install_tree(examples_src, examples_dst) | ||
|
|
||
| # Optionally install Python (.py) files as a zip archive | ||
| if "+py-tools" in spec: | ||
| py_src = join_path(self.stage.source_path, "src", "m") | ||
| py_dst = join_path(prefix, "python-tools.zip") | ||
|
|
||
| # Recursively copy all .py files from src/m to python-tools.zip | ||
| # Exclude contrib directory which contains working files | ||
| exclude_dirs = {'contrib'} | ||
|
|
||
| # Create a zip file and add *.py files, excluding exclude_dirs | ||
| with zipfile.ZipFile(py_dst, 'w', zipfile.ZIP_DEFLATED) as zf: | ||
| for root, dirs, files in os.walk(py_src): | ||
|
lawrenceabird marked this conversation as resolved.
Outdated
|
||
| dirs[:] = [d for d in dirs if d not in exclude_dirs] | ||
| for file in files: | ||
| if file.endswith('.py'): | ||
| src_path = os.path.join(root, file) | ||
|
lawrenceabird marked this conversation as resolved.
Outdated
|
||
| zf.write(src_path, arcname=file) | ||
|
|
||
| # -------------------------------------------------------------------- | ||
| # Run environment - set ISSM_DIR and PYTHONPATH | ||
| # -------------------------------------------------------------------- | ||
| def setup_run_environment(self, env): | ||
| """Set ISSM_DIR to the install root.""" | ||
|
|
||
| # Get the prefix path (install root) | ||
| issm_dir = self.prefix | ||
|
|
||
| # Set environment variable | ||
| env.set('ISSM_DIR', issm_dir) | ||
|
|
||
| # Add ISSM python files (and shared libraries) to PYTHONPATH if +py-tools | ||
| if "+py-tools" in self.spec: | ||
| env.prepend_path("PYTHONPATH", join_path(self.prefix, "python-tools.zip")) | ||
| env.prepend_path("PYTHONPATH", join_path(self.prefix, "lib")) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.