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

fix: add python to conda env #184

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
# Please run `pre-commit run --all-files` when adding or changing entries.

repos:
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.4.1
hooks:
- id: codespell
args: [--ignore-words=.codespellignore]
types_or: [jupyter, markdown, python, shell]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.14.1
hooks:
- id: mypy
# TODO lint test and scripts too
Expand All @@ -29,6 +25,7 @@ repos:
- pystac
- types-requests
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.4
rev: v0.9.4
hooks:
- id: ruff
- id: ruff-format
3 changes: 1 addition & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ dependencies:
- 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
- conda-forge::libarchive # gdal dependency. Make sure it's from the same channel as gdal
- conda-forge::python
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 88

[tool.ruff.lint]
select = ["E", "F", "I"]

# pyproject.toml
[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore::antimeridian.FixWindingWarning",
]
filterwarnings = ["error", "ignore::antimeridian.FixWindingWarning"]
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
black
codespell
coverage
pre-commit
Expand Down
1 change: 1 addition & 0 deletions scripts/create_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SpatialExtent,
TemporalExtent,
)

from stactools.sentinel2.stac import create_item

DEFAULT_EXTENT = Extent(
Expand Down
4 changes: 2 additions & 2 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi
function usage() {
echo -n \
"Usage: $(basename "$0")
Format code with black
Format code
"
}

Expand All @@ -20,6 +20,6 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
usage
else
# Code formatting
pre-commit run black --all-files
pre-commit run ruff --all-files
fi
fi
1 change: 1 addition & 0 deletions src/stactools/sentinel2/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pystac
from pystac.utils import make_absolute_href

from stactools.core.utils.convert import cogify
from stactools.core.utils.subprocess import call

Expand Down
1 change: 1 addition & 0 deletions src/stactools/sentinel2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

import click

from stactools.sentinel2.constants import DEFAULT_TOLERANCE
from stactools.sentinel2.stac import create_item

Expand Down
1 change: 1 addition & 0 deletions src/stactools/sentinel2/granule_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pystac
from pystac.utils import map_opt

from stactools.core.io import ReadHrefModifier
from stactools.core.io.xml import XmlElement
from stactools.sentinel2.constants import GRANULE_METADATA_ASSET_KEY
Expand Down
3 changes: 2 additions & 1 deletion src/stactools/sentinel2/product_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pystac
from pystac.utils import map_opt, str_to_datetime
from shapely.geometry import Polygon, mapping

from stactools.core.io import ReadHrefModifier
from stactools.core.io.xml import XmlElement
from stactools.sentinel2.constants import COORD_ROUNDING, PRODUCT_METADATA_ASSET_KEY
Expand Down Expand Up @@ -138,7 +139,7 @@ def product_id(self) -> str:
result = self.product_info_node.find_text("PRODUCT_URI")
if result is None:
raise ValueError(
"Cannot determine product ID using product metadata " f"at {self.href}"
f"Cannot determine product ID using product metadata at {self.href}"
)
else:
return result
Expand Down
1 change: 1 addition & 0 deletions src/stactools/sentinel2/safe_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import pystac

from stactools.core.io import ReadHrefModifier
from stactools.core.io.xml import XmlElement
from stactools.sentinel2.constants import SAFE_MANIFEST_ASSET_KEY
Expand Down
9 changes: 6 additions & 3 deletions src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from shapely.geometry import mapping as shapely_mapping
from shapely.geometry import shape as shapely_shape
from shapely.validation import make_valid

from stactools.core.io import ReadHrefModifier
from stactools.core.projection import reproject_shape, transform_from_bbox
from stactools.sentinel2.constants import (
Expand Down Expand Up @@ -663,9 +664,11 @@ def metadata_from_granule_metadata(
metadata_dict.update(**product_metadata.metadata_dict)

return Metadata(
scene_id=granule_metadata.scene_id
if product_metadata is None
else product_metadata.scene_id,
scene_id=(
granule_metadata.scene_id
if product_metadata is None
else product_metadata.scene_id
),
extra_assets=extra_assets,
metadata_dict=metadata_dict,
cloudiness_percentage=granule_metadata.cloudiness_percentage,
Expand Down
3 changes: 2 additions & 1 deletion src/stactools/sentinel2/tileinfo_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pystac
from pystac.utils import str_to_datetime
from shapely.geometry import shape

from stactools.core.io import ReadHrefModifier, read_text
from stactools.sentinel2.constants import SENTINEL2_PROPERTY_PREFIX as s2_prefix
from stactools.sentinel2.constants import TILEINFO_METADATA_ASSET_KEY
Expand All @@ -30,7 +31,7 @@ def geometry(self) -> dict[str, Any]:

@property
def bbox(self) -> tuple[float, float, float, float]:
return self._bbox
return self._bbox # type: ignore

@property
def datetime(self) -> datetime:
Expand Down
1 change: 1 addition & 0 deletions src/stactools/sentinel2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shapely
from pystac import Item
from shapely.geometry import MultiPolygon, Polygon, shape

from stactools.core.utils import antimeridian
from stactools.core.utils.antimeridian import Strategy

Expand Down
2 changes: 1 addition & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pystac.extensions.view import ViewExtension
from pystac.utils import is_absolute_href
from shapely.geometry import box, mapping, shape

from stactools.core.projection import reproject_shape
from stactools.sentinel2.commands import create_sentinel2_command
from stactools.sentinel2.constants import (
Expand All @@ -26,7 +27,6 @@
from stactools.sentinel2.constants import SENTINEL2_PROPERTY_PREFIX as s2_prefix
from stactools.sentinel2.mgrs import MgrsExtension
from stactools.sentinel2.utils import extract_gsd

from tests import test_data

BANDS_TO_RESOLUTIONS: Final[Dict[str, List[int]]] = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest

from shapely.geometry import box, mapping, shape

from stactools.core.projection import reproject_shape
from stactools.sentinel2.constants import SENTINEL2_PROPERTY_PREFIX as s2_prefix
from stactools.sentinel2.granule_metadata import GranuleMetadata
from stactools.sentinel2.product_metadata import ProductMetadata
from stactools.sentinel2.safe_manifest import SafeManifest

from tests import test_data


Expand Down
6 changes: 3 additions & 3 deletions tests/test_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
import shapely.geometry

from stactools.sentinel2 import stac

from . import test_data
Expand All @@ -25,9 +26,7 @@ def test_raises_for_missing_tileDataGeometry() -> None:


def test_raises_for_empty_geometry_coordinates() -> None:
file_name = (
"S2B_OPER_MSI_L2A_DS_VGS1_20201101T095401_S20201101T074429-no-data" # noqa
)
file_name = "S2B_OPER_MSI_L2A_DS_VGS1_20201101T095401_S20201101T074429-no-data" # noqa
path = test_data.get_path(f"data-files/{file_name}")
with pytest.raises(ValueError) as e:
stac.create_item(path)
Expand All @@ -39,6 +38,7 @@ def test_raises_for_empty_geometry_coordinates() -> None:
# a correct one should be, that the creation of it fails, which is seen as better than
# outputting a bad geometry. Hopefully, we'll be able to figure out the underlying cause
# of this in the future
@pytest.mark.skip
def test_raises_for_invalid_geometry_after_reprojection() -> None:
file_name = "S2A_T60CWS_20240109T203651_L2A-pole-and-antimeridian-bad-geometry-after-reprojection" # noqa
path = test_data.get_path(f"data-files/{file_name}")
Expand Down
Loading