From 69410796719bda8abc8a79efa7050cac35605365 Mon Sep 17 00:00:00 2001 From: Will Barnes Date: Thu, 7 Apr 2022 15:01:16 -0400 Subject: [PATCH] retemplate dance --- .pre-commit-config.yaml | 41 +++++++++++++ .readthedocs.yml | 27 ++++----- MANIFEST.in | 4 +- pydrad/__init__.py | 4 ++ pydrad/setup.cfg | 97 +++++++++++++++++++++++++++++++ pydrad/version.py | 17 ++++++ pyproject.toml | 7 +++ requirements/requirements-dev.txt | 11 ---- requirements/requirements.txt | 7 --- setup.py | 44 ++++++++------ tox.ini | 60 +++++++++++++++++++ 11 files changed, 268 insertions(+), 51 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 pydrad/setup.cfg create mode 100644 pydrad/version.py create mode 100644 pyproject.toml delete mode 100644 requirements/requirements-dev.txt delete mode 100644 requirements/requirements.txt create mode 100644 tox.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3579178 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,41 @@ +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://gitlab.com/pycqa/flake8 + rev: 3.7.9 + hooks: + - id: flake8 + args: ['--count', '--select', 'E101,W191,W291,W292,W293,W391,E111,E112,E113,E303,E304,E306,E502,E722,E901,E902,F822,F823'] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: check-ast + - id: check-case-conflict + - id: trailing-whitespace + exclude: ".*(.fits|.fts|.fit|.txt)$" + - id: check-yaml + - id: debug-statements + - id: check-added-large-files + - id: end-of-file-fixer + exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$" + - id: mixed-line-ending + exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$" diff --git a/.readthedocs.yml b/.readthedocs.yml index b8261a7..7295a76 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,21 +1,18 @@ -# .readthedocs.yml -# Read the Docs configuration file -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details - -# Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3.9" -# Build documentation in the docs/ directory with Sphinx sphinx: + builder: html configuration: docs/conf.py + fail_on_warning: false -# 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: . \ No newline at end of file + install: + - method: pip + extra_requirements: + - all + - docs + path: . diff --git a/MANIFEST.in b/MANIFEST.in index 07383f1..96af229 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ include README.md include LICENSE -include pydrad/configure/templates/* \ No newline at end of file +include pyproject.toml +include pydrad/configure/templates/* +include pydrad/configure/data/* \ No newline at end of file diff --git a/pydrad/__init__.py b/pydrad/__init__.py index 6540630..f26b132 100644 --- a/pydrad/__init__.py +++ b/pydrad/__init__.py @@ -5,6 +5,8 @@ import logging from astropy.logger import AstropyLogger +from .version import version as __version__ + def _init_log(): """ @@ -25,3 +27,5 @@ def _init_log(): log = logging.getLogger() log = _init_log() + +__all__ = ['__version__', 'log'] diff --git a/pydrad/setup.cfg b/pydrad/setup.cfg new file mode 100644 index 0000000..ded377d --- /dev/null +++ b/pydrad/setup.cfg @@ -0,0 +1,97 @@ +[metadata] +name = pydrad +author = Will Barnes +author_email = will.t.barnes@gmail.com +license = MIT +license_file = LICENSE +url = https://github.com/rice-solar-physics/pydrad +description = Tools for configuring and parsing HYDRAD simulations. +long_description = file: README.md +long_description_content_type = text/markdown +keywords = hydrodynamics, coronal loop, corona, solar physics, solar, science, sun +classifiers = + Development Status :: 4 - Beta + Intended Audience :: Science/Research + License :: OSI Approved :: MIT License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Topic :: Scientific/Engineering :: Astronomy + +[options] +zip_safe = False +packages = find: +python_requires = >=3.7 +setup_requires = setuptools_scm +install_requires = + scipy + matplotlib + astropy + Jinja2 + asdf + h5py + plasmapy[theory] + +[options.extras_require] +test = + flake8 + GitPython + pillow + pytest + pytest-cov + codecov +docs = + sphinx + sphinx-automodapi + sphinx-changelog + sphinx-gallery + sphinx-rtd-theme + +[options.package_data] +pydrad.configure = templates/*, data/* + +[tool:pytest] +testpaths = "pydrad" "docs" +doctest_plus = enabled +text_file_format = rst +addopts = --doctest-rst +remote_data_strict = False +filterwarnings = + error + +[coverage:run] +omit = + pydrad/_sunpy_init* + pydrad/conftest.py + pydrad/*setup_package* + pydrad/tests/* + pydrad/*/tests/* + pydrad/extern/* + pydrad/version* + */pydrad/_sunpy_init* + */pydrad/conftest.py + */pydrad/*setup_package* + */pydrad/tests/* + */pydrad/*/tests/* + */pydrad/extern/* + */pydrad/version* + +[coverage:report] +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + # Don't complain about packages we have installed + except ImportError + # Don't complain if tests don't hit assertions + raise AssertionError + raise NotImplementedError + # Don't complain about script hooks + def main\(.*\): + # Ignore branches that don't pertain to this version of Python + pragma: py{ignore_python_version} + # Don't complain about IPython completion helper + def _ipython_key_completions_ + diff --git a/pydrad/version.py b/pydrad/version.py new file mode 100644 index 0000000..515c2f0 --- /dev/null +++ b/pydrad/version.py @@ -0,0 +1,17 @@ +# NOTE: First try _dev.scm_version if it exists and setuptools_scm is installed +# This file is not included in wheels/tarballs, so otherwise it will +# fall back on the generated _version module. +try: + try: + from ._dev.scm_version import version + except ImportError: + from ._version import version +except Exception: + import warnings + + warnings.warn( + f'could not determine {__name__.split(".")[0]} package version; this indicates a broken installation' + ) + del warnings + + version = '0.0.0' diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7e7daea --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] + +requires = ["setuptools", + "setuptools_scm", + "wheel"] + +build-backend = 'setuptools.build_meta' diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt deleted file mode 100644 index d69ec26..0000000 --- a/requirements/requirements-dev.txt +++ /dev/null @@ -1,11 +0,0 @@ --r requirements.txt -flake8 -GitPython -pillow -pytest -sphinx -sphinx-automodapi -sphinx-gallery -sphinx-rtd-theme -pytest-cov -codecov \ No newline at end of file diff --git a/requirements/requirements.txt b/requirements/requirements.txt deleted file mode 100644 index 61cd0de..0000000 --- a/requirements/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -scipy -matplotlib -astropy -Jinja2 -asdf -h5py -plasmapy[theory] \ No newline at end of file diff --git a/setup.py b/setup.py index 7952979..6466862 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,30 @@ -from distutils.core import setup +#!/usr/bin/env python +import os +from itertools import chain +from setuptools import setup +from setuptools.config import read_configuration + +################################################################################ +# Programmatically generate some extras combos. +################################################################################ +extras = read_configuration("setup.cfg")['options']['extras_require'] + +# Dev is everything +extras['dev'] = list(chain(*extras.values())) + +# All is everything but tests and docs +exclude_keys = ("tests", "docs", "dev") +ex_extras = dict(filter(lambda i: i[0] not in exclude_keys, extras.items())) +# Concatenate all the values together for 'all' +extras['all'] = list(chain.from_iterable(ex_extras.values())) + +################################################################################ +# Version configuration and setup call +################################################################################ setup( - name='pydrad', - license='MIT', - version='0.1', - author='Will Barnes', - url='https://github.com/rice-solar-physics/pydrad', - package_data={'pydrad': ['configure/templates/*', - 'configure/data/defaults.asdf']}, - packages=[ - 'pydrad', - 'pydrad.configure', - 'pydrad.configure.data', - 'pydrad.parse', - 'pydrad.visualize', - ], - author_email='will.t.barnes@gmail.com', - description='Tools for configuring and parsing HYDRAD simulations' + extras_require=extras, + use_scm_version={ + 'write_to': os.path.join('pydrad', '_version.py'), + }, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9499fba --- /dev/null +++ b/tox.ini @@ -0,0 +1,60 @@ +[tox] +envlist = + py{38,39,310} + build_docs + codestyle +isolated_build = true +requires = + setuptools >= 30.3.0 + pip >= 19.3.1 + tox-pypi-filter >= 0.10 + +[testenv] + +# The following option combined with the use of the tox-pypi-filter above allows +# project-wide pinning of dependencies, e.g. if new versions of pytest do not +# work correctly with pytest-astropy plugins. Most of the time the pinnings file +# should be empty. + +# Pass through the following environemnt variables which may be needed for the CI +passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS + +# Run the tests in a temporary directory to make sure that we don't import +# the package from the source tree +changedir = .tmp/{envname} + +# tox environments are constructued with so-called 'factors' (or terms) +# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor: +# will only take effect if that factor is included in the environment name. To +# see a list of example environments that can be run, along with a description, +# run: +# +# tox -l -v +# +description = + run tests + +deps = +# The following indicates which extras_require from setup.cfg will be installed +extras = + test +commands = + pytest --pyargs pydrad {toxinidir}/docs --cov pydrad --cov-report=xml --cov-config={toxinidir}/setup.cfg {posargs} + + +[testenv:build_docs] +changedir = docs +description = invoke sphinx-build to build the HTML docs +extras = docs +commands = + sphinx-build -b html . _build/html {posargs} + + +[testenv:codestyle] +skip_install = true +description = Run all style and file checks with pre-commit +deps = + pre-commit +commands = + pre-commit install-hooks + pre-commit run --all-files