|
70 | 70 | """Files and dirs at the root of a frozen directory that should be ignored.
|
71 | 71 | This is the same list as in the preprocess_frozen_modules script."""
|
72 | 72 |
|
| 73 | +repository_urls = {} |
| 74 | +"""Cache of repository URLs for frozen modules.""" |
| 75 | + |
73 | 76 | def get_circuitpython_root_dir():
|
74 | 77 | """ The path to the root './circuitpython' directory
|
75 | 78 | """
|
@@ -168,15 +171,38 @@ def get_settings_from_makefile(port_dir, board_name):
|
168 | 171 | return settings
|
169 | 172 |
|
170 | 173 | def get_repository_url(directory):
|
171 |
| - contents = subprocess.run( |
172 |
| - ["git", "remote", "get-url", "origin"], |
173 |
| - encoding="utf-8", |
174 |
| - errors="replace", |
175 |
| - stdout=subprocess.PIPE, |
176 |
| - stderr=subprocess.PIPE, |
177 |
| - cwd=directory |
178 |
| - ) |
179 |
| - return contents.stdout.strip() |
| 174 | + if directory in repository_urls: |
| 175 | + return repository_urls[directory] |
| 176 | + readme = None |
| 177 | + for readme_path in ( |
| 178 | + os.path.join(directory, "README.rst"), |
| 179 | + os.path.join(os.path.dirname(directory), "README.rst") |
| 180 | + ): |
| 181 | + if os.path.exists(readme_path): |
| 182 | + readme = readme_path |
| 183 | + break |
| 184 | + path = None |
| 185 | + if readme: |
| 186 | + with open(readme, "r") as fp: |
| 187 | + for line in fp.readlines(): |
| 188 | + if m := re.match("\s+:target:\s+(http\S+(docs.circuitpython|readthedocs)\S+)\s*", line): |
| 189 | + path = m.group(1) |
| 190 | + break |
| 191 | + if m := re.search("<(http[^>]+)>", line): |
| 192 | + path = m.group(1) |
| 193 | + break |
| 194 | + if path is None: |
| 195 | + contents = subprocess.run( |
| 196 | + ["git", "remote", "get-url", "origin"], |
| 197 | + encoding="utf-8", |
| 198 | + errors="replace", |
| 199 | + stdout=subprocess.PIPE, |
| 200 | + stderr=subprocess.PIPE, |
| 201 | + cwd=directory |
| 202 | + ) |
| 203 | + path = contents.stdout.strip() |
| 204 | + repository_urls[directory] = path |
| 205 | + return path |
180 | 206 |
|
181 | 207 | def frozen_modules_from_dirs(frozen_mpy_dirs):
|
182 | 208 | """
|
|
0 commit comments