rok4 2.2.0__tar.gz → 2.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {rok4-2.2.0 → rok4-2.2.4}/PKG-INFO +8 -5
  2. {rok4-2.2.0 → rok4-2.2.4}/README.md +1 -0
  3. {rok4-2.2.0 → rok4-2.2.4}/README.pypi.md +1 -0
  4. {rok4-2.2.0 → rok4-2.2.4}/pyproject.toml +5 -4
  5. rok4-2.2.4/src/rok4/__init__.py +1 -0
  6. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/enums.py +1 -1
  7. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/raster.py +4 -8
  8. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/storage.py +25 -7
  9. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/utils.py +1 -2
  10. {rok4-2.2.0 → rok4-2.2.4}/src/rok4.egg-info/PKG-INFO +8 -5
  11. {rok4-2.2.0 → rok4-2.2.4}/src/rok4.egg-info/requires.txt +1 -1
  12. {rok4-2.2.0 → rok4-2.2.4}/tests/test_raster.py +2 -2
  13. {rok4-2.2.0 → rok4-2.2.4}/tests/test_storage.py +54 -0
  14. {rok4-2.2.0 → rok4-2.2.4}/tests/test_tile_matrix_set.py +2 -3
  15. rok4-2.2.0/src/rok4/__init__.py +0 -1
  16. {rok4-2.2.0 → rok4-2.2.4}/LICENSE.txt +0 -0
  17. {rok4-2.2.0 → rok4-2.2.4}/setup.cfg +0 -0
  18. {rok4-2.2.0 → rok4-2.2.4}/setup.py +0 -0
  19. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/exceptions.py +0 -0
  20. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/layer.py +0 -0
  21. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/pyramid.py +0 -0
  22. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/style.py +0 -0
  23. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/tile_matrix_set.py +0 -0
  24. {rok4-2.2.0 → rok4-2.2.4}/src/rok4/vector.py +0 -0
  25. {rok4-2.2.0 → rok4-2.2.4}/src/rok4.egg-info/SOURCES.txt +0 -0
  26. {rok4-2.2.0 → rok4-2.2.4}/src/rok4.egg-info/dependency_links.txt +0 -0
  27. {rok4-2.2.0 → rok4-2.2.4}/src/rok4.egg-info/top_level.txt +0 -0
  28. {rok4-2.2.0 → rok4-2.2.4}/tests/test_layer.py +0 -0
  29. {rok4-2.2.0 → rok4-2.2.4}/tests/test_pyramid.py +0 -0
  30. {rok4-2.2.0 → rok4-2.2.4}/tests/test_style.py +0 -0
  31. {rok4-2.2.0 → rok4-2.2.4}/tests/test_utils.py +0 -0
  32. {rok4-2.2.0 → rok4-2.2.4}/tests/test_vector.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: rok4
3
- Version: 2.2.0
3
+ Version: 2.2.4
4
4
  Summary: Python core libraries for ROK4 project
5
5
  Author-email: Géoportail IGN Developers <tout_rdev@ign.fr>
6
6
  License:
@@ -530,10 +530,11 @@ Classifier: Development Status :: 3 - Alpha
530
530
  Classifier: Topic :: Software Development :: Libraries
531
531
  Classifier: License :: CeCILL-C Free Software License Agreement (CECILL-C)
532
532
  Classifier: Programming Language :: Python :: 3
533
- Classifier: Programming Language :: Python :: 3.8
534
- Classifier: Programming Language :: Python :: 3.9
535
533
  Classifier: Programming Language :: Python :: 3.10
536
534
  Classifier: Programming Language :: Python :: 3.11
535
+ Classifier: Programming Language :: Python :: 3.12
536
+ Classifier: Programming Language :: Python :: 3.13
537
+ Classifier: Programming Language :: Python :: 3.14
537
538
  Classifier: Programming Language :: Python :: 3 :: Only
538
539
  Requires-Python: >=3.8
539
540
  Description-Content-Type: text/markdown
@@ -548,11 +549,12 @@ Requires-Dist: pdoc3>=0.10.0; extra == "doc"
548
549
  Provides-Extra: dev
549
550
  Requires-Dist: black; extra == "dev"
550
551
  Requires-Dist: isort>=5.12.0; extra == "dev"
551
- Requires-Dist: pre-commit<4,>3; extra == "dev"
552
+ Requires-Dist: pre-commit<5,>3; extra == "dev"
552
553
  Requires-Dist: ruff>=0.0.281; extra == "dev"
