77from collections .abc import Callable , Iterable , Iterator , Mapping , Sequence
88from copy import deepcopy
99from datetime import datetime
10- from os .path import isfile , join
10+ from os .path import isfile
11+ from pathlib import Path
1112from typing import (
1213 TYPE_CHECKING ,
1314 Any ,
@@ -198,7 +199,7 @@ def get_dataset_dict(self) -> dict:
198199 package ["resources" ] = self ._convert_hdxobjects (self ._resources )
199200 return package
200201
201- def save_to_json (self , path : str , follow_urls : bool = False ):
202+ def save_to_json (self , path : Path | str , follow_urls : bool = False ):
202203 """Save dataset to JSON. If follow_urls is True, resource urls that point to
203204 datasets, HXL proxy urls etc. are followed to retrieve final urls.
204205
@@ -219,7 +220,7 @@ def save_to_json(self, path: str, follow_urls: bool = False):
219220 save_json (dataset_dict , path )
220221
221222 @staticmethod
222- def load_from_json (path : str ) -> Optional ["Dataset" ]:
223+ def load_from_json (path : Path | str ) -> Optional ["Dataset" ]:
223224 """Load dataset from JSON
224225
225226 Args:
@@ -457,7 +458,7 @@ def move_resource(
457458 return resource
458459
459460 def update_from_yaml (
460- self , path : str = join ("config" , "hdx_dataset_static.yaml" )
461+ self , path : Path | str = Path ("config" , "hdx_dataset_static.yaml" )
461462 ) -> None :
462463 """Update dataset metadata with static metadata from YAML file
463464
@@ -471,7 +472,7 @@ def update_from_yaml(
471472 self .separate_resources ()
472473
473474 def update_from_json (
474- self , path : str = join ("config" , "hdx_dataset_static.json" )
475+ self , path : Path | str = Path ("config" , "hdx_dataset_static.json" )
475476 ) -> None :
476477 """Update dataset metadata with static metadata from JSON file
477478
@@ -2330,7 +2331,7 @@ def _create_preview_resourceview(self) -> None:
23302331 def _generate_resource_view (
23312332 self ,
23322333 resource : Union ["Resource" , dict , str , int ] = 0 ,
2333- path : str | None = None ,
2334+ path : Path | str | None = None ,
23342335 bites_disabled : Sequence [bool ] | None = None ,
23352336 indicators : Sequence [dict ] | None = None ,
23362337 findreplace : dict | None = None ,
@@ -2374,9 +2375,9 @@ def _generate_resource_view(
23742375 resourceview = resource_view .ResourceView (resourceview_data )
23752376 if path is None :
23762377 if indicators is None :
2377- path = join ("config" , "hdx_resource_view_static.yaml" )
2378+ path = Path ("config" , "hdx_resource_view_static.yaml" )
23782379 if not isfile (path ):
2379- path = path .replace ( ".yaml" , ".yml" )
2380+ path = path .with_suffix ( ".yml" )
23802381 else :
23812382 path = script_dir_plus_file (
23822383 "indicator_resource_view_template.yaml" ,
@@ -2488,7 +2489,7 @@ def replace_indicator(qc_config, index):
24882489 def generate_quickcharts (
24892490 self ,
24902491 resource : Union ["Resource" , dict , str , int ] = 0 ,
2491- path : str | None = None ,
2492+ path : Path | str | None = None ,
24922493 bites_disabled : Sequence [bool ] | None = None ,
24932494 indicators : Sequence [dict ] | None = None ,
24942495 findreplace : dict | None = None ,
@@ -2607,7 +2608,7 @@ def remove_dates_from_title(
26072608
26082609 def generate_resource (
26092610 self ,
2610- folder : str ,
2611+ folder : Path | str ,
26112612 filename : str ,
26122613 rows : Iterable [Sequence | Mapping ],
26132614 resourcedata : dict ,
@@ -2703,7 +2704,7 @@ def process_row(row: Sequence | Mapping) -> Sequence | Mapping | None:
27032704 dates [1 ] = enddate
27042705 return row
27052706
2706- filepath = join (folder , filename )
2707+ filepath = Path (folder ) / filename
27072708 rows = save_iterable (
27082709 filepath ,
27092710 rows ,
@@ -2739,7 +2740,7 @@ def process_row(row: Sequence | Mapping) -> Sequence | Mapping | None:
27392740
27402741 def generate_resource_from_rows (
27412742 self ,
2742- folder : str ,
2743+ folder : Path | str ,
27432744 filename : str ,
27442745 rows : Iterable [Sequence | Mapping ],
27452746 resourcedata : dict ,
@@ -2776,7 +2777,7 @@ def generate_resource_from_iterable(
27762777 headers : Sequence [str ],
27772778 iterable : Iterable [Sequence | dict ],
27782779 hxltags : dict [str , str ],
2779- folder : str ,
2780+ folder : Path | str ,
27802781 filename : str ,
27812782 resourcedata : dict ,
27822783 datecol : int | str | None = None ,
@@ -2988,7 +2989,7 @@ def generate_resource_from_iterator(
29882989 headers : Sequence [str ],
29892990 iterator : Iterator [Sequence | dict ],
29902991 hxltags : dict [str , str ],
2991- folder : str ,
2992+ folder : Path | str ,
29922993 filename : str ,
29932994 resourcedata : dict ,
29942995 datecol : int | str | None = None ,
@@ -3019,7 +3020,7 @@ def download_generate_resource(
30193020 self ,
30203021 downloader : BaseDownload ,
30213022 url : str ,
3022- folder : str ,
3023+ folder : Path | str ,
30233024 filename : str ,
30243025 resourcedata : dict ,
30253026 header_insertions : Sequence [tuple [int , str ]] | None = None ,
@@ -3122,7 +3123,7 @@ def download_and_generate_resource(
31223123 downloader : BaseDownload ,
31233124 url : str ,
31243125 hxltags : dict [str , str ],
3125- folder : str ,
3126+ folder : Path | str ,
31263127 filename : str ,
31273128 resourcedata : dict ,
31283129 header_insertions : Sequence [tuple [int , str ]] | None = None ,
0 commit comments