Skip to content

Commit

Permalink
Merge pull request #9 from cfs-energy/patch39
Browse files Browse the repository at this point in the history
Ensure project works for Python 3.9
  • Loading branch information
tbody-cfs authored Mar 22, 2024
2 parents 3d3206c + f1cb933 commit 92812df
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 53 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/workflow_actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Largely based on https://github.com/cfs-energy/cfspopcon/blob/main/.github/workflows/workflow_actions.yml
# This workflow will install Python dependencies and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: workflow_actions

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
pull_request: []
push:
tags:
- '*'
branches:
- 'main'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
tag: "Manual run"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11'] # should test the versions we allow for in pyproject.toml

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python - --version 1.8.2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Setup
run: poetry install

- name: Tests
run: MPLBACKEND=Agg poetry run pytest tests

- name: Test package
run: |
poetry build -f wheel
python -m venv test_env
source ./test_env/bin/activate
pip install $(find ./dist -name "*.whl")
# enter tempdir so import cfspopcon doesn't find the cfspopcon directory
mkdir tmp_dir && cd tmp_dir
MPLBACKEND=Agg radas_config -o ./new_config.yaml
MPLBACKEND=Agg radas -s hydrogen -c ./new_config.yaml
# build_release:
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
# needs: build
# runs-on: ubuntu-22.04

# steps:
# - uses: actions/checkout@v3

# - name: Install Poetry
# run: curl -sSL https://install.python-poetry.org | python - --version 1.8.2

# - name: Poetry build
# run: poetry build

# - uses: actions/upload-artifact@v3
# with:
# name: pypi-build
# path: ./dist

# publish:
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
# needs: build_release
# runs-on: ubuntu-22.04
# environment:
# name: pypi-publish
# url: https://pypi.org/project/cfspopcon/
# permissions:
# id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
# steps:
# - uses: actions/download-artifact@v3

# - name: Publish package distributions to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# packages-dir: pypi-build/

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The project is installed using [poetry](https://python-poetry.org/). If you have

Once you have poetry installed, you can install `radas` by running
```
poetry install --with dev
poetry install
```

Because we've added `in-project = true` in `poetry.toml`, the project will install in the `.venv` in the repository directory.
Expand Down Expand Up @@ -122,9 +122,9 @@ First, you should edit `pyproject.toml` and set `version="YYYY.MM.V"`, where `YY
# Clean up any previous distributions
rm -rf ./dist
# Install the project
# Install the project without dev dependencies
poetry lock
poetry install --with dev
poetry install --with publish
# Make sure the tests all pass!
poetry run pytest
Expand Down
45 changes: 30 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "radas"
# Version is year.month.version
version = "2024.3.0"
version = "2024.3.1"
description = "Plasma radiated power calculated using OpenADAS"
authors = ["Commonwealth Fusion Systems"]
readme = "README.md"
Expand All @@ -24,26 +24,38 @@ run_radas = 'radas.cli:run_radas_cli'
radas_config = 'radas.cli:write_config_template'

[tool.poetry.dependencies]
python = "<3.13,>=3.9"
numpy = "^1.22"
scipy = "^1.8"
matplotlib = "^3.6"
Pint = "^0.21"
pyyaml = "^6.0"
python = "<3.12,>=3.9"
numpy = ">=1.22"
scipy = ">=1.8"
matplotlib = ">=3.6"
Pint = ">=0.21"
pyyaml = ">=6.0"
xarray = ">=2023"
pint-xarray = ">=0.3"
click = "^8.1"
click = ">=8.1"

[tool.poetry.group.dev.dependencies]
twine = ">=4.0"
black = ">=23.0"
ipdb = "^0.13"
pytest = "^7.2"
pytest-order = "^1.1"
pytest-cov = "^4.1"
# Install pytest into all development environments
# (don't set optional = true)
pytest = ">=7.2"
pytest-order = ">=1.1"
pytest-cov = ">=4.1"
coverage = ">=7.2"
black = ">=23.0"

[tool.poetry.group.ipykernel]
optional = true

[tool.poetry.group.ipykernel.dependencies]
ipdb = ">=0.13"
ipykernel = ">=6.20"

[tool.poetry.group.publish]
optional = true

[tool.poetry.group.publish.dependencies]
twine = ">=4.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
2 changes: 1 addition & 1 deletion radas/adas_interface/compile_with_f2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def compile_with_f2py(
def compile_fortran_files(quiet: bool):
command = (
["python3", "-m", "numpy.f2py", "-c"]
+ files_to_compile
+ [str(path) for path in files_to_compile]
+ ["-m", module_name]
)

Expand Down
Empty file.
12 changes: 7 additions & 5 deletions radas/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import multiprocessing as mp
from pathlib import Path
from functools import partial
from typing import Optional

from .shared import open_yaml_file, default_config_file
from .adas_interface.prepare_adas_readers import prepare_adas_fortran_interface
Expand Down Expand Up @@ -43,7 +44,7 @@
)
def run_radas_cli(
directory: Path,
config: str | None,
config: Optional[str],
species: list[str],
verbose: int,
):
Expand All @@ -67,7 +68,7 @@ def run_radas_cli(

def run_radas(
directory: Path,
config: str | None,
config: Optional[str],
species: list[str],
verbose: int,
):
Expand All @@ -86,7 +87,7 @@ def run_radas(
if verbose:
print("Skipping computation.")
else:
config_file = default_config_file if config is None else Path(config)
config_file = default_config_file if config is None else Path(config).absolute()
if verbose:
print(f"Opening config file at {config_file}")
configuration = open_yaml_file(config_file)
Expand Down Expand Up @@ -181,6 +182,7 @@ def run_radas_computation(dataset: xr.Dataset, output_dir: Path, verbose: int):
help="Output path for a config file. DEFAULT: ./config.yaml",
)
def write_config_template(output: Path):
print(f"Copying {default_config_file} to {output.absolute()}")
Path(output).absolute().write_text(default_config_file.read_text())
output = Path(output).absolute()
print(f"Copying {default_config_file} to {output}")
output.write_text(default_config_file.read_text())
print("Done")
26 changes: 12 additions & 14 deletions radas/read_rate_coeffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ def read_rate_coeff(reader_dir, data_file_dir, species_name, config):
config["data_file_config"], dataset_type
)

match reader_key:

case "adf11":
rate_dataset = build_adf11_rate_dataset(
reader_dir,
data_file_dir,
species_name,
dataset_type,
dataset_config,
)
case _:
raise NotImplementedError(
f"No implementation for reading {reader_key} files."
)
if reader_key == "adf11":
rate_dataset = build_adf11_rate_dataset(
reader_dir,
data_file_dir,
species_name,
dataset_type,
dataset_config,
)
else:
raise NotImplementedError(
f"No implementation for reading {reader_key} files."
)

determine_coordinates(dataset, rate_dataset)
dataset[dataset_type] = rate_dataset.rate_coefficient
Expand Down
2 changes: 1 addition & 1 deletion radas/shared.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Bits and pieces shared by many other parts of radas."""

from pathlib import Path
from importlib_resources import files
from importlib.resources import files
import subprocess
import yaml

Expand Down

0 comments on commit 92812df

Please sign in to comment.