diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..9d1e098 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,5 @@ +changelog: + exclude: + authors: + - dependabot + - pre-commit-ci diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..c168fd2 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,84 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + detect-skip-ci-trigger: + name: "Detect CI Trigger: [skip-ci]" + if: | + github.repository == 'umr-lops/xsar' + && ( + github.event_name == 'push' || github.event_name == 'pull_request' + ) + runs-on: ubuntu-latest + outputs: + triggered: ${{ steps.detect-trigger.outputs.trigger-found }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - uses: xarray-contrib/ci-trigger@v1 + id: detect-trigger + with: + keyword: "[skip-ci]" + + ci: + name: ${{ matrix.os }} py${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + needs: detect-skip-ci-trigger + + if: needs.detect-skip-ci-trigger.outputs.triggered == 'false' + + defaults: + run: + shell: bash -l {0} + + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12"] + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + with: + # need to fetch all tags to get a correct version + fetch-depth: 0 # fetch all branches and tags + + - name: Setup environment variables + run: | + echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + + echo "CONDA_ENV_FILE=ci/requirements/environment.yaml" >> $GITHUB_ENV + + - name: Setup micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ${{ env.CONDA_ENV_FILE }} + environment-name: xsar-tests + cache-environment: true + cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{matrix.python-version}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" + create-args: >- + python=${{matrix.python-version}} + + - name: Install xsar + run: | + python -m pip install --no-deps -e . + + - name: Import xsar + run: | + python -c "import xsar" + + - name: Run tests + run: | + python -m pytest --cov=xsar diff --git a/.github/workflows/upstream-dev.yaml b/.github/workflows/upstream-dev.yaml new file mode 100644 index 0000000..68ba1ad --- /dev/null +++ b/.github/workflows/upstream-dev.yaml @@ -0,0 +1,98 @@ +name: upstream-dev CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "0 18 * * 0" # Weekly "On Sundays at 18:00" UTC + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + detect-test-upstream-trigger: + name: "Detect CI Trigger: [test-upstream]" + if: github.event_name == 'push' || github.event_name == 'pull_request' + runs-on: ubuntu-latest + outputs: + triggered: ${{ steps.detect-trigger.outputs.trigger-found }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - uses: xarray-contrib/ci-trigger@v1.2 + id: detect-trigger + with: + keyword: "[test-upstream]" + + upstream-dev: + name: upstream-dev + runs-on: ubuntu-latest + needs: detect-test-upstream-trigger + + if: | + always() + && github.repository == 'umr-lops/xsar' + && ( + github.event_name == 'schedule' + || github.event_name == 'workflow_dispatch' + || needs.detect-test-upstream-trigger.outputs.triggered == 'true' + || contains(github.event.pull_request.labels.*.name, 'run-upstream') + ) + + defaults: + run: + shell: bash -l {0} + + strategy: + fail-fast: false + matrix: + python-version: ["3.12"] + + steps: + - name: checkout the repository + uses: actions/checkout@v4 + with: + # need to fetch all tags to get a correct version + fetch-depth: 0 # fetch all branches and tags + + - name: set up conda environment + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: ci/requirements/environment.yaml + environment-name: tests + create-args: >- + python=${{ matrix.python-version }} + pytest-reportlog + + - name: install upstream-dev dependencies + run: bash ci/install-upstream-dev.sh + + - name: install the package + run: python -m pip install --no-deps -e . + + - name: show versions + run: python -m pip list + + - name: import + run: | + python -c 'import xsar' + + - name: run tests + if: success() + id: status + run: | + python -m pytest -rf --report-log=pytest-log.jsonl + + - name: report failures + if: | + failure() + && steps.tests.outcome == 'failure' + && github.event_name == 'schedule' + uses: xarray-contrib/issue-from-pytest-log@v1 + with: + log-path: pytest-log.jsonl diff --git a/ci/install-upstream-dev.sh b/ci/install-upstream-dev.sh new file mode 100644 index 0000000..c56948c --- /dev/null +++ b/ci/install-upstream-dev.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +conda remove -y --force cytoolz numpy xarray toolz python-dateutil pandas +python -m pip install \ + -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ + --no-deps \ + --pre \ + --upgrade \ + numpy \ + pandas \ + xarray +python -m pip install --upgrade \ + git+https://github.com/pytoolz/toolz \ + git+https://github.com/dateutil/dateutil diff --git a/ci/requirements/docs.yaml b/ci/requirements/docs.yaml new file mode 100644 index 0000000..4ca8ee3 --- /dev/null +++ b/ci/requirements/docs.yaml @@ -0,0 +1,8 @@ +name: xsar-docs +channels: + - conda-forge +dependencies: + - python=3.11 + - sphinx>=4 + - sphinx_book_theme + - ipython diff --git a/ci/requirements/environment.yaml b/ci/requirements/environment.yaml new file mode 100644 index 0000000..ec381cd --- /dev/null +++ b/ci/requirements/environment.yaml @@ -0,0 +1,19 @@ +name: xsar-tests +channels: + - conda-forge +dependencies: + - ipython + - pre-commit + - pytest + - pytest-reportlog + - pytest-cov + - numpy + - toolz + - cytoolz + - python-dateutil + - construct + - fsspec + - xarray + - dask + - distributed + - aiohttp diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..02110c2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,98 @@ +[project] +name = "xsar" +requires-python = ">= 3.10" +license = { text = "MIT" } +authors = [ + { name = "Olivier Archer", email = "olivier.archer@ifremer.fr" }, +] +description = "Python xarray library to use Level-1 GRD Synthetic Aperture Radar products" +readme = "README.md" +keywords = [ + "xarray", + "earth-observation", + "remote-sensing", + "satellite-imagery", + "Sentinel-1", + "RCM", + "RadarSat2", + "sar", + "synthetic-aperture-radar", +] +classifiers = [ + "Development Status :: 4 - Beta", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering", +] +dynamic = ["version"] +dependencies = [ + 'GDAL', + 'dask[array]', + 'distributed', + "xarray>=2024.10.0", + 'affine', + 'rasterio', + 'cartopy', + 'fiona', + 'pyproj', + 'numpy', + 'scipy', + 'shapely', + 'geopandas', + 'fsspec', + 'aiohttp', + 'pytz', + 'psutil', + 'jinja2', + 'rioxarray', + 'lxml', +] +[project.optional-dependencies] +RS2 = ["xradarsat2"] +RCM = ["xarray-safe-rcm"] +S1 = ["xarray-safe-s1"] + + + +[project.urls] +homepage = "https://github.com/umr-lops/xsar.readthedocs.io" +documentation = "https://xsar.readthedocs.io" +repository = "https://github.com/umr-lops/xsar" +changelog = "https://xsar.readthedocs.io/en/latest/changelog.html" + +[project.scripts] +#xsar = "xsar.xarray_backends:XsarXarrayBackend" + +[build-system] +requires = ["setuptools>=64.0", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["xsar"] +package-dir = {"" = "src"} + +[tool.setuptools_scm] +fallback_version = "999" + +[tool.isort] +profile = "black" +skip_gitignore = true +float_to_top = true +default_section = "THIRDPARTY" +known_first_party = "xsar" + +[tool.black] +line-length = 100 + +[tool.coverage.run] +source = ["xsar"] +branch = true + +[tool.coverage.report] +show_missing = true +exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 7b5bc0f..0000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -from setuptools import setup, find_packages -import glob - -setup( - name='xsar', - package_dir={'': 'src'}, - packages=find_packages('src'), - scripts=glob.glob('src/scripts/*.py'), - url='https://github.com/umr-lops/xsar', - use_scm_version=True, - setup_requires=['setuptools_scm'], - include_package_data=True, - install_requires=[ - 'GDAL', - 'dask[array]', - 'distributed', - "xarray>=2024.10.0", - 'affine', - 'rasterio', - 'cartopy', - 'fiona', - 'pyproj', - 'numpy', - 'scipy', - 'shapely', - 'geopandas', - 'fsspec', - 'aiohttp', - 'pytz', - 'psutil', - 'jinja2', - 'rioxarray', - 'lxml' - ], - extras_require={ - "RS2": ["xradarsat2"], - "RCM": ["xarray-safe-rcm"], - "S1": ["xarray-safe-s1"] - }, - entry_points={ - "xarray.backends": ["xsar=xsar.xarray_backends:XsarXarrayBackend"] - }, - license='MIT', - author='Olivier Archer, Alexandre Levieux, Antoine Grouazel', - author_email='Olivier.Archer@ifremer.fr, Alexandre.Levieux@gmail.com, Antoine.Grouazel@ifremer.fr', - description='xarray L1 SAR mapper', - summary='Python xarray library to use Level-1 GRD SAR products', - long_description_content_type='text/x-rst', - long_description = 'Python xarray library to use Level-1 GRD Synthetic Aperture Radar products' -) diff --git a/src/xsar/__init__.py b/src/xsar/__init__.py index 5e72da5..c5071db 100644 --- a/src/xsar/__init__.py +++ b/src/xsar/__init__.py @@ -21,3 +21,14 @@ from xsar.base_dataset import BaseDataset from xsar.base_meta import BaseMeta from xsar.xsar import open_dataset,open_datatree,product_info + + +import xsar +try: + from importlib import metadata +except ImportError: # for Python<3.8 + import importlib_metadata as metadata +try: + __version__ = metadata.version("xsar") +except Exception: + __version__ = "999"