Skip to content

Commit 1c120d8

Browse files
authored
Merge pull request #41 from umr-lops/revisit-ci
add workflows and adapt pyproj for pre-commit
2 parents 4c0184c + 333c5c9 commit 1c120d8

File tree

16 files changed

+1719
-838
lines changed

16 files changed

+1719
-838
lines changed

.github/workflows/ci.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
detect-skip-ci-trigger:
16+
name: "Detect CI Trigger: [skip-ci]"
17+
if: |
18+
github.repository == 'umr-lops/xarray-safe-s1'
19+
&& (
20+
github.event_name == 'push' || github.event_name == 'pull_request'
21+
)
22+
runs-on: ubuntu-latest
23+
outputs:
24+
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 2
29+
- uses: xarray-contrib/ci-trigger@v1
30+
id: detect-trigger
31+
with:
32+
keyword: "[skip-ci]"
33+
34+
ci:
35+
name: ${{ matrix.os }} py${{ matrix.python-version }}
36+
runs-on: ${{ matrix.os }}
37+
needs: detect-skip-ci-trigger
38+
39+
if: needs.detect-skip-ci-trigger.outputs.triggered == 'false'
40+
41+
defaults:
42+
run:
43+
shell: bash -l {0}
44+
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
python-version: ["3.10", "3.11", "3.12"]
49+
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
50+
51+
steps:
52+
- name: Checkout the repository
53+
uses: actions/checkout@v4
54+
with:
55+
# need to fetch all tags to get a correct version
56+
fetch-depth: 0 # fetch all branches and tags
57+
58+
- name: Setup environment variables
59+
run: |
60+
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
61+
62+
echo "CONDA_ENV_FILE=ci/requirements/environment.yaml" >> $GITHUB_ENV
63+
64+
- name: Setup micromamba
65+
uses: mamba-org/setup-micromamba@v2
66+
with:
67+
environment-file: ${{ env.CONDA_ENV_FILE }}
68+
environment-name: xarray-safe-s1-tests
69+
cache-environment: true
70+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
71+
create-args: >-
72+
python=${{matrix.python-version}}
73+
74+
- name: Install xarray-safe-s1
75+
run: |
76+
python -m pip install --no-deps -e .
77+
78+
- name: Import xarray-safe-s1
79+
run: |
80+
python -c "import safe_s1"
81+
82+
- name: Run tests
83+
run: |
84+
python -m pytest --cov=safe_s1

.github/workflows/publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ jobs:
99
name: Publish to PyPI
1010
runs-on: ubuntu-latest
1111
permissions:
12-
contents: 'read'
13-
id-token: 'write'
12+
contents: "read"
13+
id-token: "write"
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Set up Python
1717
uses: actions/setup-python@v5
1818
with:
19-
python-version: '3.x'
19+
python-version: "3.x"
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip build twine
@@ -32,4 +32,4 @@ jobs:
3232
with:
3333
password: ${{ secrets.pypi_token }}
3434
repository_url: https://upload.pypi.org/legacy/
35-
verify_metadata: true
35+
verify_metadata: true

