Skip to content

Commit

Permalink
Merge branch 'main' into 4-switch-from-cloudpathlib-to-universal_pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-braun committed Dec 13, 2024
2 parents 118cad1 + 646e796 commit 938b657
Show file tree
Hide file tree
Showing 52 changed files with 550 additions and 676 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

5 changes: 3 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ lint:
stage: lint
script:
- python -m pip install --upgrade pip
- pip install flake8
- flake8 .
- pip install ruff
- ruff format
- ruff check
except:
- tags

Expand Down
21 changes: 8 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ repos:
- id: debug-statements
- id: check-merge-conflict

- repo: 'https://github.com/PyCQA/flake8'
rev: 7.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.3
hooks:
- id: flake8

- repo: 'https://github.com/psf/black'
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
6 changes: 0 additions & 6 deletions .pypirc

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.44.x (20xx-xx-xx)

- **ENH: Drop `isort`, `black` and `flake8` and use `ruff`**
- **ENH: Use `pyproject.toml` instead of `setup.py`**
- FIX: Fix too broad exception in case of `geopandas >= 1.0`

## 1.44.1 (2024-12-12)

- OPTIM: Don't download an archive stored on the cloud when trying to read a vector stored inside it in `vectors.read`
Expand Down
2 changes: 1 addition & 1 deletion CI/SCRIPTS/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
""" CI tests """
"""CI tests"""
3 changes: 1 addition & 2 deletions CI/SCRIPTS/script_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand Down Expand Up @@ -118,4 +117,4 @@ def xml_path():


def s3_env(*args, **kwargs):
return unistra.s3_env(use_s3_env_var=CI_SERTIT_S3, *args, **kwargs)
return unistra.s3_env(use_s3_env_var=CI_SERTIT_S3, *args, **kwargs) # noqa: B026
3 changes: 2 additions & 1 deletion CI/SCRIPTS/test_arcpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the arcpy module """
"""Script testing the arcpy module"""

from sertit import arcpy, ci

ci.reduce_verbosity()
Expand Down
4 changes: 2 additions & 2 deletions CI/SCRIPTS/test_ci.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the CI """
"""Script testing the CI"""

import os
import tempfile

Expand Down
3 changes: 1 addition & 2 deletions CI/SCRIPTS/test_display.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing SNAP functions """
"""Script testing SNAP functions"""

import numpy as np

Expand Down
9 changes: 3 additions & 6 deletions CI/SCRIPTS/test_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the files """
"""Script testing the files"""

import os
import shutil
import tempfile
Expand Down Expand Up @@ -75,10 +75,7 @@ def test_archive():
files.remove(out)

# Add to zip
if path.is_cloud_path(zip2_file):
zip_out = zip2_file
else:
zip_out = archive_base + ".zip"
zip_out = zip2_file if path.is_cloud_path(zip2_file) else archive_base + ".zip"
core_copy = files.copy(core_dir, os.path.join(tmp_dir, "core2"))
zip_out = files.add_to_zip(zip_out, core_copy)

Expand Down
3 changes: 1 addition & 2 deletions CI/SCRIPTS/test_geometry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing vector functions """
"""Script testing vector functions"""

from CI.SCRIPTS.script_utils import KAPUT_KWARGS, geometry_path, s3_env, vectors_path
from sertit import ci, geometry, vectors
Expand Down
4 changes: 2 additions & 2 deletions CI/SCRIPTS/test_logs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the logs """
"""Script testing the logs"""

import logging
import os
import sys
Expand Down
4 changes: 2 additions & 2 deletions CI/SCRIPTS/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the miscellaneous functions """
"""Script testing the miscellaneous functions"""

import os

import pytest
Expand Down
6 changes: 3 additions & 3 deletions CI/SCRIPTS/test_network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the network.control """
"""Script testing the network.control"""

import pytest

from sertit import ci, network
Expand All @@ -39,7 +39,7 @@ def network_request(self):
def test_network():
mocker = NetworkRequestMocker(5)

with pytest.raises(Exception):
with pytest.raises(Exception): # noqa: B017
mocker.network_request() # Must raise

with pytest.raises(TimeoutError):
Expand Down
6 changes: 3 additions & 3 deletions CI/SCRIPTS/test_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the files """
"""Script testing the files"""

import os
import shutil
import tempfile
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_get_file_name():
r"/test/S3B_SL_1_RBT____20200909T104016_0179_043_165_2340_LN2_O_NT_004.SEN3.zip"
)
file_name = path.get_filename(fn)
assert "S3B_SL_1_RBT____20200909T104016_0179_043_165_2340_LN2_O_NT_004" == file_name
assert file_name == "S3B_SL_1_RBT____20200909T104016_0179_043_165_2340_LN2_O_NT_004"

fn = r"/test/S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432.SAFE.zip"
file_name = path.get_filename(fn)
Expand Down
4 changes: 2 additions & 2 deletions CI/SCRIPTS/test_rasters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing raster functions (with XARRAY) """
"""Script testing raster functions (with XARRAY)"""

