|
1 | 1 | """stubber configuration""" |
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | | -from typing import List |
| 4 | +from typing import List, Optional, Union |
5 | 5 |
|
6 | 6 | from mpflash.logger import log |
7 | 7 | from mpflash.versions import get_preview_mp_version, get_stable_mp_version, micropython_versions |
|
13 | 13 |
|
14 | 14 | @section("micropython-stubber") |
15 | 15 | class StubberConfig(Config): |
| 16 | + _config_path = None |
| 17 | + |
16 | 18 | "stubber configuration class" |
17 | 19 | # relative to stubs folder |
18 | 20 | fallback_path: Path = key( |
@@ -81,6 +83,15 @@ def template_path(self) -> Path: |
81 | 83 | "return the stubs path in the microypthon-stubs repo" |
82 | 84 | return self.mpy_stubs_path / "publish" / "template" |
83 | 85 |
|
| 86 | + @property |
| 87 | + def config_path(self) -> Path: |
| 88 | + "return the config path" |
| 89 | + return self._config_path |
| 90 | + |
| 91 | + @config_path.setter |
| 92 | + def config_path(self, value: Path): |
| 93 | + self._config_path = value |
| 94 | + |
84 | 95 | def post_read_hook(self) -> dict: |
85 | 96 | config_updates = {} |
86 | 97 | # relative to stubs |
@@ -108,21 +119,27 @@ def post_read_hook(self) -> dict: |
108 | 119 | return config_updates |
109 | 120 |
|
110 | 121 |
|
111 | | -def readconfig(filename: str = "pyproject.toml", prefix: str = "tool.", must_exist: bool = True): |
| 122 | +def readconfig( |
| 123 | + location: Optional[Path] = None, |
| 124 | + filename: str = "pyproject.toml", |
| 125 | + prefix: str = "tool.", |
| 126 | + must_exist: bool = True, |
| 127 | +): |
112 | 128 | "read the configuration from the pyproject.toml file" |
113 | 129 | # locate the pyproject.toml file |
114 | | - path = Path.cwd() |
| 130 | + config_path = location or Path.cwd() |
115 | 131 | use_toml = True |
116 | | - while not (path / filename).exists(): |
117 | | - path = path.parent |
118 | | - if path == path.parent: |
| 132 | + while not (config_path / filename).exists(): |
| 133 | + config_path = config_path.parent |
| 134 | + if config_path == config_path.parent: |
119 | 135 | log.trace(f"Could not find config file: {filename}") |
120 | 136 | use_toml = False |
121 | 137 | break |
122 | 138 |
|
123 | | - filename = str(path / filename) |
| 139 | + filename = str(config_path / filename) |
124 | 140 |
|
125 | 141 | config = StubberConfig() |
| 142 | + config.config_path = config_path.absolute() |
126 | 143 | # add provider sources to the config |
127 | 144 | config.add_source(EnvironmentConfigSource()) |
128 | 145 | if use_toml: |
|
0 commit comments