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 10 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
93 changes: 58 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,64 @@
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<4' tox-pypi-filter"
envs: |
wtbarnes marked this conversation as resolved.
Show resolved Hide resolved
- macos: py39
- macos: py311
- windows: py39
- windows: py311
- linux: py39
- linux: py310
- linux: py311
coverage: 'codecov'
wtbarnes marked this conversation as resolved.
Show resolved Hide resolved
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
precommit:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
toxdeps: tox-pypi-filter
envs: |
- linux: pre-commit
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)$"
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.txt|.pro|.bib|tca.*)$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|.bib|tca.*)$"

- 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
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include README.md
include LICENSE
include pydrad/configure/templates/*
include pyproject.toml
include pydrad/configure/templates/*
include pydrad/configure/data/*
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
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
import sphinx_rtd_theme
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_theme = 'sphinx_book_theme'

# -- Sphinx Book Theme Options -----------------------------------------------------
html_theme_options = {
"repository_url": 'https://github.com/rice-solar-physics/pydrad',
"use_repository_button": True,
"use_issues_button": True,
}

# -- Sphinx-gallery ----------------------------------------------------------
extensions += [
Expand Down
4 changes: 4 additions & 0 deletions pydrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import logging
from astropy.logger import AstropyLogger

from .version import version as __version__


def _init_log():
"""
Expand All @@ -25,3 +27,5 @@ def _init_log():

log = logging.getLogger()
log = _init_log()

__all__ = ['__version__', 'log']
10 changes: 10 additions & 0 deletions pydrad/configure/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os


def assert_ignore_blanks(string_1, string_2):
"""
Compare two multiline strings, ignoring lines that are blank
"""
string_1_stripped = os.linesep.join([l for l in string_1.splitlines() if l])
string_2_stripped = os.linesep.join([l for l in string_2.splitlines() if l])
assert string_1_stripped == string_2_stripped
3 changes: 2 additions & 1 deletion pydrad/configure/tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
pathlib.Path('Initial_Conditions') / 'profiles' / 'initial.amr.phy',
pathlib.Path('Initial_Conditions') / 'profiles' / 'initial.amr.sol'])
def test_generated_files_exist(hydrad, filename):
assert (hydrad / filename).is_file()
generated_file = pathlib.Path(hydrad / filename)
assert generated_file.is_file()
Loading
Loading