import logging
import os
import shutil
Expand Down
37 changes: 18 additions & 19 deletions CI/SCRIPTS/test_rasters_rio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing raster function (with rasterio) """
"""Script testing raster function (with rasterio)"""

import os
import shutil

Expand Down Expand Up @@ -354,27 +354,26 @@ def test_reproj(tmp_path, raster_path):
)
reproj_path = rasters_path().joinpath("reproj_out.tif")

with rasterio.open(str(dem_path)) as src:
with rasterio.open(str(raster_path)) as ds:
dst_arr, dst_meta = rasters_rio.reproject_match(
ds.meta, src.read(), src.meta, **KAPUT_KWARGS
)
with rasterio.open(str(dem_path)) as src, rasterio.open(str(raster_path)) as ds:
dst_arr, dst_meta = rasters_rio.reproject_match(
ds.meta, src.read(), src.meta, **KAPUT_KWARGS
)

# from ds
assert ds.meta["driver"] == dst_meta["driver"]
assert ds.meta["width"] == dst_meta["width"]
assert ds.meta["height"] == dst_meta["height"]
assert ds.meta["transform"] == dst_meta["transform"]
# from ds
assert ds.meta["driver"] == dst_meta["driver"]
assert ds.meta["width"] == dst_meta["width"]
assert ds.meta["height"] == dst_meta["height"]
assert ds.meta["transform"] == dst_meta["transform"]

# from src
assert src.meta["count"] == dst_meta["count"]
assert src.meta["nodata"] == dst_meta["nodata"]
assert src.meta["dtype"] == dst_meta["dtype"]
# from src
assert src.meta["count"] == dst_meta["count"]
assert src.meta["nodata"] == dst_meta["nodata"]
assert src.meta["dtype"] == dst_meta["dtype"]

path_out = os.path.join(tmp_path, "out.tif")
rasters_rio.write(dst_arr, dst_meta, path_out)
path_out = os.path.join(tmp_path, "out.tif")
rasters_rio.write(dst_arr, dst_meta, path_out)

ci.assert_raster_almost_equal(path_out, reproj_path, decimal=4)
ci.assert_raster_almost_equal(path_out, reproj_path, decimal=4)


@s3_env
Expand Down
34 changes: 20 additions & 14 deletions CI/SCRIPTS/test_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing the CI """
"""Script testing the CI"""

import os

import pytest
Expand Down Expand Up @@ -69,11 +69,14 @@ def test_s3():


def test_no_sign_request():
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
}
), temp_s3(no_sign_request=True):
with (
tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.us-west-2.amazonaws.com",
}
),
temp_s3(no_sign_request=True),
):
path = AnyPath(
"s3://sentinel-cogs/sentinel-s2-l2a-cogs/40/V/DR/2023/11/S2A_40VDR_20231114_0_L2A"
)
Expand All @@ -83,13 +86,16 @@ def test_no_sign_request():


def test_requester_pays():
with tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.eu-central-1.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
), temp_s3(requester_pays=True):
with (
tempenv.TemporaryEnvironment(
{
"AWS_S3_ENDPOINT": "s3.eu-central-1.amazonaws.com",
"AWS_SECRET_ACCESS_KEY": os.getenv("AWS_S3_AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID": os.getenv("AWS_S3_AWS_ACCESS_KEY_ID"),
}
),
temp_s3(requester_pays=True),
):
path = AnyPath("s3://sentinel-s2-l1c/tiles/29/H/NA/2023/11/14/0/")
assert path.exists()
with rasterio.open(str(path / "B12.jp2")) as ds:
Expand Down
3 changes: 1 addition & 2 deletions CI/SCRIPTS/test_snap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing SNAP functions """
"""Script testing SNAP functions"""

import shutil

Expand Down
4 changes: 2 additions & 2 deletions CI/SCRIPTS/test_strings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2024, SERTIT-ICube - France, https://sertit.unistra.fr/
# This file is part of sertit-utils project
# https://github.com/sertit/sertit-utils
Expand All @@ -14,7 +13,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Script testing string functions """
"""Script testing string functions"""

import argparse
import logging
from datetime import date, datetime
Expand Down
Loading

0 comments on commit 938b657

Please sign in to comment.