|
3 | 3 |
|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
| 6 | +import logging |
6 | 7 | import os |
7 | 8 | from pathlib import Path |
8 | 9 |
|
9 | 10 |
|
10 | | -DEBUG_MODE = False # Set to True to enable additional debug logging. |
| 11 | +logger = logging.getLogger("airbyte") |
| 12 | + |
11 | 13 |
|
| 14 | +DEBUG_MODE = False # Set to True to enable additional debug logging. |
12 | 15 |
|
13 | 16 | AB_EXTRACTED_AT_COLUMN = "_airbyte_extracted_at" |
14 | 17 | """A column that stores the timestamp when the record was extracted.""" |
|
36 | 39 | } |
37 | 40 | """A set of internal columns that are reserved for PyAirbyte's internal use.""" |
38 | 41 |
|
39 | | -DEFAULT_PROJECT_DIR: Path = ( |
40 | | - Path(os.getenv("AIRBYTE_PROJECT_DIR", "") or Path.cwd()).expanduser().absolute() |
| 42 | + |
| 43 | +def _try_create_dir_if_missing(path: Path, desc: str = "specified") -> Path: |
| 44 | + """Try to create a directory if it does not exist.""" |
| 45 | + resolved_path = path.expanduser().resolve() |
| 46 | + try: |
| 47 | + if resolved_path.exists(): |
| 48 | + if not resolved_path.is_dir(): |
| 49 | + logger.warning( |
| 50 | + "The %s path exists but is not a directory: '%s'", desc, resolved_path |
| 51 | + ) |
| 52 | + return resolved_path |
| 53 | + resolved_path.mkdir(parents=True, exist_ok=True) |
| 54 | + except Exception as ex: |
| 55 | + logger.warning( |
| 56 | + "Could not auto-create missing %s directory at '%s': %s", desc, resolved_path, ex |
| 57 | + ) |
| 58 | + return resolved_path |
| 59 | + |
| 60 | + |
| 61 | +DEFAULT_PROJECT_DIR: Path = _try_create_dir_if_missing( |
| 62 | + Path(os.getenv("AIRBYTE_PROJECT_DIR", "") or Path.cwd()).expanduser().absolute(), |
| 63 | + desc="project", |
41 | 64 | ) |
42 | 65 | """Default project directory. |
43 | 66 |
|
|
47 | 70 |
|
48 | 71 | This serves as the parent directory for both cache and install directories when not explicitly |
49 | 72 | configured. |
| 73 | +
|
| 74 | +If a path is specified that does not yet exist, PyAirbyte will attempt to create it. |
50 | 75 | """ |
51 | 76 |
|
| 77 | + |
| 78 | +DEFAULT_INSTALL_DIR: Path = _try_create_dir_if_missing( |
| 79 | + Path(os.getenv("AIRBYTE_INSTALL_DIR", "") or DEFAULT_PROJECT_DIR).expanduser().absolute(), |
| 80 | + desc="install", |
| 81 | +) |
| 82 | +"""Default install directory for connectors. |
| 83 | +
|
| 84 | +If not set, defaults to `DEFAULT_PROJECT_DIR` (`AIRBYTE_PROJECT_DIR` env var) or the current |
| 85 | +working directory if neither is set. |
| 86 | +
|
| 87 | +If a path is specified that does not yet exist, PyAirbyte will attempt to create it. |
| 88 | +""" |
| 89 | + |
| 90 | + |
52 | 91 | DEFAULT_CACHE_ROOT: Path = ( |
53 | 92 | (Path(os.getenv("AIRBYTE_CACHE_ROOT", "") or (DEFAULT_PROJECT_DIR / ".cache"))) |
54 | 93 | .expanduser() |
|
69 | 108 | Specific caches may override this value with a different schema name. |
70 | 109 | """ |
71 | 110 |
|
72 | | -DEFAULT_INSTALL_DIR: Path = ( |
73 | | - Path(os.getenv("AIRBYTE_INSTALL_DIR", "") or DEFAULT_PROJECT_DIR).expanduser().absolute() |
74 | | -) |
75 | | -"""Default install directory for connectors. |
76 | | -
|
77 | | -If not set, defaults to `DEFAULT_PROJECT_DIR` (`AIRBYTE_PROJECT_DIR` env var) or the current |
78 | | -working directory if neither is set. |
79 | | -""" |
80 | | - |
81 | | - |
82 | 111 | DEFAULT_GOOGLE_DRIVE_MOUNT_PATH = "/content/drive" |
83 | 112 | """Default path to mount Google Drive in Google Colab environments.""" |
84 | 113 |
|
|
0 commit comments