|
4 | 4 | import os |
5 | 5 | from base64 import b64decode |
6 | 6 | from collections import UserDict |
7 | | -from os.path import expanduser, isfile, join |
| 7 | +from os.path import expanduser |
| 8 | +from pathlib import Path |
8 | 9 | from typing import Any, Optional |
9 | 10 |
|
10 | 11 | import ckanapi |
@@ -38,22 +39,22 @@ class Configuration(UserDict): |
38 | 39 | hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. |
39 | 40 | hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. |
40 | 41 | hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR |
41 | | - hdx_config_json (str): Path to JSON HDX configuration OR |
42 | | - hdx_config_yaml (str): Path to YAML HDX configuration |
| 42 | + hdx_config_json (Path | str): Path to JSON HDX configuration OR |
| 43 | + hdx_config_yaml (Path | str): Path to YAML HDX configuration |
43 | 44 | project_config_dict (dict): Project configuration dictionary OR |
44 | | - project_config_json (str): Path to JSON Project configuration OR |
45 | | - project_config_yaml (str): Path to YAML Project configuration |
| 45 | + project_config_json (Path | str): Path to JSON Project configuration OR |
| 46 | + project_config_yaml (Path | str): Path to YAML Project configuration |
46 | 47 | hdx_base_config_dict (dict): HDX base configuration dictionary OR |
47 | | - hdx_base_config_json (str): Path to JSON HDX base configuration OR |
48 | | - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
| 48 | + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR |
| 49 | + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
49 | 50 | """ |
50 | 51 |
|
51 | 52 | _configuration = None |
52 | 53 | home_folder = expanduser("~") |
53 | 54 | default_hdx_base_config_yaml = script_dir_plus_file( |
54 | 55 | "hdx_base_configuration.yaml", ConfigurationError |
55 | 56 | ) |
56 | | - default_hdx_config_yaml = join(home_folder, ".hdx_configuration.yaml") |
| 57 | + default_hdx_config_yaml = Path(home_folder, ".hdx_configuration.yaml") |
57 | 58 |
|
58 | 59 | prefix = f"HDXPythonLibrary/{__version__}" |
59 | 60 |
|
@@ -111,10 +112,10 @@ def __init__(self, **kwargs: Any) -> None: |
111 | 112 | raise ConfigurationError("More than one HDX configuration given!") |
112 | 113 | else: |
113 | 114 | if not hdx_config_yaml: |
114 | | - hdx_config_yaml = Configuration.default_hdx_config_yaml |
115 | | - if not isfile(hdx_config_yaml): |
116 | | - hdx_config_yaml = hdx_config_yaml.replace(".yaml", ".yml") |
117 | | - if isfile(hdx_config_yaml): |
| 115 | + hdx_config_yaml = Path(Configuration.default_hdx_config_yaml) |
| 116 | + if not hdx_config_yaml.is_file(): |
| 117 | + hdx_config_yaml = hdx_config_yaml.with_suffix(".yml") |
| 118 | + if hdx_config_yaml.is_file(): |
118 | 119 | logger.info( |
119 | 120 | f"No HDX configuration parameter. Using default configuration file: {hdx_config_yaml}." |
120 | 121 | ) |
@@ -364,7 +365,7 @@ def create_session_user_agent( |
364 | 365 | cls, |
365 | 366 | session: requests.Session = None, |
366 | 367 | user_agent: str | None = None, |
367 | | - user_agent_config_yaml: str | None = None, |
| 368 | + user_agent_config_yaml: Path | str | None = None, |
368 | 369 | user_agent_lookup: str | None = None, |
369 | 370 | use_env: bool = False, |
370 | 371 | **kwargs: Any, |
@@ -509,14 +510,14 @@ def setup( |
509 | 510 | hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. |
510 | 511 | hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. |
511 | 512 | hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR |
512 | | - hdx_config_json (str): Path to JSON HDX configuration OR |
513 | | - hdx_config_yaml (str): Path to YAML HDX configuration |
| 513 | + hdx_config_json (Path | str): Path to JSON HDX configuration OR |
| 514 | + hdx_config_yaml (Path | str): Path to YAML HDX configuration |
514 | 515 | project_config_dict (dict): Project configuration dictionary OR |
515 | | - project_config_json (str): Path to JSON Project configuration OR |
516 | | - project_config_yaml (str): Path to YAML Project configuration |
| 516 | + project_config_json (Path | str): Path to JSON Project configuration OR |
| 517 | + project_config_yaml (Path | str): Path to YAML Project configuration |
517 | 518 | hdx_base_config_dict (dict): HDX base configuration dictionary OR |
518 | | - hdx_base_config_json (str): Path to JSON HDX base configuration OR |
519 | | - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
| 519 | + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR |
| 520 | + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
520 | 521 |
|
521 | 522 | Returns: |
522 | 523 | None |
@@ -549,14 +550,14 @@ def _create( |
549 | 550 | hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. |
550 | 551 | hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. |
551 | 552 | hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR |
552 | | - hdx_config_json (str): Path to JSON HDX configuration OR |
553 | | - hdx_config_yaml (str): Path to YAML HDX configuration |
| 553 | + hdx_config_json (Path | str): Path to JSON HDX configuration OR |
| 554 | + hdx_config_yaml (Path | str): Path to YAML HDX configuration |
554 | 555 | project_config_dict (dict): Project configuration dictionary OR |
555 | | - project_config_json (str): Path to JSON Project configuration OR |
556 | | - project_config_yaml (str): Path to YAML Project configuration |
| 556 | + project_config_json (Path | str): Path to JSON Project configuration OR |
| 557 | + project_config_yaml (Path | str): Path to YAML Project configuration |
557 | 558 | hdx_base_config_dict (dict): HDX base configuration dictionary OR |
558 | | - hdx_base_config_json (str): Path to JSON HDX base configuration OR |
559 | | - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
| 559 | + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR |
| 560 | + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
560 | 561 |
|
561 | 562 | Returns: |
562 | 563 | HDX site url |
@@ -588,14 +589,14 @@ def create( |
588 | 589 | hdx_read_only (bool): Whether to access HDX in read only mode. Defaults to False. |
589 | 590 | hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. |
590 | 591 | hdx_config_dict (dict): HDX configuration dictionary to use instead of above 3 parameters OR |
591 | | - hdx_config_json (str): Path to JSON HDX configuration OR |
592 | | - hdx_config_yaml (str): Path to YAML HDX configuration |
| 592 | + hdx_config_json (Path | str): Path to JSON HDX configuration OR |
| 593 | + hdx_config_yaml (Path | str): Path to YAML HDX configuration |
593 | 594 | project_config_dict (dict): Project configuration dictionary OR |
594 | | - project_config_json (str): Path to JSON Project configuration OR |
595 | | - project_config_yaml (str): Path to YAML Project configuration |
| 595 | + project_config_json (Path | str): Path to JSON Project configuration OR |
| 596 | + project_config_yaml (Path | str): Path to YAML Project configuration |
596 | 597 | hdx_base_config_dict (dict): HDX base configuration dictionary OR |
597 | | - hdx_base_config_json (str): Path to JSON HDX base configuration OR |
598 | | - hdx_base_config_yaml (str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
| 598 | + hdx_base_config_json (Path | str): Path to JSON HDX base configuration OR |
| 599 | + hdx_base_config_yaml (Path | str): Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml. |
599 | 600 |
|
600 | 601 | Returns: |
601 | 602 | HDX site url |
|
0 commit comments