553
554
  Provides-Extra: test
554
555
  Requires-Dist: pytest>=7.1.2; extra == "test"
555
556
  Requires-Dist: coverage>=7.0.5; extra == "test"
557
+ Dynamic: license-file
556
558
 
557
559
  # ROK4 Python libraries
558
560
 
@@ -591,6 +593,7 @@ Following environment variables could be used, by module :
591
593
  * `ROK4_S3_KEY` : Key(s) for S3 server(s)
592
594
  * `ROK4_S3_SECRETKEY` : Secret key(s) for S3 server(s)
593
595
  * `ROK4_S3_URL` : URL(s) for S3 server(s)
596
+ * `ROK4_S3_REGION` : Region(s) for S3 server(s)
594
597
  * `ROK4_SSL_NO_VERIFY` : Disable SSL conrols for S3 access (any non empty value)
595
598
  * `tile_matrix_set` :
596
599
  * `ROK4_TMS_DIRECTORY` : Root directory (file or object) for tile matrix sets
@@ -38,6 +38,7 @@ Les variables d'environnement suivantes peuvent être nécessaires, par module :
38
38
  * `ROK4_S3_KEY` : Clé(s) de(s) serveur(s) S3
39
39
  * `ROK4_S3_SECRETKEY` : Clé(s) secrète(s) de(s) serveur(s) S3
40
40
  * `ROK4_S3_URL` : URL de(s) serveur(s) S3
41
+ * `ROK4_S3_REGION` : Région de(s) serveur(s) S3
41
42
  * `ROK4_SSL_NO_VERIFY` : Désactivation de la vérification SSL pour les accès S3 (n'importe quelle valeur non vide)
42
43
  * `tile_matrix_set` :
43
44
  * `ROK4_TMS_DIRECTORY` : Dossier racine (fichier ou objet) des tile matrix sets
@@ -35,6 +35,7 @@ Following environment variables could be used, by module :
35
35
  * `ROK4_S3_KEY` : Key(s) for S3 server(s)
36
36
  * `ROK4_S3_SECRETKEY` : Secret key(s) for S3 server(s)
37
37
  * `ROK4_S3_URL` : URL(s) for S3 server(s)
38
+ * `ROK4_S3_REGION` : Region(s) for S3 server(s)
38
39
  * `ROK4_SSL_NO_VERIFY` : Disable SSL conrols for S3 access (any non empty value)
39
40
  * `tile_matrix_set` :
40
41
  * `ROK4_TMS_DIRECTORY` : Root directory (file or object) for tile matrix sets
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
 
3
3
  name = "rok4"
4
- version = "2.2.0"
4
+ version = "2.2.4"
5
5
 
6
6
  description = "Python core libraries for ROK4 project"
7
7
  readme = "README.pypi.md"
@@ -23,10 +23,11 @@ classifiers = [
23
23
  "License :: CeCILL-C Free Software License Agreement (CECILL-C)",
24
24
 
25
25
  "Programming Language :: Python :: 3",
26
- "Programming Language :: Python :: 3.8",
27
- "Programming Language :: Python :: 3.9",
28
26
  "Programming Language :: Python :: 3.10",
29
27
  "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: 3.14",
30
31
  "Programming Language :: Python :: 3 :: Only",
31
32
  ]
32
33
 
@@ -46,7 +47,7 @@ doc = [
46
47
  dev = [
47
48
  "black",
48
49
  "isort >= 5.12.0",
49
- "pre-commit >3,<4",
50
+ "pre-commit >3,<5",
50
51
  "ruff >= 0.0.281"
51
52
  ]
52
53
 
@@ -0,0 +1 @@
1
+ __version__ = "2.2.4"
@@ -1,4 +1,4 @@
1
- #! python3 # noqa: E265
1
+ #! python3
2
2
 
3
3
  # standard lib
4
4
  from enum import Enum
@@ -253,14 +253,10 @@ class RasterSet:
253
253
  if bbox == [None, None, None, None]:
254
254
  bbox = list(raster.bbox)
255
255
  else:
256
- if bbox[0] > raster.bbox[0]:
257
- bbox[0] = raster.bbox[0]
258
- if bbox[1] > raster.bbox[1]:
259
- bbox[1] = raster.bbox[1]
260
- if bbox[2] < raster.bbox[2]:
261
- bbox[2] = raster.bbox[2]
262
- if bbox[3] < raster.bbox[3]:
263
- bbox[3] = raster.bbox[3]
256
+ bbox[0] = min(bbox[0], raster.bbox[0])
257
+ bbox[1] = min(bbox[1], raster.bbox[1])
258
+ bbox[2] = max(bbox[2], raster.bbox[2])
259
+ bbox[3] = max(bbox[3], raster.bbox[3])
264
260
 
265
261
  # Inventaire des colors distinctes
266
262
  self.colors.add((raster.bands, raster.format))
@@ -28,6 +28,7 @@ Using S3 storage requires environment variables :
28
28
  - ROK4_S3_KEY
29
29
  - ROK4_S3_SECRETKEY
30
30
  - ROK4_S3_URL
31
+ - ROK4_S3_REGION (optional)
31
32
 
32
33
  To use several S3 clusters, each environment variable have to contain a list (comma-separated), with the same number of elements
33
34
 
@@ -36,6 +37,8 @@ Example, work with 2 S3 clusters:
36
37
  - ROK4_S3_KEY=KEY1,KEY2
37
38
  - ROK4_S3_SECRETKEY=SKEY1,SKEY2
38
39
  - ROK4_S3_URL=https://s3.storage.fr,https://s4.storage.fr
40
+ - ROK4_S3_REGION=region1,region2
41
+
39
42
 
40
43
  To precise the cluster to use, bucket name should be bucket_name@s3.storage.fr or bucket_name@s4.storage.fr. If no host is defined (no @) in the bucket name, first S3 cluster is used
41
44
  """
@@ -52,9 +55,21 @@ from typing import Dict, Tuple, Union
52
55
  import boto3
53
56
  import botocore.exceptions
54
57
  import requests
55
- from osgeo import gdal
56
58
 
57
59
  # conditional import
60
+
61
+ try:
62
+ from osgeo import gdal
63
+
64
+ # Enable GDAL/OGR exceptions
65
+ gdal.UseExceptions()
66
+
67
+ GDAL_AVAILABLE: bool = True
68
+ except ImportError:
69
+ GDAL_AVAILABLE: bool = False
70
+ gdal = None
71
+
72
+
58
73
  try:
59
74
  import rados
60
75
 
@@ -69,8 +84,6 @@ from rok4.exceptions import MissingEnvironmentError, StorageError
69
84
 
70
85
  # -- GLOBALS --
71
86
 
72
- # Enable GDAL/OGR exceptions
73
- gdal.UseExceptions()
74
87
 
75
88
  __CEPH_CLIENT = None
76
89
  __CEPH_IOCTXS = {}
@@ -91,8 +104,7 @@ except KeyError:
91
104
 
92
105
  try:
93
106
  __LRU_TTL = int(os.environ["ROK4_READING_LRU_CACHE_TTL"])
94
- if __LRU_TTL < 0:
95
- __LRU_TTL = 0
107
+ __LRU_TTL = max(__LRU_TTL, 0)
96
108
  except ValueError:
97
109
  pass
98
110
  except KeyError:
@@ -134,8 +146,13 @@ def __get_s3_client(bucket_name: str) -> Tuple[Dict[str, Union["boto3.client", s
134
146
  keys = os.environ["ROK4_S3_KEY"].split(",")
135
147
  secret_keys = os.environ["ROK4_S3_SECRETKEY"].split(",")
136
148
  urls = os.environ["ROK4_S3_URL"].split(",")
149
+ # ROK4_S3_REGION est optionnelle : None est utilisé pour les clusters sans région définie
150
+ if os.environ.get("ROK4_S3_REGION", "") != "":
151
+ regions = os.environ["ROK4_S3_REGION"].split(",")
152
+ else:
153
+ regions = [None] * len(keys)
137
154
 
138
- if len(keys) != len(secret_keys) or len(keys) != len(urls):
155
+ if len(keys) != len(secret_keys) or len(keys) != len(urls) or len(keys) != len(regions):
139
156
  raise StorageError(
140
157
  "S3",
141
158
  "S3 informations in environment variables are inconsistent : same number of element in each list is required",
@@ -154,6 +171,7 @@ def __get_s3_client(bucket_name: str) -> Tuple[Dict[str, Union["boto3.client", s
154
171
  aws_secret_access_key=secret_keys[i],
155
172
  verify=verify,
156
173
  endpoint_url=urls[i],
174
+ region_name=regions[i],
157
175
  config=botocore.config.Config(tcp_keepalive=True, max_pool_connections=10),
158
176
  ),
159
177
  "key": keys[i],
@@ -1071,7 +1089,7 @@ def get_osgeo_path(path: str) -> str:
1071
1089
 
1072
1090
  storage_type, unprefixed_path, tray_name, base_name = get_infos_from_path(path)
1073
1091
 
1074
- if storage_type == StorageType.S3:
1092
+ if storage_type == StorageType.S3 and GDAL_AVAILABLE:
1075
1093
  s3_client, bucket_name = __get_s3_client(tray_name)
1076
1094
 
1077
1095
  gdal.SetConfigOption("AWS_SECRET_ACCESS_KEY", s3_client["secret_key"])
@@ -1,5 +1,4 @@
1
- """Provide functions to manipulate OGR / OSR entities
2
- """
1
+ """Provide functions to manipulate OGR / OSR entities"""
3
2
 
4
3
  # -- IMPORTS --
5
4
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: rok4
3
- Version: 2.2.0
3
+ Version: 2.2.4
4
4
  Summary: Python core libraries for ROK4 project
5
5
  Author-email: Géoportail IGN Developers <tout_rdev@ign.fr>
6
6
  License:
@@ -530,10 +530,11 @@ Classifier: Development Status :: 3 - Alpha
530
530
  Classifier: Topic :: Software Development :: Libraries
531
531
  Classifier: License :: CeCILL-C Free Software License Agreement (CECILL-C)
532
532
  Classifier: Programming Language :: Python :: 3
533
- Classifier: Programming Language :: Python :: 3.8
534
- Classifier: Programming Language :: Python :: 3.9
535
533
  Classifier: Programming Language :: Python :: 3.10
536
534
  Classifier: Programming Language :: Python :: 3.11
535
+ Classifier: Programming Language :: Python :: 3.12
536
+ Classifier: Programming Language :: Python :: 3.13
537
+ Classifier: Programming Language :: Python :: 3.14
537
538
  Classifier: Programming Language :: Python :: 3 :: Only
538
539
  Requires-Python: >=3.8
539
540
  Description-Content-Type: text/markdown
@@ -548,11 +549,12 @@ Requires-Dist: pdoc3>=0.10.0; extra == "doc"
548
549
  Provides-Extra: dev
549
550
  Requires-Dist: black; extra == "dev"
550
551
  Requires-Dist: isort>=5.12.0; extra == "dev"
551
- Requires-Dist: pre-commit<4,>3; extra == "dev"
552
+ Requires-Dist: pre-commit<5,>3; extra == "dev"
552
553
  Requires-Dist: ruff>=0.0.281; extra == "dev"
553
554
  Provides-Extra: test
554
555
  Requires-Dist: pytest>=7.1.2; extra == "test"
555
556
  Requires-Dist: coverage>=7.0.5; extra == "test"
557
+ Dynamic: license-file
556
558
 
557
559
  # ROK4 Python libraries
558
560
 
@@ -591,6 +593,7 @@ Following environment variables could be used, by module :
591
593
  * `ROK4_S3_KEY` : Key(s) for S3 server(s)
592
594
  * `ROK4_S3_SECRETKEY` : Secret key(s) for S3 server(s)
593
595
  * `ROK4_S3_URL` : URL(s) for S3 server(s)
596
+ * `ROK4_S3_REGION` : Region(s) for S3 server(s)
594
597
  * `ROK4_SSL_NO_VERIFY` : Disable SSL conrols for S3 access (any non empty value)
595
598
  * `tile_matrix_set` :
596
599
  * `ROK4_TMS_DIRECTORY` : Root directory (file or object) for tile matrix sets
@@ -7,7 +7,7 @@ requests>=2.30.0
7
7
  [dev]
8
8
  black
9
9
  isort>=5.12.0
10
- pre-commit<4,>3
10
+ pre-commit<5,>3
11
11
  ruff>=0.0.281
12
12
 
13
13
  [doc]
@@ -340,7 +340,7 @@ class TestRasterSetFromList(TestCase):
340
340
  assert math.isclose(serial_out["bbox"][i], serial_in["bbox"][i], rel_tol=1e-5)
341
341
  assert len(rasterset.colors) > 0
342
342
  assert rasterset.colors == colors
343
- for key in serial_in.keys():
343
+ for key in serial_in:
344
344
  if key != "bbox":
345
345
  assert serial_out[key] == serial_in[key]
346
346
  assert isinstance(serial_out["bbox"], list)
@@ -419,7 +419,7 @@ class TestRasterSetFromDescriptor(TestCase):
419
419
  for i in range(0, 4, 1):
420
420
  assert math.isclose(rasterset.bbox[i], serial_in["bbox"][i], rel_tol=1e-5)
421
421
  assert math.isclose(serial_out["bbox"][i], serial_in["bbox"][i], rel_tol=1e-5)
422
- for key in serial_in.keys():
422
+ for key in serial_in:
423
423
  if key != "bbox":
424
424
  assert serial_out[key] == serial_in[key]
425
425
 
@@ -91,6 +91,60 @@ def test_s3_invalid_envs():
91
91
  get_data_str("s3://bucket/path/to/object")
92
92
 
93
93
 
94
+ @mock.patch.dict(
95
+ os.environ,
96
+ {
97
+ "ROK4_S3_URL": "a,b",
98
+ "ROK4_S3_SECRETKEY": "b,c",
99
+ "ROK4_S3_KEY": "c,d",
100
+ "ROK4_S3_REGION": "r1,r2,r3",
101
+ },
102
+ clear=True,
103
+ )
104
+ def test_s3_invalid_optionnal_envs():
105
+ with pytest.raises(StorageError):
106
+ get_data_str("s3://bucket/path/to/object")
107
+
108
+
109
+ @mock.patch.dict(
110
+ os.environ,
111
+ {"ROK4_S3_URL": "https://a", "ROK4_S3_SECRETKEY": "b", "ROK4_S3_KEY": "c"},
112
+ clear=True,
113
+ )
114
+ @mock.patch("rok4.storage.boto3.client")
115
+ def test_s3_client_without_region(mocked_s3_client):
116
+ disconnect_s3_clients()
117
+ s3_instance = MagicMock()
118
+ s3_instance.get_object.return_value = {"Body": MagicMock(read=MagicMock(return_value=b"data"))}
119
+ mocked_s3_client.return_value = s3_instance
120
+ get_data_str("s3://bucket/path/to/object-no-region")
121
+ mocked_s3_client.assert_called_once()
122
+ assert mocked_s3_client.call_args.kwargs["region_name"] is None
123
+ disconnect_s3_clients()
124
+
125
+
126
+ @mock.patch.dict(
127
+ os.environ,
128
+ {
129
+ "ROK4_S3_URL": "https://a",
130
+ "ROK4_S3_SECRETKEY": "b",
131
+ "ROK4_S3_KEY": "c",
132
+ "ROK4_S3_REGION": "r1",
133
+ },
134
+ clear=True,
135
+ )
136
+ @mock.patch("rok4.storage.boto3.client")
137
+ def test_s3_client_with_region(mocked_s3_client):
138
+ disconnect_s3_clients()
139
+ s3_instance = MagicMock()
140
+ s3_instance.get_object.return_value = {"Body": MagicMock(read=MagicMock(return_value=b"data"))}
141
+ mocked_s3_client.return_value = s3_instance
142
+ get_data_str("s3://bucket/path/to/object-with-region")
143
+ mocked_s3_client.assert_called_once()
144
+ assert mocked_s3_client.call_args.kwargs["region_name"] == "r1"
145
+ disconnect_s3_clients()
146
+
147
+
94
148
  @mock.patch.dict(
95
149
  os.environ, {"ROK4_S3_URL": "a", "ROK4_S3_SECRETKEY": "b", "ROK4_S3_KEY": "c"}, clear=True
96
150
  )
@@ -69,9 +69,8 @@ def test_missing_crs(mocked_get_data_str):
69
69
  def test_wrong_crs(mocked_get_data_str):
70
70
  with pytest.raises(Exception) as exc:
71
71
  TileMatrixSet("tms")
72
- assert (
73
- str(exc.value)
74
- == "Wrong attribute 'crs' ('epsg:123456') in 'file:///path/to/tms.json', not recognize by OSR. Trace : PROJ: proj_create_from_database: crs not found"
72
+ assert str(exc.value).startswith(
73
+ "Wrong attribute 'crs' ('epsg:123456') in 'file:///path/to/tms.json', not recognize by OSR. Trace : PROJ: proj_create_from_database: crs not found"
75
74
  )
76
75
  mocked_get_data_str.assert_called_once_with("file:///path/to/tms.json")
77
76
 
@@ -1 +0,0 @@
1
- __version__ = "2.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes