From 1e76469cb12d785a5d959792856bcf4bea4916be Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Wed, 17 Jul 2024 17:30:39 +0200 Subject: [PATCH 01/16] Registers package with sunpy template --- .codecov.yaml | 11 ++ .codespellrc | 13 ++ .coveragerc | 30 +++++ .cruft.json | 31 +++++ .flake8 | 27 ++++ .github/workflows/ci.yml | 87 +++++++++++-- .github/workflows/sub_package_update.yml | 79 +++++++++++ .gitignore | 145 ++++++++++++++++++--- .isort.cfg | 16 +++ .pre-commit-config.yaml | 4 +- .readthedocs.yaml | 29 +++++ .rtd-environment.yml | 7 + .ruff.toml | 37 ++++++ MANIFEST.in | 8 ++ README.rst | 1 - docs/conf.py | 40 +++--- docs/index.rst | 4 +- docs/make.bat | 70 +++++----- licenses/LICENSE.rst | 25 ++++ licenses/TEMPLATE_LICENSE.rst | 6 +- pyproject.toml | 60 ++++++++- pytest.ini | 33 +++++ setup.cfg | 159 ----------------------- setup.py | 40 +----- sunkit_spex/__init__.py | 8 +- sunkit_spex/_dev/__init__.py | 6 + sunkit_spex/_dev/scm_version.py | 12 ++ sunkit_spex/tests/__init__.py | 1 - sunkit_spex/version.py | 17 +++ tox.ini | 102 +++++++++------ 30 files changed, 763 insertions(+), 345 deletions(-) create mode 100644 .codecov.yaml create mode 100644 .codespellrc create mode 100644 .coveragerc create mode 100644 .cruft.json create mode 100644 .flake8 create mode 100644 .github/workflows/sub_package_update.yml create mode 100644 .isort.cfg create mode 100644 .readthedocs.yaml create mode 100644 .rtd-environment.yml create mode 100644 .ruff.toml create mode 100644 licenses/LICENSE.rst create mode 100644 pytest.ini delete mode 100644 setup.cfg create mode 100644 sunkit_spex/_dev/__init__.py create mode 100644 sunkit_spex/_dev/scm_version.py create mode 100644 sunkit_spex/version.py diff --git a/.codecov.yaml b/.codecov.yaml new file mode 100644 index 00000000..8fe09b73 --- /dev/null +++ b/.codecov.yaml @@ -0,0 +1,11 @@ +comment: off +coverage: + status: + project: + default: + threshold: 0.2% + +codecov: + require_ci_to_pass: false + notify: + wait_for_ci: true diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 00000000..042a14ed --- /dev/null +++ b/.codespellrc @@ -0,0 +1,13 @@ +[codespell] +skip = *.asdf,*.fits,*.fts,*.header,*.json,*.xsh,*cache*,*egg*,*extern*,.git,.idea,.tox,_build,*truncated,*.svg,.asv_env,.history +ignore-words-list = + alog, + nd, + nin, + observ, + ot, + te, + upto, + afile, + precessed, + precess diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..096924ff --- /dev/null +++ b/.coveragerc @@ -0,0 +1,30 @@ +[run] +omit = + sunkit_spex/conftest.py + sunkit_spex/*setup_package* + sunkit_spex/extern/* + sunkit_spex/version* + */sunkit_spex/conftest.py + */sunkit_spex/*setup_package* + */sunkit_spex/extern/* + */sunkit_spex/version* + +[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_ + # typing.TYPE_CHECKING is False at runtime + if TYPE_CHECKING: + # Ignore typing overloads + @overload diff --git a/.cruft.json b/.cruft.json new file mode 100644 index 00000000..6fe337fd --- /dev/null +++ b/.cruft.json @@ -0,0 +1,31 @@ +{ + "template": "https://github.com/sunpy/package-template", + "commit": "112d7d4adf0fa168bbb9ddb1886ad4f1e595b8be", + "checkout": null, + "context": { + "cookiecutter": { + "package_name": "sunkit-spex", + "module_name": "sunkit_spex", + "short_description": "A package for solar X-ray spectroscopy.", + "author_name": "The SunPy Community", + "author_email": "sunpy@googlegroups.com", + "project_url": "https://sunkit-spex.readthedocs.io", + "license": "BSD 3-Clause", + "minimum_python_version": "3.9", + "use_compiled_extensions": "n", + "enable_dynamic_dev_versions": "y", + "include_example_code": "n", + "include_cruft_update_github_workflow": "y", + "_sphinx_theme": "alabaster", + "_parent_project": "", + "_install_requires": "", + "_copy_without_render": [ + "docs/_templates", + "docs/_static", + ".github/workflows/sub_package_update.yml" + ], + "_template": "https://github.com/sunpy/package-template" + } + }, + "directory": null +} diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..19540755 --- /dev/null +++ b/.flake8 @@ -0,0 +1,27 @@ +[flake8] +ignore = + # missing-whitespace-around-operator + E225 + # missing-whitespace-around-arithmetic-operator + E226 + # line-too-long + E501 + # unused-import + F401 + # undefined-local-with-import-star + F403 + # redefined-while-unused + F811 + # Line break occurred before a binary operator + W503, + # Line break occurred after a binary operator + W504 +max-line-length = 110 +exclude = + .git + __pycache__ + docs/conf.py + build + sunkit-spex/__init__.py +rst-directives = + plot diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3ac1406..58e912d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,24 @@ + name: CI on: push: + branches: + - 'main' + - '*.*' + - '!*backport*' + tags: + - 'v*' + - '!*dev*' + - '!*pre*' + - '!*post*' pull_request: + # Allow manual runs through the web UI workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: core: @@ -12,30 +26,77 @@ jobs: with: submodules: false coverage: codecov + toxdeps: tox-pypi-filter envs: | - - linux: py39 + - linux: py312 + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + sdist_verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - run: python -m pip install -U --user build + - run: python -m build . --sdist + - run: python -m pip install -U --user twine + - run: python -m twine check dist/* test: - needs: [core] + needs: [core, sdist_verify] uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main with: submodules: false coverage: codecov + toxdeps: tox-pypi-filter + posargs: -n auto envs: | - - windows: py39 - - macos: py39 + - windows: py311 + - macos: py310 + - linux: py310-oldestdeps secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} docs: - needs: [test] - uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main + needs: [core] + uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main + with: + default_python: '3.10' + submodules: false + pytest: false + toxdeps: tox-pypi-filter + libraries: | + apt: + - graphviz + envs: | + - linux: build_docs + + cron: + if: | + github.event_name == 'workflow_dispatch' || ( + github.event_name == 'pull_request' && + contains(github.event.pull_request.labels.*.name, 'Run cron CI') + ) + uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main + with: + default_python: '3.10' + submodules: false + coverage: codecov + toxdeps: tox-pypi-filter + envs: | + - linux: py311-devdeps + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + publish_pure: + needs: [test, docs] + uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@main with: - default_python: '3.9' + python-version: '3.10' + test_extras: 'tests' + test_command: 'pytest -p no:warnings --doctest-rst --pyargs sunkit_spex' submodules: false - pytest: false - libraries: | - apt: - - graphviz - envs: | - - linux: build_docs + secrets: + pypi_token: ${{ secrets.pypi_token }} diff --git a/.github/workflows/sub_package_update.yml b/.github/workflows/sub_package_update.yml new file mode 100644 index 00000000..06779481 --- /dev/null +++ b/.github/workflows/sub_package_update.yml @@ -0,0 +1,79 @@ +# This template is taken from the cruft example code, for further information please see: +# https://cruft.github.io/cruft/#automating-updates-with-github-actions +name: Automatic Update from package template +permissions: + contents: write + pull-requests: write + +on: + # Allow manual runs through the web UI + workflow_dispatch: + schedule: + # ┌───────── minute (0 - 59) + # │ ┌───────── hour (0 - 23) + # │ │ ┌───────── day of the month (1 - 31) + # │ │ │ ┌───────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────── day of the week (0 - 6 or SUN-SAT) + - cron: '0 7 * * 1' # Every Monday at 7am UTC + +jobs: + update: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - add-paths: . + body: apply the changes to this repo. + branch: cruft/update + commit-message: "Automatic package template update" + title: Updates from the package template + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Cruft + run: python -m pip install git+https://github.com/Cadair/cruft@patch-p1 + + - name: Check if update is available + continue-on-error: false + id: check + run: | + CHANGES=0 + if [ -f .cruft.json ]; then + if ! cruft check; then + CHANGES=1 + fi + else + echo "No .cruft.json file" + fi + + echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT" + + - name: Run update if available + if: steps.check.outputs.has_changes == '1' + run: | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git config --global user.name "${{ github.actor }}" + + cruft update --skip-apply-ask --refresh-private-variables + git restore --staged . + + - name: Create pull request + if: steps.check.outputs.has_changes == '1' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + add-paths: ${{ matrix.add-paths }} + commit-message: ${{ matrix.commit-message }} + branch: ${{ matrix.branch }} + delete-branch: true + branch-suffix: timestamp + title: ${{ matrix.title }} + body: | + This is an autogenerated PR, which will ${{ matrix.body }}. + [Cruft](https://cruft.github.io/cruft/) has detected updates from the Package Template diff --git a/.gitignore b/.gitignore index 35249128..bd0b120a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,17 @@ +### Python: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class +tmp/ # C extensions *.so # Distribution / packaging .Python +pip-wheel-metadata/ build/ develop-eggs/ dist/ @@ -26,6 +30,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +sunkit_spex/_version.py # PyInstaller # Usually these files are written by a python script from a template @@ -71,6 +76,9 @@ instance/ # Sphinx documentation docs/_build/ +# automodapi +docs/api +docs/sg_execution_times.rst # PyBuilder .pybuilder/ @@ -95,7 +103,15 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff @@ -114,10 +130,6 @@ ENV/ env.bak/ venv.bak/ -# Spyder project settings -.spyderproject -.spyproject - # Rope project settings .ropeproject @@ -126,31 +138,126 @@ venv.bak/ # mypy .mypy_cache/ -.dmypy.json -dmypy.json # Pyre type checker .pyre/ +# IDE +# PyCharm +.idea + +# Spyder project settings +.spyderproject +.spyproject + +### VScode: https://raw.githubusercontent.com/github/gitignore/master/Global/VisualStudioCode.gitignore +.vscode/* +.vs/* + +### https://raw.github.com/github/gitignore/master/Global/OSX.gitignore +.DS_Store +.AppleDouble +.LSOverride + +# Icon must ends with two \r. +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +### Linux: https://raw.githubusercontent.com/github/gitignore/master/Global/Linux.gitignore +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + # pytype static type analyzer .pytype/ -# Cython debug symbols -cython_debug/ +# General +.DS_Store +.AppleDouble +.LSOverride -# static files generated from Django application using `collectstatic` -media -static +# Icon must end with two \r +Icon -# Specifc Template -docs/_build -docs/generated -docs/api + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows: https://raw.githubusercontent.com/github/gitignore/master/Global/Windows.gitignore + +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### Extra Python Items and SunPy Specific docs/whatsnew/latest_changelog.txt docs/sg_execution_times.rst sunkit_spex/version.py htmlcov/ -# IDE files -.idea -.project +# Release script +.github_cache + +# Misc Stuff +.history +*.orig +.tmp +node_modules/ +package-lock.json +package.json +.prettierrc + +# Log files generated by 'vagrant up' +*.log diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..9eec8507 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,16 @@ +[settings] +balanced_wrapping = true +skip = + docs/conf.py + sunkit_spex/__init__.py +default_section = THIRDPARTY +include_trailing_comma = true +known_astropy = astropy, asdf +known_sunpy = sunpy +known_first_party = sunkit_spex +length_sort = false +length_sort_sections = stdlib +line_length = 110 +multi_line_output = 3 +no_lines_before = LOCALFOLDER +sections = STDLIB, THIRDPARTY, ASTROPY, SUNPY, FIRSTPARTY, LOCALFOLDER diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02ebfde4..def4535a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,13 +5,11 @@ repos: hooks: - id: ruff args: ["--fix"] - # Run the formatter. - - id: ruff-format - repo: https://github.com/PyCQA/isort rev: 5.13.2 hooks: - id: isort - exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*)$" + exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|sunkit_spex/extern)$" - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..790abab4 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,29 @@ +version: 2 + +build: + os: ubuntu-22.04 + tools: + python: "mambaforge-4.10" + jobs: + post_checkout: + - git fetch --unshallow || true + pre_install: + - git update-index --assume-unchanged .rtd-environment.yml docs/conf.py + +conda: + environment: .rtd-environment.yml + +sphinx: + builder: html + configuration: docs/conf.py + fail_on_warning: false + +formats: + - htmlzip + +python: + install: + - method: pip + extra_requirements: + - docs + path: . diff --git a/.rtd-environment.yml b/.rtd-environment.yml new file mode 100644 index 00000000..f13d82a5 --- /dev/null +++ b/.rtd-environment.yml @@ -0,0 +1,7 @@ +name: sunkit-spex +channels: + - conda-forge +dependencies: + - python=3.10 + - pip + - graphviz!=2.42.*,!=2.43.* diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000..f77e539c --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,37 @@ +target-version = "py310" +line-length = 110 +exclude = [ + ".git,", + "__pycache__", + "build", + "sunkit-spex/version.py", +] + +[lint] +select = ["E", "F", "W", "UP", "PT"] +extend-ignore = [ + # pycodestyle (E, W) + "E501", # LineTooLong # TODO! fix + # pytest (PT) + "PT001", # Always use pytest.fixture() + "PT004", # Fixtures which don't return anything should have leading _ + "PT007", # Parametrize should be lists of tuples # TODO! fix + "PT011", # Too broad exception assert # TODO! fix + "PT023", # Always use () on pytest decorators +] + +[lint.per-file-ignores] +# Part of configuration, not a package. +"setup.py" = ["INP001"] +"conftest.py" = ["INP001"] +"docs/conf.py" = [ + "E402" # Module imports not at top of file +] +"docs/*.py" = [ + "INP001", # Implicit-namespace-package. The examples are not a package. +] +"__init__.py" = ["E402", "F401", "F403"] +"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"] + +[lint.pydocstyle] +convention = "numpy" diff --git a/MANIFEST.in b/MANIFEST.in index 1dab5410..2b6b8f63 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,7 @@ +# Exclude specific files +# All files which are tracked by git and not explicitly excluded here are included by setuptools_scm +# Prune folders + include README.rst include CHANGES.rst include setup.cfg @@ -15,3 +19,7 @@ prune docs/_build prune docs/api global-exclude *.pyc *.o + +# This subpackage is only used in development checkouts +# and should not be included in built tarballs +prune sunkit_spex/_dev diff --git a/README.rst b/README.rst index 8262b9c7..2bac12d7 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,6 @@ the `Openastronomy packaging guide NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/licenses/LICENSE.rst b/licenses/LICENSE.rst new file mode 100644 index 00000000..9e29f91c --- /dev/null +++ b/licenses/LICENSE.rst @@ -0,0 +1,25 @@ +Copyright (c) 2024, The SunPy Community +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +* Neither the name of the Astropy Team nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/licenses/TEMPLATE_LICENSE.rst b/licenses/TEMPLATE_LICENSE.rst index f29177b0..544a2dba 100644 --- a/licenses/TEMPLATE_LICENSE.rst +++ b/licenses/TEMPLATE_LICENSE.rst @@ -1,10 +1,10 @@ -This project is based upon the Astropy package template -(https://github.com/astropy/package-template/) which is licenced under the terms +This project is based upon the OpenAstronomy package template +(https://github.com/OpenAstronomy/package-template/) which is licensed under the terms of the following licence. --- -Copyright (c) 2018, Astropy Developers +Copyright (c) 2018, OpenAstronomy Developers All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/pyproject.toml b/pyproject.toml index baa9d7d4..df0ce305 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,60 @@ [build-system] requires = [ - "setuptools>=56,!=61.0.0", - "setuptools_scm[toml]>=6.2", - "wheel" - ] -build-backend = 'setuptools.build_meta' + "setuptools>=56,!=61.0.0", + "setuptools_scm[toml]>=6.2", + "wheel" +] +build-backend = "setuptools.build_meta" + +[project] +name = "sunkit_spex" +description = "A package for solar X-ray spectroscopy." +requires-python = ">=3.9" +readme = { file = "README.rst", content-type = "text/x-rst" } +license = { file = "licenses/LICENSE.rst", content-type = "text/plain" } +authors = [ + { name = "The SunPy Community", email = "sunpy@googlegroups.com" }, +] +dependencies = [ + "corner", + "emcee", + "matplotlib", + "ndim", + "nestle", + "numdifftools", + "orthopy", + "parfive", + "quadpy", + "scipy", + "sunpy", + "xarray" +] + +dynamic = ["version"] + +[project.optional-dependencies] +tests = [ + "pytest", + "pytest-doctestplus", + "pytest-cov", + "pytest-xdist", +] +docs = [ + "sphinx", + "sphinx-automodapi", +] +[project.urls] +repository = "https://sunkit-spex.readthedocs.io" + +[tool.setuptools] +zip-safe = false +include-package-data = true + +[tool.setuptools.packages.find] +exclude = ["sunkit_spex._dev*"] + +[tool.setuptools_scm] +write_to = "sunkit_spex/_version.py" [ tool.gilesbot ] # [ tool.gilesbot.circleci_artifacts ] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..580de233 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,33 @@ +[pytest] +minversion = 7.0 +testpaths = + sunkit_spex + docs +norecursedirs = + .tox + build + docs/_build + docs/generated + *.egg-info + examples + sunkit_spex/_dev + .history + sunkit_spex/extern +doctest_plus = enabled +doctest_optionflags = + NORMALIZE_WHITESPACE + FLOAT_CMP + ELLIPSIS +text_file_format = rst +addopts = + --doctest-rst + -p no:unraisableexception + -p no:threadexception +filterwarnings = + # Turn all warnings into errors so they do not pass silently. + error + # Do not fail on pytest config issues (i.e. missing plugins) but do show them + always::pytest.PytestConfigWarning + # A list of warnings to ignore follows. If you add to this list, you MUST + # add a comment or ideally a link to an issue that explains why the warning + # is being ignored diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 138ea475..00000000 --- a/setup.cfg +++ /dev/null @@ -1,159 +0,0 @@ -[metadata] -name = sunkit-spex -provides = sunkit_spex -author = The SunPy Community -author_email = sunpy@googlegroups.com -license = BSD 3-Clause -license_file = LICENSE.rst -url = https://github.com/sunpy/sunkit-spex -description = A package for solar X-ray spectroscopy. -long_description = file: README.rst -long_description_content_type = text/x-rst - -[options] -zip_safe = False -packages = find: -python_requires = >=3.9 -setup_requires = setuptools_scm -install_requires = - corner - emcee - matplotlib - ndcube - ndim - nestle - numdifftools - orthopy - parfive - quadpy - scipy - sunpy - xarray - -[options.extras_require] -test = - pytest - pytest-astropy - pytest-cov - pytest-xdist - -docs = - sphinx - sphinx-automodapi - sunpy-sphinx-theme - sphinx-changelog>=1.1.1 - sphinx-gallery - -[options.package_data] -sunkit_spex = data/* - -[tool:pytest] -testpaths = "sunkit_spex" "docs" -norecursedirs = ".tox" "build" "docs[\/]_build" "docs[\/]generated" "*.egg-info" ".jupyter" ".history" "Fitter[\/]extern" -doctest_plus = enabled -doctest_optionflags = NORMALIZE_WHITESPACE FLOAT_CMP ELLIPSIS -addopts = --dist no --doctest-rst --doctest-ignore-import-errors -p no:unraisableexception -p no:threadexception -markers = - remote_data: marks this test function as needing remote data. - online: marks this test function as needing online connectivity. - mpl_image_compare: marks this test function as using hash-based Matplotlib figure verification. This mark is not meant to be directly applied, but is instead automatically applied when a test function uses the @sunpy.tests.helpers.figure_test decorator. - flaky - array_compare -remote_data_strict = False -# Pin junit behaviour; we might want to update this to xunit2 at some point -junit_family=xunit1 -filterwarnings = - error - # https://github.com/pytest-dev/pytest-cov/issues/557 - # It was fixed and released but it does not seem to be fixed - ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning - # Raised by sunpy.coordinates.transformations and will be removed in sunpy 6.1 - ignore:.*module is deprecated, as it was designed for internal use - # https://github.com/pandas-dev/pandas/issues/54466 - # Should stop when pandas 3.0.0 is released - ignore:(?s).*Pyarrow will become a required dependency of pandas:DeprecationWarning - # TODO review and fix just getting test running - ignore:numpy.ndarray size changed.*:RuntimeWarning - ignore:Some input energy values outside valid range.*:UserWarning - ignore:invalid value encountered in.*:RuntimeWarning - ignore:divide by zero encountered in.*:RuntimeWarning - ignore:The truth value of an empty array is ambiguous..*:DeprecationWarning - ignore:LinAlgError when calculating the hessian. Errors may not be calculated.:UserWarning - -[pycodestyle] -max_line_length = 100 - -[flake8] -max-line-length = 100 -exclude = - .git, - __pycache__, - docs/conf.py, - build -rst-directives = - plot - -[isort] -balanced_wrapping = True -skip=sunkit_spex/extern/,.py,docs/conf.py,sunkit_spex/__init__.py -default_section = THIRDPARTY -include_trailing_comma = True -known_astropy = astropy, asdf -known_first_party = sunpy -length_sort = False -length_sort_sections=stdlib -line_length = 110 -multi_line_output = 3 -no_lines_before = LOCALFOLDER -sections = STDLIB, THIRDPARTY, ASTROPY, FIRSTPARTY, LOCALFOLDER - -[codespell] -skip = ,*.fits,*.fts,*.header,*.json,*.xsh,*cache*,*egg*,*extern*,.git,.idea,.tox,_build,*truncated,*.svg,.asv_env,.history,sunkit_spex/fitting_legacy/* -ignore-words-list = - alog, - nd, - nin, - observ, - ot, - te, - upto, - afile, - combin, - livetime, - livetimes, - sav, - selt, - thirdparty - -[coverage:run] -omit = - sunkit_spex/_sunpy_init* - sunkit_spex/conftest.py - sunkit_spex/*setup_package* - sunkit_spex/tests/* - sunkit_spex/*/tests/* - sunkit_spex/extern/* - sunkit_spex/version* - */sunkit_spex/ - */sunkit_spex/conftest.py - */sunkit_spex/*setup_package* - */sunkit_spex/tests/* - */sunkit_spex/*/tests/* - */sunkit_spex/extern/* - */sunkit_spex/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/setup.py b/setup.py index 6d8848eb..c8233455 100755 --- a/setup.py +++ b/setup.py @@ -1,42 +1,4 @@ #!/usr/bin/env python -# Licensed under a 3-clause BSD style license - see LICENSE.rst - -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 -################################################################################ - -VERSION_TEMPLATE = """ -# Note that we need to fall back to the hard-coded version if either -# setuptools_scm can't be imported or setuptools_scm can't determine the -# version, so we catch the generic 'Exception'. -try: - from setuptools_scm import get_version - __version__ = get_version(root='..', relative_to=__file__) -except Exception: - __version__ = '{version}' -""".lstrip() -setup( - extras_require=extras, - use_scm_version={"write_to": os.path.join("sunkit_spex", "version.py"), "write_to_template": VERSION_TEMPLATE}, -) +setup() diff --git a/sunkit_spex/__init__.py b/sunkit_spex/__init__.py index b4763c0f..46a3cf00 100644 --- a/sunkit_spex/__init__.py +++ b/sunkit_spex/__init__.py @@ -1,9 +1,7 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst +from .version import version as __version__ - -from .version import __version__ - -__all__ = [] from . import extern from .legacy import fitting from .models.physical import io, thermal + +__all__ = [] diff --git a/sunkit_spex/_dev/__init__.py b/sunkit_spex/_dev/__init__.py new file mode 100644 index 00000000..72583c08 --- /dev/null +++ b/sunkit_spex/_dev/__init__.py @@ -0,0 +1,6 @@ +""" +This package contains utilities that are only used when developing drms in a +copy of the source repository. +These files are not installed, and should not be assumed to exist at +runtime. +""" diff --git a/sunkit_spex/_dev/scm_version.py b/sunkit_spex/_dev/scm_version.py new file mode 100644 index 00000000..1bcf0dd9 --- /dev/null +++ b/sunkit_spex/_dev/scm_version.py @@ -0,0 +1,12 @@ +# Try to use setuptools_scm to get the current version; this is only used +# in development installations from the git repository. +import os.path + +try: + from setuptools_scm import get_version + + version = get_version(root=os.path.join('..', '..'), relative_to=__file__) +except ImportError: + raise +except Exception as e: + raise ValueError('setuptools_scm can not determine version.') from e diff --git a/sunkit_spex/tests/__init__.py b/sunkit_spex/tests/__init__.py index 838b4573..92ea7073 100644 --- a/sunkit_spex/tests/__init__.py +++ b/sunkit_spex/tests/__init__.py @@ -1,4 +1,3 @@ -# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This module contains package tests. """ diff --git a/sunkit_spex/version.py b/sunkit_spex/version.py new file mode 100644 index 00000000..515c2f0a --- /dev/null +++ b/sunkit_spex/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/tox.ini b/tox.ini index 725c8b3e..fbef79e0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,64 +1,80 @@ [tox] +min_version = 4.0 +requires = + tox-pypi-filter>=0.14 envlist = - py{39,310,311} - build_docs + py{310,311,312} + py312-devdeps + py310-oldestdeps codestyle + build_docs isolated_build = true -# This is included for testing of the template. You can remove it safely. -skip_missing_interpreters = 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. -pypi_filter_requirements = https://raw.githubusercontent.com/sunpy/package-template/master/sunpy_version_pins.txt - -# Pass through the following environment variables which may be needed for the CI -passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS - +pypi_filter = https://raw.githubusercontent.com/sunpy/sunpy/main/.test_package_pins.txt # 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 constructed 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 -# +change_dir = .tmp/{envname} description = run tests - + oldestdeps: with the oldest supported version of key dependencies + devdeps: with the latest developer version of key dependencies +pass_env = + HOME + WINDIR + # A variable to tell tests we are on a CI system + CI + # Custom compiler locations (such as ccache) + CC + # Location of locales (needed by sphinx on some systems) + LOCALE_ARCHIVE + # If the user has set a LC override we should follow it + LC_ALL +set_env = + MPLBACKEND = agg + devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple deps = -# The following indicates which extras_require from setup.cfg will be installed + # For packages which publish nightly wheels this will pull the latest nightly + devdeps: numpy>=0.0.dev0 + # Packages without nightly wheels will be built from source like this + # devdeps: git+https://github.com/ndcube/ndcube + oldestdeps: minimum_dependencies +# The following indicates which extras_require will be installed extras = - test -commands = - pytest --pyargs sunkit_spex {toxinidir}/docs --cov sunkit_spex --cov-config={toxinidir}/setup.cfg {posargs} - - -[testenv:build_docs] -changedir = docs -description = invoke sphinx-build to build the HTML docs -extras = docs + tests +commands_pre = + oldestdeps: minimum_dependencies sunkit_spex --filename requirements-min.txt + oldestdeps: pip install -r requirements-min.txt + pip freeze --all --no-input commands = - sphinx-build -W -b html . _build/html {posargs} - + # To amend the pytest command for different factors you can add a line + # which starts with a factor like `online: --remote-data=any \` + # If you have no factors which require different commands this is all you need: + pytest \ + -vvv \ + -r fEs \ + --pyargs sunkit_spex \ + --cov-report=xml \ + --cov=sunkit_spex \ + --cov-config={toxinidir}/.coveragerc \ + {toxinidir}/docs \ + {posargs} [testenv:codestyle] +pypi_filter = skip_install = true description = Run all style and file checks with pre-commit deps = pre-commit commands = - python -V pre-commit install-hooks - pre-commit run --all-files + pre-commit run --color always --all-files --show-diff-on-failure + +[testenv:build_docs] +description = invoke sphinx-build to build the HTML docs +change_dir = + docs +extras = + docs +commands = + sphinx-build -j auto --color -W --keep-going -b html -d _build/.doctrees . _build/html {posargs} From 9375a96bb2f0ba51f10ebb531018c7129a036316 Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Mon, 22 Jul 2024 14:28:06 +0200 Subject: [PATCH 02/16] Adding spex custom settings --- .codespellrc | 10 +++++++--- .flake8 | 27 --------------------------- .github/workflows/ci.yml | 2 +- .ruff.toml | 7 ++++++- sunkit_spex/__init__.py | 2 +- 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 .flake8 diff --git a/.codespellrc b/.codespellrc index 042a14ed..7bf6883f 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,5 +1,5 @@ [codespell] -skip = *.asdf,*.fits,*.fts,*.header,*.json,*.xsh,*cache*,*egg*,*extern*,.git,.idea,.tox,_build,*truncated,*.svg,.asv_env,.history +skip = ,*.fits,*.fts,*.header,*.json,*.xsh,*cache*,*egg*,*extern*,.git,.idea,.tox,_build,*truncated,*.svg,.asv_env,.history,sunkit_spex/fitting_legacy/* ignore-words-list = alog, nd, @@ -9,5 +9,9 @@ ignore-words-list = te, upto, afile, - precessed, - precess + combin, + livetime, + livetimes, + sav, + selt + diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 19540755..00000000 --- a/.flake8 +++ /dev/null @@ -1,27 +0,0 @@ -[flake8] -ignore = - # missing-whitespace-around-operator - E225 - # missing-whitespace-around-arithmetic-operator - E226 - # line-too-long - E501 - # unused-import - F401 - # undefined-local-with-import-star - F403 - # redefined-while-unused - F811 - # Line break occurred before a binary operator - W503, - # Line break occurred after a binary operator - W504 -max-line-length = 110 -exclude = - .git - __pycache__ - docs/conf.py - build - sunkit-spex/__init__.py -rst-directives = - plot diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58e912d1..2c148b7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: coverage: codecov toxdeps: tox-pypi-filter envs: | - - linux: py312 + - linux: py39 secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.ruff.toml b/.ruff.toml index f77e539c..59f16bc9 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -5,6 +5,7 @@ exclude = [ "__pycache__", "build", "sunkit-spex/version.py", + "sunkit_spex/legacy/fitting_legacy" ] [lint] @@ -25,7 +26,8 @@ extend-ignore = [ "setup.py" = ["INP001"] "conftest.py" = ["INP001"] "docs/conf.py" = [ - "E402" # Module imports not at top of file + "E402", # Module imports not at top of file + "F403" ] "docs/*.py" = [ "INP001", # Implicit-namespace-package. The examples are not a package. @@ -35,3 +37,6 @@ extend-ignore = [ [lint.pydocstyle] convention = "numpy" + +[lint.flake8-pytest-style] +parametrize-names-type = "csv" diff --git a/sunkit_spex/__init__.py b/sunkit_spex/__init__.py index 46a3cf00..65572299 100644 --- a/sunkit_spex/__init__.py +++ b/sunkit_spex/__init__.py @@ -1,4 +1,4 @@ -from .version import version as __version__ +from .version import __version__ from . import extern from .legacy import fitting From 6a5e5534b84553add687c63a7e7bad94d6215e20 Mon Sep 17 00:00:00 2001 From: Shane Maloney Date: Wed, 24 Jul 2024 16:36:44 -0600 Subject: [PATCH 03/16] Fix tests --- .github/workflows/ci.yml | 2 +- pytest.ini | 6 ++++++ .../physical/tests/{test_thermal.py => test_thermal2.py} | 0 3 files changed, 7 insertions(+), 1 deletion(-) rename sunkit_spex/models/physical/tests/{test_thermal.py => test_thermal2.py} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c148b7d..338df812 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: submodules: false coverage: codecov toxdeps: tox-pypi-filter - posargs: -n auto + posargs: envs: | - windows: py311 - macos: py310 diff --git a/pytest.ini b/pytest.ini index 580de233..23cd925f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -31,3 +31,9 @@ filterwarnings = # A list of warnings to ignore follows. If you add to this list, you MUST # add a comment or ideally a link to an issue that explains why the warning # is being ignored + ignore:numpy.ndarray size changed.*:RuntimeWarning + ignore:Some input energy values outside valid range.*:UserWarning + ignore:invalid value encountered in.*:RuntimeWarning + ignore:divide by zero encountered in.*:RuntimeWarning + ignore:The truth value of an empty array is ambiguous..*:DeprecationWarning + ignore:LinAlgError when calculating the hessian. Errors may not be calculated.:UserWarning diff --git a/sunkit_spex/models/physical/tests/test_thermal.py b/sunkit_spex/models/physical/tests/test_thermal2.py similarity index 100% rename from sunkit_spex/models/physical/tests/test_thermal.py rename to sunkit_spex/models/physical/tests/test_thermal2.py From 4bef009c5a8c288003a3b65ff08c5d0802ec2340 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:02:09 +0100 Subject: [PATCH 04/16] cruft update --- .cruft.json | 2 +- .github/workflows/ci.yml | 35 ++++++++++++++---------- .github/workflows/sub_package_update.yml | 2 +- .pre-commit-config.yaml | 4 +-- .readthedocs.yaml | 4 +-- .rtd-environment.yml | 2 +- docs/conf.py | 16 +++++++++-- pyproject.toml | 6 ++-- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.cruft.json b/.cruft.json index 6fe337fd..099fa975 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sunpy/package-template", - "commit": "112d7d4adf0fa168bbb9ddb1886ad4f1e595b8be", + "commit": "dd830771f0bb01d5313912e0082f3434715e474a", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 338df812..d9d33d97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,3 @@ - name: CI on: @@ -38,7 +37,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.12' - run: python -m pip install -U --user build - run: python -m build . --sdist - run: python -m pip install -U --user twine @@ -63,7 +62,7 @@ jobs: needs: [core] uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main with: - default_python: '3.10' + default_python: '3.12' submodules: false pytest: false toxdeps: tox-pypi-filter @@ -81,7 +80,7 @@ jobs: ) uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@main with: - default_python: '3.10' + default_python: '3.12' submodules: false coverage: codecov toxdeps: tox-pypi-filter @@ -90,13 +89,21 @@ jobs: secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - publish_pure: - needs: [test, docs] - uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@main - with: - python-version: '3.10' - test_extras: 'tests' - test_command: 'pytest -p no:warnings --doctest-rst --pyargs sunkit_spex' - submodules: false - secrets: - pypi_token: ${{ secrets.pypi_token }} + publish: + # Build wheels on PRs only when labelled. Releases will only be published if tagged ^v.* + # see https://github-actions-workflows.openastronomy.org/en/latest/publish.html#upload-to-pypi + if: | + github.event_name != 'pull_request' || + ( + github.event_name == 'pull_request' && + contains(github.event.pull_request.labels.*.name, 'Run publish') + ) + needs: [test, docs] + uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@main + with: + python-version: '3.12' + test_extras: 'tests' + test_command: 'pytest -p no:warnings --doctest-rst --pyargs sunkit_spex' + submodules: false + secrets: + pypi_token: ${{ secrets.pypi_token }} diff --git a/.github/workflows/sub_package_update.yml b/.github/workflows/sub_package_update.yml index 06779481..74558476 100644 --- a/.github/workflows/sub_package_update.yml +++ b/.github/workflows/sub_package_update.yml @@ -65,7 +65,7 @@ jobs: - name: Create pull request if: steps.check.outputs.has_changes == '1' - uses: peter-evans/create-pull-request@v6 + uses: peter-evans/create-pull-request@v7 with: token: ${{ secrets.GITHUB_TOKEN }} add-paths: ${{ matrix.add-paths }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index def4535a..c1e54840 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: # This should be before any formatting hooks like isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.5.2" + rev: "v0.6.9" hooks: - id: ruff args: ["--fix"] @@ -11,7 +11,7 @@ repos: - id: isort exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|sunkit_spex/extern)$" - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-ast - id: check-case-conflict diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 790abab4..3d9312da 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,9 +1,9 @@ version: 2 build: - os: ubuntu-22.04 + os: ubuntu-lts-latest tools: - python: "mambaforge-4.10" + python: "mambaforge-latest" jobs: post_checkout: - git fetch --unshallow || true diff --git a/.rtd-environment.yml b/.rtd-environment.yml index f13d82a5..f692a12f 100644 --- a/.rtd-environment.yml +++ b/.rtd-environment.yml @@ -2,6 +2,6 @@ name: sunkit-spex channels: - conda-forge dependencies: - - python=3.10 + - python=3.12 - pip - graphviz!=2.42.*,!=2.43.* diff --git a/docs/conf.py b/docs/conf.py index 814aa0b2..58e602ee 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -7,11 +7,23 @@ import datetime import pathlib +from packaging.version import Version + # -- Project information ----------------------------------------------------- # The full version, including alpha/beta/rc tags from sunkit_spex import __version__ -release = __version__ + +_version = Version(__version__) +version = release = str(_version) +# Avoid "post" appearing in version string in rendered docs +if _version.is_postrelease: + version = release = _version.base_version +# Avoid long githashes in rendered Sphinx docs +elif _version.is_devrelease: + version = release = f"{_version.base_version}.dev{_version.dev}" +is_development = _version.is_devrelease +is_release = not(_version.is_prerelease or _version.is_devrelease) project = "sunkit-spex" author = "The SunPy Community" @@ -54,7 +66,7 @@ master_doc = "index" # Treat everything in single ` as a Python reference. -default_role = 'py:obj' +default_role = "py:obj" # -- Options for intersphinx extension --------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index df0ce305..9539fcf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ requires = [ "setuptools>=56,!=61.0.0", "setuptools_scm[toml]>=6.2", - "wheel" + "wheel", ] build-backend = "setuptools.build_meta" @@ -11,7 +11,7 @@ name = "sunkit_spex" description = "A package for solar X-ray spectroscopy." requires-python = ">=3.9" readme = { file = "README.rst", content-type = "text/x-rst" } -license = { file = "licenses/LICENSE.rst", content-type = "text/plain" } +license = { file = "licenses/LICENSE.rst" } authors = [ { name = "The SunPy Community", email = "sunpy@googlegroups.com" }, ] @@ -42,6 +42,7 @@ tests = [ docs = [ "sphinx", "sphinx-automodapi", + "packaging", ] [project.urls] repository = "https://sunkit-spex.readthedocs.io" @@ -51,6 +52,7 @@ zip-safe = false include-package-data = true [tool.setuptools.packages.find] +include = ["sunkit_spex*"] exclude = ["sunkit_spex._dev*"] [tool.setuptools_scm] From 95cc80b51254932047920702dcd2cdee3beadb03 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:15:00 +0100 Subject: [PATCH 05/16] Run pre-commit --- .codespellrc | 1 - .isort.cfg | 1 + .pre-commit-config.yaml | 1 + .ruff.toml | 13 ++++++-- ruff.toml | 42 -------------------------- sunkit_spex/legacy/thermal.py | 1 + sunkit_spex/models/physical/thermal.py | 3 +- 7 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 ruff.toml diff --git a/.codespellrc b/.codespellrc index 7bf6883f..3d74b99d 100644 --- a/.codespellrc +++ b/.codespellrc @@ -14,4 +14,3 @@ ignore-words-list = livetimes, sav, selt - diff --git a/.isort.cfg b/.isort.cfg index 9eec8507..a55a4f8a 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -3,6 +3,7 @@ balanced_wrapping = true skip = docs/conf.py sunkit_spex/__init__.py + sunkit_spex/legacy/ default_section = THIRDPARTY include_trailing_comma = true known_astropy = astropy, asdf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1e54840..384cd331 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: hooks: - id: ruff args: ["--fix"] + - id: ruff-format - repo: https://github.com/PyCQA/isort rev: 5.13.2 hooks: diff --git a/.ruff.toml b/.ruff.toml index 59f16bc9..346fe4b1 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -1,11 +1,12 @@ target-version = "py310" -line-length = 110 +line-length = 120 exclude = [ ".git,", "__pycache__", "build", - "sunkit-spex/version.py", - "sunkit_spex/legacy/fitting_legacy" + "sunkit_spex/version.py", + "sunkit_spex/legacy/fitting", + "sunkit_spex/extern/", ] [lint] @@ -40,3 +41,9 @@ convention = "numpy" [lint.flake8-pytest-style] parametrize-names-type = "csv" + +[format] +exclude = [ + "sunkit_spex/_dev/scm_version.py", + "docs/conf.py", +] diff --git a/ruff.toml b/ruff.toml deleted file mode 100644 index b45e2a42..00000000 --- a/ruff.toml +++ /dev/null @@ -1,42 +0,0 @@ -target-version = "py39" -line-length = 120 -exclude = [ - ".git,", - "__pycache__", - "build", - "sunkit_spex/version.py", - "sunkit_spex/legacy/fitting" -] - -[lint] -select = ["E", "F", "W", "UP", "PT"] -extend-ignore = [ - # pycodestyle (E, W) - "E501", # LineTooLong # TODO! fix - # pytest (PT) - "PT001", # Always use pytest.fixture() - "PT004", # Fixtures which don't return anything should have leading _ - "PT007", # Parametrize should be lists of tuples # TODO! fix - "PT011", # Too broad exception assert # TODO! fix - "PT023", # Always use () on pytest decorators -] - - -[lint.per-file-ignores] -# Part of configuration, not a package. -"setup.py" = ["INP001"] -"conftest.py" = ["INP001"] -"docs/conf.py" = ["E402", "F403"] -"docs/*.py" = [ - "INP001", # Implicit-namespace-package. The examples are not a package. -] -"__init__.py" = ["E402", "F401", "F403"] -"test_*.py" = ["B011", "D", "E402", "PGH001", "S101"] -# Need to import clients to register them, but don't use them in file -#"sunpy/net/__init__.py" = ["F811"] - -[lint.pydocstyle] -convention = "numpy" - -[lint.flake8-pytest-style] -parametrize-names-type = "csv" diff --git a/sunkit_spex/legacy/thermal.py b/sunkit_spex/legacy/thermal.py index d39d1fea..c2f60165 100644 --- a/sunkit_spex/legacy/thermal.py +++ b/sunkit_spex/legacy/thermal.py @@ -7,6 +7,7 @@ import astropy.units as u from sunpy.data import manager + from .io import load_chianti_continuum, load_chianti_lines_lite, load_xray_abundances __all__ = [ diff --git a/sunkit_spex/models/physical/thermal.py b/sunkit_spex/models/physical/thermal.py index f17950d4..d2db52db 100644 --- a/sunkit_spex/models/physical/thermal.py +++ b/sunkit_spex/models/physical/thermal.py @@ -6,12 +6,13 @@ import astropy.units as u +from sunpy.data import manager + from sunkit_spex.models.physical.io import ( load_chianti_continuum, load_chianti_lines_lite, load_xray_abundances, ) -from sunpy.data import manager __all__ = [ "thermal_emission", From cd2bb078f5eb9f1322e7fb8ae42dcd449577e2ca Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:17:27 +0100 Subject: [PATCH 06/16] huh --- .../models/physical/tests/{test_thermal2.py => test_thermal.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sunkit_spex/models/physical/tests/{test_thermal2.py => test_thermal.py} (100%) diff --git a/sunkit_spex/models/physical/tests/test_thermal2.py b/sunkit_spex/models/physical/tests/test_thermal.py similarity index 100% rename from sunkit_spex/models/physical/tests/test_thermal2.py rename to sunkit_spex/models/physical/tests/test_thermal.py From c49b79b354ccd94f5bca22e85cc9b5eedc830e53 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:20:05 +0100 Subject: [PATCH 07/16] bad py39 you old --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9d33d97..38350cad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: coverage: codecov toxdeps: tox-pypi-filter envs: | - - linux: py39 + - linux: py312 secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 93fdc049d8351cf17c5abc9569dcef2388e8129c Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:29:00 +0100 Subject: [PATCH 08/16] make the tests pass --- pyproject.toml | 4 +++- sunkit_spex/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9539fcf5..7c79f3a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,9 @@ dependencies = [ "quadpy", "scipy", "sunpy", - "xarray" + "xarray", + "gwcs", + "ndcube", ] dynamic = ["version"] diff --git a/sunkit_spex/__init__.py b/sunkit_spex/__init__.py index 65572299..46a3cf00 100644 --- a/sunkit_spex/__init__.py +++ b/sunkit_spex/__init__.py @@ -1,4 +1,4 @@ -from .version import __version__ +from .version import version as __version__ from . import extern from .legacy import fitting From 450a41827b2c58df1b2ae2f80274347ffde35c01 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 16:32:35 +0100 Subject: [PATCH 09/16] remove circleci --- .circleci/config.yml | 76 ----------------------------------------- .circleci/early_exit.sh | 7 ---- 2 files changed, 83 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100644 .circleci/early_exit.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 54437dac..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,76 +0,0 @@ -no-backports: &no-backports - name: Skip any branches called backport* - command: | - if [[ "${CIRCLE_BRANCH}" = *"backport"* ]]; then - circleci step halt - fi - -skip-check: &skip-check - name: Check for [ci skip] - command: bash .circleci/early_exit.sh - -merge-check: &merge-check - name: Check if we need to merge upstream master - command: | - if [[ -n "${CIRCLE_PR_NUMBER}" ]]; then - git fetch origin --tags - git fetch origin +refs/pull/$CIRCLE_PR_NUMBER/merge:pr/$CIRCLE_PR_NUMBER/merge - git checkout -qf pr/$CIRCLE_PR_NUMBER/merge - fi - -apt-run: &apt-install - name: Install apt packages - command: | - apt update - apt install -y graphviz build-essential - -version: 2 -jobs: - twine-check: - docker: - - image: continuumio/miniconda3 - steps: - - checkout - - run: *no-backports - - run: *skip-check - - run: *merge-check - - run: pip install -U pep517 - - run: python -m pep517.build --source . - - run: python -m pip install -U --user --force-reinstall twine - - run: python -m twine check dist/* - - html-docs: - docker: - - image: continuumio/miniconda3 - steps: - - checkout - - run: *no-backports - - run: *skip-check - - run: *merge-check - - run: *apt-install - - run: pip install -U 'tox<4' tox-pypi-filter - - run: tox -e build_docs - - run: - name: Prepare for upload - command: | - # If it's not a PR, don't upload - if [ -z "${CIRCLE_PULL_REQUEST}" ]; then - rm -r docs/_build/html/* - else - # If it is a PR, delete sources, because it's a lot of files - # which we don't really need to upload - rm -r docs/_build/html/_sources - fi - - store_artifacts: - path: docs/_build/html - -workflows: - version: 2 - - twine-check: - jobs: - - twine-check - - test-documentation: - jobs: - - html-docs diff --git a/.circleci/early_exit.sh b/.circleci/early_exit.sh deleted file mode 100644 index 6890bc29..00000000 --- a/.circleci/early_exit.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -commitmessage=$(git log --pretty=%B -n 1) -if [[ $commitmessage = *"[ci skip]"* ]] || [[ $commitmessage = *"[skip ci]"* ]]; then - echo "Skipping build because [ci skip] found in commit message" - circleci step halt -fi From 731224e702b7cf63535787f5dd6255a26ebde9eb Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 17:03:58 +0100 Subject: [PATCH 10/16] Fix oldestdeps --- pyproject.toml | 29 +++++++++++++++-------------- pytest.ini | 3 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7c79f3a9..cb49294d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,20 +16,21 @@ authors = [ { name = "The SunPy Community", email = "sunpy@googlegroups.com" }, ] dependencies = [ - "corner", - "emcee", - "matplotlib", - "ndim", - "nestle", - "numdifftools", - "orthopy", - "parfive", - "quadpy", - "scipy", - "sunpy", - "xarray", - "gwcs", - "ndcube", + "corner>=2.2", + "emcee>=3.1", + "matplotlib>=3.7", + "ndim>=0.1", + "nestle>=0.2", + "numdifftools>=0.9.40", + "numpy>=1.24", + "orthopy>=0.9", + "parfive>=2.0", + "quadpy>=0.17", + "scipy>=1.11", + "sunpy>=6.0", + "xarray>=2022.10", + "gwcs>=0.19", + "ndcube>=2.1", ] dynamic = ["version"] diff --git a/pytest.ini b/pytest.ini index 23cd925f..c9c1945e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -37,3 +37,6 @@ filterwarnings = ignore:divide by zero encountered in.*:RuntimeWarning ignore:The truth value of an empty array is ambiguous..*:DeprecationWarning ignore:LinAlgError when calculating the hessian. Errors may not be calculated.:UserWarning + # Oldestdeps issues + ignore:`finfo.machar` is deprecated:DeprecationWarning + ignore:Please use `convolve1d` from the `scipy.ndimage` namespace, the `scipy.ndimage.filters` namespace is deprecated.:DeprecationWarning From 6d035b6a4fe227f30a06d666ebb03637116bbc0b Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 15 Oct 2024 17:20:02 +0100 Subject: [PATCH 11/16] Fix docs --- .gitignore | 3 +++ pyproject.toml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index bd0b120a..ac8c9d82 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,9 @@ docs/_build/ # automodapi docs/api docs/sg_execution_times.rst +docs/generated/ +examples/rhessi/ +examples/sunxspexRhessiSpectralFitting.pickle # PyBuilder .pybuilder/ diff --git a/pyproject.toml b/pyproject.toml index cb49294d..c2aa34d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,11 @@ docs = [ "sphinx", "sphinx-automodapi", "packaging", + "sphinx-changelog", + "sphinx-gallery", + "sunpy-sphinx-theme", ] + [project.urls] repository = "https://sunkit-spex.readthedocs.io" From bc4f5aff0e927f50703d46298e53ceeda4275b32 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 16 Oct 2024 10:43:39 +0100 Subject: [PATCH 12/16] remove old rtd --- .readthedocs.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index ef587ab8..00000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,28 +0,0 @@ -# .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" - apt_packages: - - graphviz - -# 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: - install: - - method: pip - path: . - extra_requirements: - - docs - - all From aeab7765a0ce4a11adef6acb895ce3aaaad1ad91 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 16 Oct 2024 10:48:27 +0100 Subject: [PATCH 13/16] cleanup sunpy theme --- docs/conf.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 58e602ee..b801c1e7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -85,11 +85,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -try: - from sunpy_sphinx_theme.conf import * -except ImportError: - html_theme = "sunpy" - +html_theme = "sunpy" # 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, @@ -113,7 +109,6 @@ "filename_pattern": "^((?!skip_).)*$", "examples_dirs": example_dir, "gallery_dirs": path.joinpath("generated", "gallery"), - # "default_thumb_file": path.joinpath("logo", "sunpy_icon_128x128.png"), "abort_on_example_error": False, "plot_gallery": "True", "remove_config_comments": True, From 032cd43fea8c6a97dba383967cb94b319ff2391f Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 16 Oct 2024 10:54:43 +0100 Subject: [PATCH 14/16] some cruft in pyproject --- pyproject.toml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c2aa34d8..3d48dccc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,18 +66,6 @@ exclude = ["sunkit_spex._dev*"] write_to = "sunkit_spex/_version.py" [ tool.gilesbot ] -# [ tool.gilesbot.circleci_artifacts ] -# enabled = true -# -# [ tool.gilesbot.circleci_artifacts.figure_report ] -# url = ".tmp/py38-figure/figure_test_images/fig_comparison.html" -# message = "Click details to see the figure test comparisons, for py38-figure." -# report_on_fail = true -# -# [ tool.gilesbot.circleci_artifacts.figure_report_devdeps ] -# url = ".tmp/py39-figure-devdeps/figure_test_images/fig_comparison.html" -# message = "Click details to see the figure test comparisons for py39-figure-devdeps." -# report_on_fail = true [ tool.gilesbot.pull_requests ] enabled = true From 10e35f40c1465dc987c2d1374b1ffeef6a95f7eb Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 16 Oct 2024 10:55:20 +0100 Subject: [PATCH 15/16] update to python 3.10 min --- .cruft.json | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.cruft.json b/.cruft.json index 099fa975..f6b9c682 100644 --- a/.cruft.json +++ b/.cruft.json @@ -11,7 +11,7 @@ "author_email": "sunpy@googlegroups.com", "project_url": "https://sunkit-spex.readthedocs.io", "license": "BSD 3-Clause", - "minimum_python_version": "3.9", + "minimum_python_version": "3.10", "use_compiled_extensions": "n", "enable_dynamic_dev_versions": "y", "include_example_code": "n", diff --git a/pyproject.toml b/pyproject.toml index 3d48dccc..bfd79d33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta" [project] name = "sunkit_spex" description = "A package for solar X-ray spectroscopy." -requires-python = ">=3.9" +requires-python = ">=3.10" readme = { file = "README.rst", content-type = "text/x-rst" } license = { file = "licenses/LICENSE.rst" } authors = [ From 9af692faad52d92f57db2d3654ce6760a5acb1eb Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Wed, 16 Oct 2024 11:36:15 +0100 Subject: [PATCH 16/16] Update sunkit_spex/_dev/__init__.py Co-authored-by: Shane Maloney --- sunkit_spex/_dev/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunkit_spex/_dev/__init__.py b/sunkit_spex/_dev/__init__.py index 72583c08..e38b3a8d 100644 --- a/sunkit_spex/_dev/__init__.py +++ b/sunkit_spex/_dev/__init__.py @@ -1,5 +1,5 @@ """ -This package contains utilities that are only used when developing drms in a +This package contains utilities that are only used when developing in a copy of the source repository. These files are not installed, and should not be assumed to exist at runtime.