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

Retemplate the repository #158

Merged
merged 25 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ omit =
pydrad/*/tests/*
*/pydrad/conftest.py
*/pydrad/tests/*
*/pydrad/*/tests/*
*/pydrad/*/tests/*
92 changes: 57 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
name: Test
name: CI

on:
push:
branches: [ main ]
branches:
- 'main'
- '*.*'
tags:
- 'v*'
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/requirements-dev.txt
python setup.py install
- name: Clone HYDRAD
uses: actions/checkout@v2
with:
repository: rice-solar-physics/HYDRAD
path: HYDRAD
- name: Test
run: |
pytest --hydrad-dir=$GITHUB_WORKSPACE/HYDRAD --cov=pydrad --cov-report=xml
- name: Report coverage
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
verbose: true
file: ./coverage.xml
test:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
toxdeps: tox-pypi-filter
envs: |
- macos: py311
- windows: py311
- linux: py39
- linux: py310
- linux: py311
coverage: 'codecov'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
codestyle:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
toxdeps: tox-pypi-filter
envs: |
- linux: codestyle
python-version: '3.11'
docs:
needs: [test]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
toxdeps: tox-pypi-filter
envs: |
- linux: build_docs
python-version: '3.11'
publish:
# Build wheels when pushing to any branch except main
# publish.yml will only publish if tagged ^v.*
if: |
(
github.event_name != 'pull_request' && (
github.ref_name != 'main' ||
github.event_name == 'workflow_dispatch'
)
) || (
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'Run publish')
)
needs: [test]
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@main
with:
test_extras: 'dev'
test_command: 'pytest -p no:warnings --doctest-rst --pyargs pydrad'
submodules: false
python-version: '3.11'
secrets:
pypi_token: ${{ secrets.PYPI_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/

# pytest
.pytest_cache

# Project specific
pydrad/_version.py
71 changes: 71 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
repos:
# The warnings/errors we check for here are:
# E101 - mix of tabs and spaces
# W191 - use of tabs
# W291 - trailing whitespace
# W292 - no newline at end of file
# W293 - trailing whitespace
# W391 - blank line at end of file
# E111 - 4 spaces per indentation level
# E112 - 4 spaces per indentation level
# E113 - 4 spaces per indentation level
# E303 - too many blank lines (3)
# E304 - blank lines found after function decorator
# E305 - expected 2 blank lines after class or function definition
# E306 - expected 1 blank line before a nested definition
# E502 - the backslash is redundant between brackets
# E722 - do not use bare except
# E901 - SyntaxError or IndentationError
# E902 - IOError
# F822: undefined name in __all__
# F823: local variable name referenced before assignment
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-use-pathlib]
args: ['--count', '--select', 'E101,W191,W291,W292,W293,W391,E111,E112,E113,E303,E304,E306,E502,E722,E901,E902,F822,F823,PL100,PL102,PL103,PL104,PL105,PL110,PL112,PL113,PL18,PL120,PL122,PL123']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
exclude: ".*(.fits|.fts|.fit|.txt|.pro)$|pydrad/configure/(templates|data)/.*"
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.txt|.pro|.bib|tca.*)$|pydrad/configure/(templates|data)/.*"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|.bib|tca.*)$|pydrad/configure/(templates|data)/.*"

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--keep-runtime-typing, --py38-plus]
files: ^fiasco/

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args: ['--config setup.cfg']

- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
name: isort
entry: isort
require_serial: true
language: python
types:
- python
18 changes: 11 additions & 7 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
formats: []

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: requirements/requirements-dev.txt
- method: setuptools
path: .
- method: pip
path: .
extra_requirements:
- docs
- all
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ To install the package and the needed dependencies,
```shell
$ git clone https://github.com/rice-solar-physics/pydrad.git
$ cd pydrad
$ pip install -r requirements/requirements.txt
$ python setup.py install
$ pip install .
```

If you'd like to run the tests and confirm that everything is working alright,
```shell
$ pip install -r requirements/requirements-dev.txt
$ pytest
```
$ pip install -e .[tests]
$ pytest pydrad
```

See the [docs](https://rice-solar-physics.github.io/pydrad/) for more info. Additionally, **you will need access to the HYDRAD source code.**
See the [docs](https://pydrad.readthedocs.io/en/latest) for more info.

## Help
Create an issue if you run into any problems. Submit a PR if you would like to add any functionality.
51 changes: 30 additions & 21 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
"""
Test rendering of templates for configuration and header files
"""
import pytest
import astropy.units as u
import pytest

import pydrad.configure
from pydrad.configure.util import get_clean_hydrad


def pytest_addoption(parser):
parser.addoption('--hydrad-dir', action='store', default=None)


@pytest.fixture
def hydrad_clean(request):
return request.config.getoption('--hydrad-dir')
@pytest.fixture(scope='session')
def hydrad_clean(tmpdir_factory, request):
# Returns a local path to a copy of the HYDRAD code
# If a path is not passed as a command line argument to pytest,
# a new copy is cloned from GitHub
hydrad_dir = request.config.getoption('--hydrad-dir')
if hydrad_dir is None:
hydrad_dir = tmpdir_factory.mktemp('hydrad_tmp_clean')
get_clean_hydrad(hydrad_dir, base_path=None, from_github=True, overwrite=True)
return hydrad_dir


@pytest.fixture
def configuration_dict():
def get_configuration_dict():
return {
'general': {
'footpoint_height': 5.e+08*u.cm,
Expand Down Expand Up @@ -105,20 +112,22 @@ def configuration_dict():
}


@pytest.fixture
def configuration(configuration_dict):
return pydrad.configure.Configure(configuration_dict, freeze_date=True)
@pytest.fixture(scope='function')
def configuration():
return pydrad.configure.Configure(get_configuration_dict(), freeze_date=True)


@pytest.fixture
def hydrad(tmp_path, configuration, hydrad_clean):
if hydrad_clean is None:
pytest.skip('Path to HYDRAD code not specified. Skipping those tests that require HYDRAD.')
else:
hydrad_tmp = tmp_path / 'hydrad_tmp'
configuration.setup_simulation(hydrad_tmp, hydrad_clean)
pydrad.configure.util.run_shell_command(
['./HYDRAD.exe'],
hydrad_tmp,
)
return hydrad_tmp
@pytest.fixture(scope='session')
def hydrad(tmpdir_factory, hydrad_clean):
# NOTE: purposefully reconstructing the configuration here, rather than using the fixture
# above in order to keep configuration at the function scope level
configuration = pydrad.configure.Configure(get_configuration_dict(), freeze_date=True)
# Run a HYDRAD simulation for the given configuration and return the path to the directory
# containing the results.
hydrad_tmp = tmpdir_factory.mktemp('hydrad_tmp')
configuration.setup_simulation(hydrad_tmp, hydrad_clean, overwrite=True)
pydrad.configure.util.run_shell_command(
['./HYDRAD.exe'],
hydrad_tmp,
)
return hydrad_tmp
2 changes: 1 addition & 1 deletion docs/code_ref/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pydrad configure

.. automodapi:: pydrad.configure
:no-heading:
:no-inheritance-diagram:
:no-inheritance-diagram:
2 changes: 1 addition & 1 deletion docs/code_ref/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ API Reference

configure
parse
visualize
visualize
2 changes: 1 addition & 1 deletion docs/code_ref/parse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pydrad parse

.. automodapi:: pydrad.parse
:no-heading:
:no-inheritance-diagram:
:no-inheritance-diagram:
2 changes: 1 addition & 1 deletion docs/code_ref/visualize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pydrad visualize

.. automodapi:: pydrad.visualize
:no-heading:
:no-inheritance-diagram:
:no-inheritance-diagram:
Loading