Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/template upgrade #23

Merged
Merged
19 changes: 16 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
.git
.github
.git/
.github/
.gitignore

build/
.mypy_cache/
.pytest_cache/
__pycache__/
*.pyc
*.egg-info/

CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
docker_env
README.md
README-template.md

docker_env

.coverage
coverage.xml
9 changes: 3 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ max-line-length = 100
# E127: flake8 reporting incorrect continuation line indent errors
# on multi-line and multi-level indents

# W503, W504: flake8 reports this as incorrect, and scripts/format_code
# changes code to it, so let format_code win.
# W503, W504: flake8 reports this as incorrect, but black changes
# code to it, so let black win.

# E126: Continuation line over-indented for hanging indent
# Conflicts with yapf formatting

ignore = E127,W503,W504,E126
ignore = E127,W503,W504
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Please explain the changes you made here.
- [ ] Code lints properly (run `scripts/lint`).
- [ ] Tests pass (run `scripts/test`).
- [ ] Documentation has been updated to reflect changes, if applicable.
- [ ] Examples have been updated to reflect changes, if applicable
- [ ] Changes are added to the [CHANGELOG](../CHANGELOG.md).
20 changes: 7 additions & 13 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.8", "3.9", "3.10"]
defaults:
run:
shell: bash -l {0}
Expand Down Expand Up @@ -70,11 +70,9 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: "3.x"
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
-
name: Login to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
Expand All @@ -92,17 +90,15 @@ jobs:
echo "stactools_version=$STACTOOLS_VERSION" >> $GITHUB_ENV
echo "docker_workdir=$DOCKER_WORKDIR" >> $GITHUB_ENV
echo "docker_namespace_package_dir=$DOCKER_NAMESPACE_PACKAGE_DIR" >> $GITHUB_ENV
-
name: Docker meta main
- name: Docker meta main
id: meta-main
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
-
name: Build and push main
- name: Build and push main
uses: docker/build-push-action@v2
with:
context: .
Expand All @@ -115,8 +111,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
tags: ${{ steps.meta-main.outputs.tags }}
labels: ${{ steps.meta-main.outputs.labels }}
-
name: Docker meta dev
- name: Docker meta dev
id: meta-dev
uses: docker/metadata-action@v3
with:
Expand All @@ -126,8 +121,7 @@ jobs:
tags: |
type=ref,event=branch
type=ref,event=pr
-
name: Build and push dev
- name: Build and push dev
uses: docker/build-push-action@v2
with:
context: .
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tests/data-files/external

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PULL_REQUEST_TEMPLATE.MD
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Configuration file for pre-commit (https://pre-commit.com/).
# Please run `pre-commit run --all-files` when adding or changing entries.

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
additional_dependencies:
- click != 8.1.0
- stactools
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.1
hooks:
- id: markdownlint
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project attempts to match the major and minor versions of [stactools](https://github.com/stac-utils/stactools) and increments the patch number as needed.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project attempts to match the major and minor versions of
[stactools](https://github.com/stac-utils/stactools) and increments the patch
number as needed.

## [Unreleased]

- Upgraded core linting and testing to latest from **stactools-template** (<https://github.com/stactools-packages/template/commit/8b15971a9f1fae7933b0e45aac8d59188daf5db5>)

## [0.3.0] - 2022-12-01

### Added
Expand All @@ -26,7 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Added `stac sentinel1 grd` subcommand
- `stac sentinel1 create-item` now required subcommand `grd` or `rtc`
- Support for Microsoft Azure storage: similar format to SAFE, without `.SAFE` ending to the folders and slightly different file names.
- Support for Microsoft Azure storage: similar format to SAFE,\
without `.SAFE` ending to the folders and slightly different file names.

## [0.1.0] - 2021-09-04

Expand Down
5 changes: 3 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ WORKDIR $DOCKER_WORKDIR
# For caching purposes, install dependencies but remove the actual package
COPY pyproject.toml setup.cfg ./
COPY src/$DOCKER_NAMESPACE_PACKAGE_DIR/__init__.py src/$DOCKER_NAMESPACE_PACKAGE_DIR/
RUN pip install . \
RUN pip install . --no-binary rasterio \
&& rm -r /opt/conda/lib/python$PYTHON_VERSION/site-packages/$DOCKER_NAMESPACE_PACKAGE_DIR

COPY src ./src
RUN pip install .
RUN git init
RUN pip install . --no-binary rasterio
9 changes: 7 additions & 2 deletions docker/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ ARG DOCKER_WORKDIR
ENV PYTHON_VERSION=3.9
WORKDIR $DOCKER_WORKDIR

RUN apt-get -y -q update \
&& apt-get -y -q install build-essential \
&& rm -rf /var/lib/apt/lists/

# For caching purposes, install dependencies but remove the actual package
COPY pyproject.toml requirements-dev.txt setup.cfg ./
COPY src/$DOCKER_NAMESPACE_PACKAGE_DIR/__init__.py src/$DOCKER_NAMESPACE_PACKAGE_DIR/
RUN pip install -r requirements-dev.txt \
&& pip install . \
&& pip install . --no-binary rasterio \
&& rm -r /opt/conda/lib/python$PYTHON_VERSION/site-packages/$DOCKER_NAMESPACE_PACKAGE_DIR

COPY . ./
RUN pip install -e .
RUN git init
RUN pip install -e . --no-binary rasterio
6 changes: 4 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ name: stactools-sentinel1
channels:
- conda-forge
dependencies:
- gdal
- rasterio
- conda-forge::gdal>=3.3
- conda-forge::geos>=3.3
- conda-forge::rasterio>=1.3
- conda-forge::libstdcxx-ng # gdal dependency. Make sure it's from the same channel as gdal
34 changes: 18 additions & 16 deletions examples/generate_example.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
#!/usr/bin/env python3
'''
"""
Generate example STAC from test data
'''
"""
import pystac

from stactools.sentinel1 import stac
from stactools.sentinel1.rtc import stac

catalog = pystac.Catalog(id='sentinel1-rtc-example',
description='Example Catalog: Analysis Ready Sentinel-1 Backscatter Imagery AWS Public Dataset',
title="Sentinel-1 RTC AWS Open Data",
catalog_type=pystac.CatalogType.RELATIVE_PUBLISHED)
catalog = pystac.Catalog(
id="sentinel1-rtc-example",
description="Example Catalog: Analysis Ready Sentinel-1 Backscatter Imagery AWS Public Dataset",
title="Sentinel-1 RTC AWS Open Data",
catalog_type=pystac.CatalogType.RELATIVE_PUBLISHED,
)

collection = stac.create_collection()

base_href = 'https://sentinel-s1-rtc-indigo.s3.us-west-2.amazonaws.com'
key = 'tiles/RTC/1/IW/17/R/MJ/2020/S1A_20200103_17RMJ_ASC'
item1 = stac.create_item(f'{base_href}/{key}')
base_href = "https://sentinel-s1-rtc-indigo.s3.us-west-2.amazonaws.com"
key = "tiles/RTC/1/IW/17/R/MJ/2020/S1A_20200103_17RMJ_ASC"
item1 = stac.create_item(f"{base_href}/{key}")

key = 'tiles/RTC/1/IW/12/S/YJ/2016/S1B_20161121_12SYJ_ASC'
item2 = stac.create_item(f'{base_href}/{key}')
key = "tiles/RTC/1/IW/12/S/YJ/2016/S1B_20161121_12SYJ_ASC"
item2 = stac.create_item(f"{base_href}/{key}")

collection.add_items([item1, item2])

catalog.add_child(collection)
catalog.generate_subcatalogs(template='${year}')
catalog.generate_subcatalogs(template="${year}")

catalog.normalize_hrefs('./')
catalog.normalize_hrefs("./")
# NOTE: can simplify after https://github.com/stac-utils/pystac/pull/565/files
#published_root_url = 'https://raw.githubusercontent.com/stactools-packages/sentinel1/main/examples/catalog.json'
#catalog.set_self_href(published_root_url) # !!! manually change after saving !!!
# published_root_url = 'https://raw.githubusercontent.com/stactools-packages/sentinel1/main/examples/catalog.json' # noqa: E501
# catalog.set_self_href(published_root_url) # !!! manually change after saving !!!
catalog.validate_all()
catalog.save()
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mypy_path = src
explicit_package_bases = True
namespace_packages = True
show_error_codes = True
strict = True

[mypy-rasterio.*]
ignore_missing_imports = True
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
17 changes: 4 additions & 13 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
black
codespell
coverage
editorconfig-checker==2.3.*
flake8
isort
jupyter
mypy
pylint
sphinx
sphinx-autobuild
sphinx-click
sphinxcontrib-fulltoc
sphinxcontrib-napoleon
toml
types-click
types-pytz
yapf
pre-commit
pytest
pytest-cov
8 changes: 3 additions & 5 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ fi
function usage() {
echo -n \
"Usage: $(basename "$0")
Format code with yapf
Format code with black and isort
"
}

DIRS_TO_CHECK=("src" "tests" "scripts")

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
# Sort imports
isort --overwrite-in-place .
pre-commit run isort --all-files
# Code formatting
yapf -ipr ${DIRS_TO_CHECK[@]}
pre-commit run black --all-files
fi
fi
14 changes: 2 additions & 12 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ Execute project linters.
"
}

EC_EXCLUDE="(__pycache__|.git|.coverage|coverage.xml|.*\.egg-info|.mypy_cache|.tif|.tiff|.npy)"

DIRS_TO_CHECK=("src" "tests" "scripts")

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
# Text formatting
ec --exclude "$EC_EXCLUDE"
# Sort imports
isort --check .
# Code formatting
yapf -dpr ${DIRS_TO_CHECK[@]}
# Lint
flake8 ${DIRS_TO_CHECK[@]}
pre-commit run flake8 --all-files
# Type checking
mypy src
pre-commit run mypy --all-files
fi
fi
2 changes: 1 addition & 1 deletion scripts/publish
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi
function usage() {
echo -n \
"Usage: $(basename "$0")
Publish all stactools packages.
Publish this stactools package.

Options:
--test Publish to test pypi
Expand Down
13 changes: 9 additions & 4 deletions scripts/stactools-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

# Filter out entries that don't start with 'stactools ' or 'stactools['.
# Split the entry on whitespace and select the last item which should be the version.
version = [
req for req in conf_dict['options']['install_requires']
if req.startswith('stactools ') or req.startswith('stactools[')
][0].split().pop()
version = (
[
req
for req in conf_dict["options"]["install_requires"]
if req.startswith("stactools ") or req.startswith("stactools[")
][0]
.split()
.pop()
)

print(version)
Loading