Skip to content
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

When to set environment variables? #82

Open
NoraLoose opened this issue Sep 16, 2024 · 2 comments
Open

When to set environment variables? #82

NoraLoose opened this issue Sep 16, 2024 · 2 comments

Comments

@NoraLoose
Copy link
Contributor

In https://github.com/CWorthy-ocean/C-Star/blob/main/cstar/base/environment.py, we set environment variables. Some of these (in particular CONDA_PREFIX) are not available to RTD. I therefore had to hardcode the following:

C-Star/docs/conf.py

Lines 24 to 25 in fc35204

# cstar will look for os.environ["CONDA_PREFIX"] but this is not available on RTD; let's fill it with dummy
os.environ["CONDA_PREFIX"] = str(root)

We should think about whether we can move the setting of environment variables elsewhere, so that this step only happens if you actually want to make a run (this is when the environment variables are supposedly needed?), but not upon importing cstar.

If RTD is the only case in which this logic fails, it's maybe fine, but I can imagine it will fail in other cases as well.

@TomNicholas
Copy link
Member

Maybe let's use a context manager, see for example https://docs.xarray.dev/en/stable/user-guide/options.html. Then we could do something like

with cstar.set_environment("roms_marbl"):
    case = Case.from_yaml(...)
    case.setup()
    case.run()

Then we have automatically unset the environment variables at the point the contextmanager is exited.

@dafyddstephenson
Copy link
Contributor

Maybe let's use a context manager,

I dabbled with this in #168 , but found that setting and unsetting the environment every time we needed to do something with ROMS or MARBL was leading to significant holdups, especially on machines using Linux Environment Modules to manage software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants