-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructuration pour isoler la production des chemins standardisés (#74)
* commence restructuration * simplifie briques * test * import dans le module * modification dans s3 aussi * black
- Loading branch information
1 parent
a5a0886
commit 80b8a5a
Showing
5 changed files
with
159 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Module for communication with Minio S3 Storage | ||
""" | ||
|
||
from typing import Dict, Union | ||
|
||
BUCKET = "projet-cartiflette" | ||
PATH_WITHIN_BUCKET = "diffusion/shapefiles-test1" | ||
ENDPOINT_URL = "https://minio.lab.sspcloud.fr" | ||
|
||
# CREATE STANDARDIZED PATHS ------------------------ | ||
|
||
|
||
def create_path_bucket(config: Dict[str, Union[str, int, float]]) -> str: | ||
""" | ||
This function creates a file path for a vector file within a specified bucket. | ||
Parameters: | ||
config (Dict[str, Union[str, int, float]]): A dictionary containing vector file parameters. | ||
Returns: | ||
str: The complete file path for the vector file that will be used to read | ||
or write when interacting with S3 storage. | ||
""" | ||
|
||
bucket = config.get("bucket", BUCKET) | ||
path_within_bucket = config.get("path_within_bucket", PATH_WITHIN_BUCKET) | ||
provider = config.get("provider", "IGN") | ||
source = config.get("source", "EXPRESS-COG-TERRITOIRE") | ||
vectorfile_format = config.get("vectorfile_format", "geojson") | ||
borders = config.get("borders", "COMMUNE") | ||
filter_by = config.get("filter_by", "region") | ||
year = config.get("year", "2022") | ||
value = config.get("value", "28") | ||
crs = config.get("crs", 2154) | ||
|
||
write_path = f"{bucket}/{path_within_bucket}" | ||
write_path = f"{write_path}/{year=}" | ||
write_path = f"{write_path}/administrative_level={borders}" | ||
write_path = f"{write_path}/{crs=}" | ||
write_path = f"{write_path}/{filter_by}={value}/{vectorfile_format=}" | ||
write_path = f"{write_path}/{provider=}/{source=}" | ||
write_path = f"{write_path}/raw.{vectorfile_format}" | ||
write_path = write_path.replace("'", "") | ||
|
||
if vectorfile_format == "shp": | ||
write_path = write_path.rsplit("/", maxsplit=1)[0] + "/" | ||
|
||
return write_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from cartiflette.utils import ( | ||
create_path_bucket | ||
) | ||
# Import create_path_bucket function and VectorFileConfig here (if not already imported) | ||
|
||
# Define some test cases with different configurations | ||
@pytest.mark.parametrize( | ||
"config, expected_path", | ||
[ | ||
({"bucket": "my_bucket"}, 'my_bucket/diffusion/shapefiles-test1/year=2022/administrative_level=COMMUNE/crs=2154/region=28/vectorfile_format=geojson/provider=IGN/source=EXPRESS-COG-TERRITOIRE/raw.geojson'), | ||
({"vectorfile_format": "shp"}, 'projet-cartiflette/diffusion/shapefiles-test1/year=2022/administrative_level=COMMUNE/crs=2154/region=28/vectorfile_format=shp/provider=IGN/source=EXPRESS-COG-TERRITOIRE/'), | ||
({"borders": "DEPARTEMENT", "filter_by": "REGION", "year": "2023", "value": "42", "crs": 4326}, 'projet-cartiflette/diffusion/shapefiles-test1/year=2023/administrative_level=DEPARTEMENT/crs=4326/REGION=42/vectorfile_format=geojson/provider=IGN/source=EXPRESS-COG-TERRITOIRE/raw.geojson'), | ||
({"path_within_bucket": "data", "vectorfile_format": "gpkg"}, 'projet-cartiflette/data/year=2022/administrative_level=COMMUNE/crs=2154/region=28/vectorfile_format=gpkg/provider=IGN/source=EXPRESS-COG-TERRITOIRE/raw.gpkg'), | ||
], | ||
) | ||
def test_create_path_bucket(config, expected_path): | ||
result = create_path_bucket(config) | ||
assert result == expected_path | ||
|
||
# Run the tests | ||
if __name__ == "__main__": | ||
pytest.main() |