-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate installation of SOCRATES (#48)
* Load socrates env in Python * Set default directory * Add tool for downloading SOCRATES * Move set_rad_env away from __init__ * Clean download code * Turn set_rad_env into a singleton * Revise dowload function to download source and compile * Fix GA * Add platformdirs dependency * Set path to socrates dir * Fix path to SOCRATES * Add documentation * Format code * Update documentation
- Loading branch information
1 parent
fc4786b
commit b6d725d
Showing
9 changed files
with
171 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,8 +1,39 @@ | ||
This page shows you how to get started using JANUS. | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | ||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, | ||
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse | ||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non | ||
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
# Getting started | ||
|
||
JANUS contains a small CLI tool to help get set up with JANUS. | ||
|
||
## Install SOCRATES | ||
|
||
Download and install SOCRATES: | ||
|
||
```console | ||
janus download socrates | ||
``` | ||
|
||
Make sure you have the netcdf fortran libraries installed: | ||
|
||
``` | ||
sudo apt install libnetcdff-dev netcdf-bin | ||
``` | ||
|
||
## Download data | ||
|
||
Download spectral and stellar data: | ||
|
||
```console | ||
janus download spectral | ||
janus download stellar | ||
``` | ||
|
||
## Environment variables | ||
|
||
### `SOCRATES` | ||
|
||
By default, SOCRATES is installed to the default location based on the [XDG specification](https://specifications.freedesktop.org/basedir-spec/latest/). | ||
|
||
If you install and compile [SOCRATES](https://github.com/nichollsh/SOCRATES) yourself, | ||
you can override the path using the `SOCRATES` environment variable, e.g. | ||
|
||
```console | ||
SOCRATES=/home/user/path/to/SOCRATES pytest | ||
``` |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Import this file to set environment variables for socrates. | ||
Based on: | ||
https://github.com/FormingWorlds/SOCRATES/blob/main/sbin/set_rad_env_tmp | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from .socrates import SOCRATES_DIR | ||
|
||
import os | ||
import sys | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import click | ||
import platformdirs | ||
import requests | ||
|
||
if not SOCRATES_DIR.exists(): | ||
raise RuntimeError(f'Cannot find SOCRATES in this location: {SOCRATES_DIR}') | ||
|
||
with open(SOCRATES_DIR / 'version') as f: | ||
version = f.readline() | ||
|
||
print(f'socrates location: {SOCRATES_DIR}') | ||
print(f'socrates version: {version}') | ||
|
||
sep = os.pathsep | ||
|
||
os.environ['RAD_DIR'] = str(SOCRATES_DIR) | ||
os.environ['RAD_BIN'] = str(SOCRATES_DIR / 'bin') | ||
os.environ['RAD_DATA'] = str(SOCRATES_DIR / 'data') | ||
os.environ['RAD_SCRIPT'] = str(SOCRATES_DIR / 'sbin') | ||
os.environ['LOCK_FILE'] = 'radiation_code.lock' | ||
os.environ['PATH'] = str(SOCRATES_DIR / 'bin') + sep + os.environ['PATH'] | ||
os.environ['PATH'] = str(SOCRATES_DIR / 'sbin') + sep + os.environ['PATH'] | ||
os.environ['MANPATH'] = str(SOCRATES_DIR / 'man') + sep + os.environ.get('MANPATH', '') | ||
sys.path.append(str(SOCRATES_DIR / 'python')) | ||
|
||
os.environ['LD_LIBRARY_PATH'] = 'netcdfff' + sep + os.environ.get('LD_LIBRARY_PATH', '') |
This file contains 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess as sp | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import click | ||
import platformdirs | ||
import requests | ||
|
||
SOCRATES_DATA_DIR = Path(platformdirs.user_data_dir('socrates')) | ||
SOCRATES_DIR = Path(os.environ.get('SOCRATES', SOCRATES_DATA_DIR / 'SOCRATES')) | ||
|
||
|
||
def _set_permissions(drc: Path): | ||
"""Set executable flag for scripts.""" | ||
# Set executable permissions for make script | ||
(drc / 'make' / 'mkdep').chmod(mode=33261) | ||
|
||
|
||
def _download(*, url: str, filename: str): | ||
"""Download file from url.""" | ||
chunk_size = 1024 * 8 | ||
|
||
with requests.get(url, stream=True) as r: | ||
r.raise_for_status() | ||
total_size = int(r.headers.get('Content-Length', 0)) | ||
with ( | ||
open(filename, 'wb') as f, | ||
click.progressbar(label='Downloading', length=total_size) as pbar, | ||
): | ||
for chunk in r.iter_content(chunk_size=chunk_size): | ||
f.write(chunk) | ||
pbar.update(chunk_size) | ||
|
||
|
||
def download_socrates(ref: str = 'main'): | ||
"""Version can be 'main' or the git commit hash.""" | ||
filename = 'socrates.zip' | ||
path = 'refs/heads/main' if ref == 'main' else ref | ||
|
||
_download( | ||
url=f'https://github.com/nichollsh/SOCRATES/archive/{path}.zip', | ||
filename=filename, | ||
) | ||
|
||
SOCRATES_DATA_DIR.mkdir(exist_ok=True, parents=True) | ||
|
||
subdir = f'SOCRATES-{ref}' | ||
target_dir = SOCRATES_DATA_DIR / subdir | ||
|
||
click.echo(f'Extracting to {target_dir}') | ||
|
||
with zipfile.ZipFile(filename, 'r') as zip_ref: | ||
zip_ref.extractall(SOCRATES_DATA_DIR) | ||
|
||
_set_permissions(drc=target_dir) | ||
|
||
sp.run(['bash', 'configure'], cwd=target_dir) | ||
sp.run(['bash', 'build_code'], cwd=target_dir) | ||
|
||
symlink = SOCRATES_DATA_DIR / 'SOCRATES' | ||
symlink.unlink(missing_ok=True) | ||
symlink.symlink_to(target_dir) | ||
|
||
print(f'SOCRATES downloaded to {target_dir}') |
This file contains 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
This file contains 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
This file contains 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