.github/workflows/upstream-dev.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: upstream-dev CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
- cron: "0 18 * * 0" # Weekly "On Sundays at 18:00" UTC
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
detect-test-upstream-trigger:
18+
name: "Detect CI Trigger: [test-upstream]"
19+
if: github.event_name == 'push' || github.event_name == 'pull_request'
20+
runs-on: ubuntu-latest
21+
outputs:
22+
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 2
27+
- uses: xarray-contrib/ci-trigger@v1.2
28+
id: detect-trigger
29+
with:
30+
keyword: "[test-upstream]"
31+
32+
upstream-dev:
33+
name: upstream-dev
34+
runs-on: ubuntu-latest
35+
needs: detect-test-upstream-trigger
36+
37+
if: |
38+
always()
39+
&& github.repository == 'umr-lops/xarray-safe-s1'
40+
&& (
41+
github.event_name == 'schedule'
42+
|| github.event_name == 'workflow_dispatch'
43+
|| needs.detect-test-upstream-trigger.outputs.triggered == 'true'
44+
|| contains(github.event.pull_request.labels.*.name, 'run-upstream')
45+
)
46+
47+
defaults:
48+
run:
49+
shell: bash -l {0}
50+
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
python-version: ["3.12"]
55+
56+
steps:
57+
- name: checkout the repository
58+
uses: actions/checkout@v4
59+
with:
60+
# need to fetch all tags to get a correct version
61+
fetch-depth: 0 # fetch all branches and tags
62+
63+
- name: set up conda environment
64+
uses: mamba-org/setup-micromamba@v1
65+
with:
66+
environment-file: ci/requirements/environment.yaml
67+
environment-name: tests
68+
create-args: >-
69+
python=${{ matrix.python-version }}
70+
pytest-reportlog
71+
72+
- name: install upstream-dev dependencies
73+
run: bash ci/install-upstream-dev.sh
74+
75+
- name: install the package
76+
run: python -m pip install --no-deps -e .
77+
78+
- name: show versions
79+
run: python -m pip list
80+
81+
- name: import
82+
run: |
83+
python -c 'import safe_s1'
84+
85+
- name: run tests
86+
if: success()
87+
id: status
88+
run: |
89+
python -m pytest -rf --report-log=pytest-log.jsonl
90+
91+
- name: report failures
92+
if: |
93+
failure()
94+
&& steps.tests.outcome == 'failure'
95+
&& github.event_name == 'schedule'
96+
uses: xarray-contrib/issue-from-pytest-log@v1
97+
with:
98+
log-path: pytest-log.jsonl

ci/install-upstream-dev.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
conda remove -y --force cytoolz numpy xarray toolz python-dateutil
4+
python -m pip install \
5+
-i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
6+
--no-deps \
7+
--pre \
8+
--upgrade \
9+
numpy \
10+
xarray
11+
python -m pip install --upgrade \
12+
git+https://github.com/pytoolz/toolz \
13+
git+https://github.com/dateutil/dateutil

ci/requirements/environment.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: xarray-safe-s1-tests
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.10
5+
- python
66
# development
77
- ipython
88
- pre-commit
@@ -14,6 +14,7 @@ dependencies:
1414
# testing
1515
- pytest
1616
- pytest-reportlog
17+
- pytest-cov
1718
- hypothesis
1819
- coverage
1920
# I/O
@@ -29,12 +30,9 @@ dependencies:
2930
- numpy
3031
- pandas
3132
- shapely
32-
- datetime
3333
- geopandas
3434
- affine
3535
- pyproj
3636
# processing
37-
- os
38-
- io
3937
- lxml
4038
- jmespath

docs/api.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ API reference
88

99
.. autoclass:: Sentinel1Reader
1010
:members:
11-

docs/conf.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1717
# ones.
1818
extensions = [
19-
'sphinx.ext.autosummary',
20-
'sphinx.ext.autodoc',
19+
"sphinx.ext.autosummary",
20+
"sphinx.ext.autodoc",
2121
"myst_parser",
2222
"sphinx.ext.extlinks",
2323
"sphinx.ext.intersphinx",
2424
"IPython.sphinxext.ipython_directive",
2525
"IPython.sphinxext.ipython_console_highlighting",
26-
'nbsphinx',
27-
'jupyter_sphinx',
28-
'sphinx.ext.napoleon'
26+
"nbsphinx",
27+
"jupyter_sphinx",
28+
"sphinx.ext.napoleon",
2929
]
3030

3131
extlinks = {
@@ -36,9 +36,9 @@
3636
# Add any paths that contain templates here, relative to this directory.
3737
templates_path = ["_templates"]
3838

39-
html_static_path = ['_static']
39+
html_static_path = ["_static"]
4040

41-
html_style = 'css/xsar.css'
41+
html_style = "css/xsar.css"
4242

4343
# List of patterns, relative to source directory, that match files and
4444
# directories to ignore when looking for source files.
@@ -84,21 +84,21 @@
8484
"dask": ("https://docs.dask.org/en/latest", None),
8585
"xarray": ("https://docs.xarray.dev/en/latest/", None),
8686
"rasterio": ("https://rasterio.readthedocs.io/en/latest/", None),
87-
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None)
87+
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
8888
}
8989

