diff --git a/.cruft.json b/.cruft.json new file mode 100644 index 0000000..e35c008 --- /dev/null +++ b/.cruft.json @@ -0,0 +1,18 @@ +{ + "template": "https://github.com/ecmwf-projects/cookiecutter-conda-package", + "commit": "d379e35af1aa17d816367bcb0942fcf3e238be9d", + "checkout": null, + "context": { + "cookiecutter": { + "project_name": "sarsen", + "project_slug": "sarsen", + "project_short_description": "Sarsen", + "copyright_holder": "B-Open Solutions srl", + "copyright_year": "2016", + "mypy_strict": true, + "integration_tests": true, + "_template": "https://github.com/ecmwf-projects/cookiecutter-conda-package" + } + }, + "directory": null +} diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index 1d2bc59..dc6c9c7 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -14,65 +14,95 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +defaults: + run: + shell: bash -l {0} + jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.x - uses: pre-commit/action@v3.0.0 + combine-environments: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Install conda-merge + run: | + python -m pip install conda-merge + - name: Combine environments + run: | + for SUFFIX in ci integration; do + conda-merge ci/environment-$SUFFIX.yml environment.yml > ci/combined-environment-$SUFFIX.yml || exit + done + - uses: actions/upload-artifact@v4 + with: + name: combined-environments + path: ci/combined-environment-*.yml + unit-tests: - name: unit-tests (3.11) + name: unit-tests + needs: combine-environments runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} + strategy: + matrix: + python-version: ['3.11'] steps: - uses: actions/checkout@v4 - - name: Install Conda environment with Micromamba - uses: mamba-org/provision-with-micromamba@v16 + - uses: actions/download-artifact@v4 + with: + name: combined-environments + path: ci + - name: Get current date + id: date + run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}" + - uses: mamba-org/setup-micromamba@v1 with: - environment-file: environment.yml + environment-file: ci/combined-environment-ci.yml environment-name: DEVELOP - channels: conda-forge - cache-env: true - cache-env-key: ubuntu-latest-3.11 - extra-specs: | - python=3.11 + cache-environment: true + cache-environment-key: environment-${{ steps.date.outputs.date }} + cache-downloads-key: downloads-${{ steps.date.outputs.date }} + create-args: >- + python=${{ matrix.python-version }} - name: Install package run: | python -m pip install --no-deps -e . - name: Run tests run: | - make test COV_REPORT=xml - - name: Run doc tests - run: | - make doc-test COV_REPORT=xml - - name: Upload code coverage to Codecov - uses: codecov/codecov-action@v3.1.4 + make unit-tests COV_REPORT=xml type-check: - needs: [unit-tests] + needs: [combine-environments, unit-tests] runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} steps: - uses: actions/checkout@v4 - - name: Install Conda environment with Micromamba - uses: mamba-org/provision-with-micromamba@v16 + - uses: actions/download-artifact@v4 with: - environment-file: environment.yml + name: combined-environments + path: ci + - name: Get current date + id: date + run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}" + - uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/combined-environment-ci.yml environment-name: DEVELOP - channels: conda-forge - cache-env: true - cache-env-key: ubuntu-latest-3.11 - extra-specs: | + cache-environment: true + cache-environment-key: environment-${{ steps.date.outputs.date }} + cache-downloads-key: downloads-${{ steps.date.outputs.date }} + create-args: >- python=3.11 - name: Install package run: | @@ -81,56 +111,125 @@ jobs: run: | make type-check + docs-build: + needs: [combine-environments, unit-tests] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: combined-environments + path: ci + - name: Get current date + id: date + run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}" + - uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/combined-environment-ci.yml + environment-name: DEVELOP + cache-environment: true + cache-environment-key: environment-${{ steps.date.outputs.date }} + cache-downloads-key: downloads-${{ steps.date.outputs.date }} + create-args: >- + python=3.11 + - name: Install package + run: | + python -m pip install --no-deps -e . + - name: Build documentation + run: | + make docs-build + integration-tests: - needs: [unit-tests] + needs: [combine-environments, unit-tests] + if: | + success() && true runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} strategy: matrix: - python-version: ['3.10', '3.9'] - extra: [''] include: - python-version: '3.9' - extra: -minver - - python-version: '3.11' - extra: -mindep + extra: -integration + steps: - uses: actions/checkout@v4 - - name: Install Conda environment with Micromamba - uses: mamba-org/provision-with-micromamba@v16 + - uses: actions/download-artifact@v4 + with: + name: combined-environments + path: ci + - name: Get current date + id: date + run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}" + - uses: mamba-org/setup-micromamba@v1 with: - environment-file: environment${{ matrix.extra }}.yml + environment-file: ci/combined-environment${{ matrix.extra }}.yml environment-name: DEVELOP${{ matrix.extra }} - channels: conda-forge - cache-env: true - cache-env-key: ubuntu-latest-${{ matrix.python-version }}${{ matrix.extra }}. - extra-specs: | + cache-environment: true + cache-environment-key: environment-${{ steps.date.outputs.date }} + cache-downloads-key: downloads-${{ steps.date.outputs.date }} + create-args: >- python=${{ matrix.python-version }} - name: Install package run: | python -m pip install --no-deps -e . - name: Run tests run: | - make test COV_REPORT=xml - - name: Upload code coverage to Codecov - uses: codecov/codecov-action@v3.1.4 + make unit-tests COV_REPORT=xml distribution: runs-on: ubuntu-latest - needs: [integration-tests, type-check] + needs: [unit-tests, type-check, docs-build, integration-tests] + if: | + always() && + needs.unit-tests.result == 'success' && + needs.type-check.result == 'success' && + needs.docs-build.result == 'success' && + (needs.integration-tests.result == 'success' || needs.integration-tests.result == 'skipped') steps: - uses: actions/checkout@v4 - - name: Build distributions + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install package + run: | + python -m pip install --upgrade pip + python -m pip install build twine + - name: Build distribution run: | - $CONDA/bin/python -m pip install build - $CONDA/bin/python -m build - - name: Publish a Python distribution to PyPI - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@release/v1 + python -m build + - name: Check wheels + run: | + cd dist || exit + python -m pip install sarsen*.whl || exit + python -m twine check --strict * || exit + python -c "import sarsen" || exit + cd .. + - uses: actions/upload-artifact@v4 + with: + name: distribution + path: dist + + upload-to-pypi: + runs-on: ubuntu-latest + needs: distribution + if: | + always() && + needs.distribution.result == 'success' && + github.event_name == 'push' && + startsWith(github.ref, 'refs/tags') + environment: + name: pypi + url: https://pypi.org/p/sarsen + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publish + + steps: + - uses: actions/download-artifact@v4 + with: + name: distribution + path: dist + - uses: pypa/gh-action-pypi-publish@v1.8.11 with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} + verbose: true diff --git a/.gitignore b/.gitignore index 48c5beb..cfaf797 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,243 @@ # project specific *.tif + +# setuptools-scm version.py -notebooks/GRD +# Sphinx automatic generation of API +docs/_api/ + +# Combined environments +ci/combined-environment-*.yml + +# Created by https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,vim,visualstudiocode,pycharm,emacs,linux,macos,windows +# Edit at https://www.toptal.com/developers/gitignore?templates=python,jupyternotebooks,vim,visualstudiocode,pycharm,emacs,linux,macos,windows + +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### JupyterNotebooks ### +# gitignore template for Jupyter Notebooks +# website: http://jupyter.org/ + +.ipynb_checkpoints +*/.ipynb_checkpoints/* + +# IPython +profile_default/ +ipython_config.py + +# Remove previous ipynb_checkpoints +# git rm -r .ipynb_checkpoints/ + +### Linux ### + +# 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* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# 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 + +### macOS Patch ### +# iCloud generated files +*.icloud + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -15,7 +250,6 @@ __pycache__/ .Python build/ develop-eggs/ -dist/ downloads/ eggs/ .eggs/ @@ -25,7 +259,6 @@ parts/ sdist/ var/ wheels/ -pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -55,6 +288,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -77,17 +311,17 @@ instance/ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook -.ipynb_checkpoints # IPython -profile_default/ -ipython_config.py # pyenv -.python-version +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. @@ -96,7 +330,22 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# 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 @@ -133,8 +382,93 @@ dmypy.json # Pyre type checker .pyre/ -# others -dask-worker-space -.DS_Store -.vscode -.gitignore +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +### VisualStudioCode ### +.vscode/ +# .vscode/* +# !.vscode/settings.json +# !.vscode/tasks.json +# !.vscode/launch.json +# !.vscode/extensions.json +# !.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +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 + +# End of https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,vim,visualstudiocode,pycharm,emacs,linux,macos,windows diff --git a/.pre-commit-config-cruft.yaml b/.pre-commit-config-cruft.yaml new file mode 100644 index 0000000..b55f24f --- /dev/null +++ b/.pre-commit-config-cruft.yaml @@ -0,0 +1,7 @@ +repos: +- repo: https://github.com/cruft/cruft + rev: 2.15.0 + hooks: + - id: cruft + entry: cruft update -y + additional_dependencies: [toml] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62fca7c..7d86a38 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -8,34 +8,32 @@ repos: - id: check-yaml - id: check-toml - id: check-added-large-files + - id: check-merge-conflict - id: debug-statements - id: mixed-line-ending -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort -- repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - repo: https://github.com/keewis/blackdoc - rev: v0.3.8 + rev: v0.3.9 hooks: - id: blackdoc - exclude: generate_reductions.py - additional_dependencies: [black==22.3.0] -- repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + additional_dependencies: [black==23.11.0] +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.13 hooks: - - id: flake8 + - id: ruff + args: [--fix, --show-fixes] + - id: ruff-format - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: - id: mdformat - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.10.0 + rev: v2.12.0 hooks: - id: pretty-format-yaml - args: [--autofix] + args: [--autofix, --preserve-quotes] - id: pretty-format-toml args: [--autofix] +- repo: https://github.com/gitleaks/gitleaks + rev: v8.18.1 + hooks: + - id: gitleaks diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..85b2d46 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM continuumio/miniconda3 + +WORKDIR /src/sarsen + +COPY environment.yml /src/sarsen/ + +RUN conda install -c conda-forge gcc python=3.11 \ + && conda env update -n base -f environment.yml + +COPY . /src/sarsen + +RUN pip install --no-deps -e . diff --git a/Makefile b/Makefile index 9ffc0cb..1fa1138 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,36 @@ CONDA := conda CONDAFLAGS := COV_REPORT := html -default: qa test type-check +default: qa unit-tests type-check qa: pre-commit run --all-files -test: - python -m pytest -vv --cov=. --cov-report=$(COV_REPORT) - -doc-test: - python -m pytest -vv --doctest-glob='*.md' README.md +unit-tests: + python -m pytest -vv --cov=. --cov-report=$(COV_REPORT) --doctest-glob="*.md" --doctest-glob="*.rst" type-check: - python -m mypy --strict . + python -m mypy . conda-env-update: - $(CONDA) env update $(CONDAFLAGS) -f environment.yml + $(CONDA) install -y -c conda-forge conda-merge + $(CONDA) run conda-merge environment.yml ci/environment-ci.yml > ci/combined-environment-ci.yml + $(CONDA) env update $(CONDAFLAGS) -f ci/combined-environment-ci.yml + +docker-build: + docker build -t $(PROJECT) . + +docker-run: + docker run --rm -ti -v $(PWD):/srv $(PROJECT) + +template-update: + pre-commit run --all-files cruft -c .pre-commit-config-cruft.yaml -conda-env-update-all: conda-env-update - $(CONDA) env update $(CONDAFLAGS) -f environment-dev.yml +docs-build: + cd docs && rm -fr _api && make clean && make html + +# DO NOT EDIT ABOVE THIS LINE, ADD COMMANDS BELOW + + +doc-test: + python -m pytest -vv --doctest-glob='*.md' README.md diff --git a/ci/environment-ci.yml b/ci/environment-ci.yml new file mode 100644 index 0000000..5d9e350 --- /dev/null +++ b/ci/environment-ci.yml @@ -0,0 +1,21 @@ +# environment-ci.yml: Additional dependencies to install in the CI environment. +channels: +- conda-forge +- nodefaults +dependencies: +- make +- mypy +- myst-parser +- pip +- pre-commit +- pydata-sphinx-theme +- pytest +- pytest-cov +- sphinx +- sphinx-autoapi +# DO NOT EDIT ABOVE THIS LINE, ADD DEPENDENCIES BELOW +- mdformat +- pandas-stubs +- types-setuptools +- pip: + - mdformat-gfm diff --git a/ci/environment-integration.yml b/ci/environment-integration.yml new file mode 100644 index 0000000..82db3d6 --- /dev/null +++ b/ci/environment-integration.yml @@ -0,0 +1,19 @@ +# environment-integration.yml: Additional dependencies to install in the integration environment (e.g., pinned dependencies). +channels: +- conda-forge +- nodefaults +dependencies: +- make +- pytest +- pytest-cov +# DO NOT EDIT ABOVE THIS LINE, ADD DEPENDENCIES BELOW +- dask == 2023.2.0 +- fsspec == 2023.1.0 +- numpy == 1.22.0 +- packaging == 21.3 +- pandas == 1.4.0 +- rasterio == 1.3.0 +- rioxarray == 0.13.0 +- xarray == 2023.02.0 +- xarray-sentinel == 0.9.3 +- xmlschema == 2.2.0 diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_static/.gitkeep b/docs/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/_templates/.gitkeep b/docs/_templates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..b84d65c --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,76 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Import and path setup --------------------------------------------------- + +import os +import sys + +import sarsen + +sys.path.insert(0, os.path.abspath("../")) + +# -- Project information ----------------------------------------------------- + +project = "sarsen" +copyright = "2016, B-Open Solutions srl" +author = "B-Open Solutions srl" +version = sarsen.__version__ +release = sarsen.__version__ + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "autoapi.extension", + "myst_parser", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", +] + +# autodoc configuration +autodoc_typehints = "none" + +# autoapi configuration +autoapi_dirs = ["../sarsen"] +autoapi_ignore = ["*/version.py"] +autoapi_options = [ + "members", + "inherited-members", + "undoc-members", + "show-inheritance", + "show-module-summary", + "imported-members", +] +autoapi_root = "_api" + +# napoleon configuration +napoleon_google_docstring = False +napoleon_numpy_docstring = True +napoleon_preprocess_types = True + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "pydata_sphinx_theme" + +# 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"] diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..7b55574 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,16 @@ +# Welcome to sarsen's documentation! + +Sarsen. + +```{toctree} +:caption: 'Contents:' +:maxdepth: 2 + +API Reference <_api/sarsen/index> +``` + +# Indices and tables + +- {ref}`genindex` +- {ref}`modindex` +- {ref}`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..954237b --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%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.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/environment.yml b/environment.yml index b45766a..8d6d7f9 100644 --- a/environment.yml +++ b/environment.yml @@ -1,5 +1,12 @@ +# environment.yml: Mandatory dependencies only. channels: - conda-forge +- nodefaults +# EXAMPLE: +# dependencies: +# - package1 +# - package2 +# DO NOT EDIT ABOVE THIS LINE, ADD DEPENDENCIES BELOW AS SHOWN IN THE EXAMPLE dependencies: - attrs - bottleneck @@ -7,22 +14,11 @@ dependencies: - flox - fsspec - gdal -- make -- mdformat -- mypy -- numexpr - numpy >= 1.22.0 -- pandas-stubs -- pip -- pytest -- pytest-cov - rasterio >= 1.3.0 - rioxarray - scipy - typer -- types-setuptools - xarray >= 2022.06.0 - xarray-sentinel >= 0.9.3 - xmlschema -- pip: - - mdformat-gfm diff --git a/pyproject.toml b/pyproject.toml index c247891..7ea5dbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,17 +1,39 @@ [build-system] -requires = [ - "setuptools>=42", - "wheel", - "setuptools_scm[toml]>=3.4", - "setuptools_scm_git_archive" +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] + +[project] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering" +] +dependencies = [ + "attrs", + "flox", + "numpy", + "pandas", + "rasterio", + "rioxarray", + "typer", + "xarray >= 2022.06.0", + "xarray-sentinel >= 0.9.3" ] +description = "Algorithms and utilities for Synthetic Aperture Radar (SAR) sensors" +dynamic = ["version"] +license = {file = "LICENSE"} +name = "sarsen" +readme = "README.md" [tool.coverage.run] branch = true -[tool.isort] -profile = "black" - [tool.mypy] plugins = "numpy.typing.mypy_plugin" strict = true @@ -20,9 +42,41 @@ strict = true ignore_missing_imports = true module = ["py", "rasterio"] +[tool.ruff] +ignore = [ + # pydocstyle: Missing Docstrings + "D1" +] +# Same as Black. +indent-width = 4 +line-length = 88 +select = [ + # pyflakes + "F", + # pycodestyle + "E", + "W", + # isort + "I", + # pydocstyle + "D" +] + +[tool.ruff.lint.pycodestyle] +max-line-length = 110 + +[tool.ruff.pydocstyle] +convention = "numpy" + +[tool.setuptools] +packages = ["sarsen"] + +[tool.setuptools.package-data] +sarsen = ["py.typed"] + [tool.setuptools_scm] write_to = "sarsen/version.py" write_to_template = ''' -# don't change, don't track in version control +# Do not change! Do not track in version control! __version__ = "{version}" ''' diff --git a/sarsen/__init__.py b/sarsen/__init__.py index 9b99d2b..d589065 100644 --- a/sarsen/__init__.py +++ b/sarsen/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2016-2022 B-Open Solutions srl +# Copyright 2016, B-Open Solutions srl. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/sarsen/apps.py b/sarsen/apps.py index e2c7129..16d6b6e 100644 --- a/sarsen/apps.py +++ b/sarsen/apps.py @@ -20,7 +20,6 @@ def simulate_acquisition( include_variables: Container[str] = (), ) -> xr.Dataset: """Compute the image coordinates of the DEM given the satellite orbit.""" - orbit_interpolator = orbit.OrbitPolyfitIterpolator.from_position(position_ecef) position_ecef = orbit_interpolator.position() velocity_ecef = orbit_interpolator.velocity() @@ -40,12 +39,12 @@ def simulate_acquisition( for data_var_name in acquisition.data_vars: if include_variables and data_var_name not in include_variables: - acquisition = acquisition.drop_vars(data_var_name) + acquisition = acquisition.drop_vars(data_var_name) # type: ignore # drop coordinates that are not associated with any data variable for coord_name in acquisition.coords: if all(coord_name not in dv.coords for dv in acquisition.data_vars.values()): - acquisition = acquisition.drop_vars(coord_name) + acquisition = acquisition.drop_vars(coord_name) # type: ignore return acquisition diff --git a/sarsen/geocoding.py b/sarsen/geocoding.py index bce1cb4..4ee5469 100644 --- a/sarsen/geocoding.py +++ b/sarsen/geocoding.py @@ -90,7 +90,10 @@ def backward_geocode( # NOTE: dem_distance has the associated azimuth_time as a coordinate already _, _, _, (dem_distance, satellite_direction) = secant_method( - zero_doppler, t_prev, t_curr, diff_ufunc # type: ignore + zero_doppler, + t_prev, + t_curr, + diff_ufunc, ) acquisition = xr.Dataset( data_vars={ diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 310cc72..0000000 --- a/setup.cfg +++ /dev/null @@ -1,44 +0,0 @@ -[metadata] -name = sarsen -author = B-Open -author_email = software@bopen.eu -license = Apache License 2.0 -description = Algorithms and utilities for Synthetic Aperture Radar (SAR) sensors -url = https://github.com/bopen/sarsen -classifiers = - Development Status :: 4 - Beta - Intended Audience :: Science/Research - License :: OSI Approved :: Apache Software License - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - Topic :: Scientific/Engineering -long_description_content_type=text/markdown -long_description = file: README.md -keywords = algorithms, copernicus, earth-observation, remote-sensing, sentinel-1, sar, synthetic-aperture-radar, xarray - -[options] -packages = find: -python_requires = >=3.9 -install_requires = - attrs - flox - numpy - pandas - rasterio - rioxarray - typer - xarray >= 2022.06.0 - xarray-sentinel >= 0.9.3 -include_package_data = True - -[options.entry_points] -console_scripts = - sarsen = sarsen.__main__:app - -[flake8] -max-line-length = 120 -extend-ignore = E203, W503 diff --git a/tests/test_00_version.py b/tests/test_00_version.py new file mode 100644 index 0000000..8528f89 --- /dev/null +++ b/tests/test_00_version.py @@ -0,0 +1,5 @@ +import sarsen + + +def test_version() -> None: + assert sarsen.__version__ != "999" diff --git a/tests/test_10_chunking.py b/tests/test_10_chunking.py index d7a60f4..2ffa25d 100644 --- a/tests/test_10_chunking.py +++ b/tests/test_10_chunking.py @@ -1,5 +1,3 @@ -from typing import Callable - import numpy as np import xarray as xr @@ -62,6 +60,9 @@ def test_compute_chunks() -> None: def test_map_ovelap() -> None: arr = xr.DataArray(np.arange(22 * 31).reshape((22, 31)), dims=("x", "y")) - function: Callable[[xr.DataArray], xr.DataArray] = lambda x: x + + def function(x: xr.DataArray) -> xr.DataArray: + return x + res = chunking.map_ovelap(function=function, obj=arr, chunks=10, bound=2) assert res.equals(arr)