9090
html_theme_options = {
91-
'navigation_depth': 4, # FIXME: doesn't work as expeted: should expand side menu
92-
'collapse_navigation': False # FIXME: same as above
91+
"navigation_depth": 4, # FIXME: doesn't work as expeted: should expand side menu
92+
"collapse_navigation": False, # FIXME: same as above
9393
}
9494

9595
# If true, links to the reST sources are added to the pages.
9696
html_show_sourcelink = False
9797

9898
nbsphinx_allow_errors = False
9999

100-
nbsphinx_execute = 'always'
100+
nbsphinx_execute = "always"
101101

102102
nbsphinx_timeout = 300
103103

104-
today_fmt = '%b %d %Y at %H:%M'
104+
today_fmt = "%b %d %Y at %H:%M"

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ Last documentation build: |today|
7979
.. _xarray.Dataset: http://xarray.pydata.org/en/stable/generated/xarray.Dataset.html
8080
.. _`recommended installation`: installing.rst#recommended-packages
8181
.. _SAFE format: https://sentinel.esa.int/web/sentinel/user-guides/sentinel-1-sar/data-formats
82-
.. _jupyter notebook: https://jupyter.readthedocs.io/en/latest/running.html#running
82+
.. _jupyter notebook: https://jupyter.readthedocs.io/en/latest/running.html#running

docs/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ Pytest configuration
4545
Pytest uses a default configuration file (`config.yml`) in which we can found products paths to test.
4646
This configuration can be superseded by adding a local config file on the home directory :
4747
(`~/xarray-safe-s1/localconfig.yml`).
48-
In this file, testing files can be listed in the var `product_paths`.
48+
In this file, testing files can be listed in the var `product_paths`.

pyproject.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,36 @@ skip_gitignore = true
3737
float_to_top = true
3838
default_section = "THIRDPARTY"
3939
known_first_party = "safe_s1"
40+
41+
[tool.coverage.report]
42+
show_missing = true
43+
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"]
44+
45+
[tool.ruff.lint]
46+
ignore = [
47+
"E402", # module level import not at top of file
48+
"E501", # line too long - let black worry about that
49+
"E731", # do not assign a lambda expression, use a def
50+
"UP038", # type union instead of tuple for isinstance etc
51+
]
52+
select = [
53+
"F", # Pyflakes
54+
"E", # Pycodestyle
55+
"I", # isort
56+
"UP", # Pyupgrade
57+
"TID", # flake8-tidy-imports
58+
"W",
59+
]
60+
extend-safe-fixes = [
61+
"TID252", # absolute imports
62+
"UP031", # percent string interpolation
63+
]
64+
fixable = ["I", "TID252", "UP"]
65+
66+
[tool.ruff.lint.isort]
67+
known-first-party = ["safe_s1"]
68+
known-third-party = ["xarray", "toolz", "construct"]
69+
70+
[tool.ruff.lint.flake8-tidy-imports]
71+
# Disallow all relative imports.
72+
ban-relative-imports = "all"

safe_s1/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import traceback
2-
#import safe_s1
32
from safe_s1.reader import Sentinel1Reader
3+
44
try:
55
from importlib import metadata
6-
except ImportError: # for Python<3.8
6+
except ImportError: # for Python<3.8
77
import importlib_metadata as metadata
8-
try:
8+
try:
99
__version__ = metadata.version("xarray-safe-s1")
1010
except Exception:
11-
print('trace',traceback.format_exc())
11+
print("trace", traceback.format_exc())
1212
__version__ = "999"

safe_s1/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# default data paths for tests
22
product_paths:
3-
- 'S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE'
3+
- "S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE"

0 commit comments

Comments
 (0)