|
9 | 9 | from dataclasses import asdict, dataclass, field |
10 | 10 | from pathlib import Path |
11 | 11 | from typing import Any, Dict, List, Optional, Tuple, Union |
| 12 | +import warnings |
12 | 13 |
|
13 | 14 | import requests |
14 | 15 | from pydantic import BaseModel |
@@ -293,13 +294,30 @@ def download_url(url: str) -> Dict[str, Any]: |
293 | 294 | response.raise_for_status() |
294 | 295 | return response.json() |
295 | 296 |
|
296 | | - def download_package(self, package_name: str, version: str) -> None: |
| 297 | + def download_package( |
| 298 | + self, |
| 299 | + package_name: str, |
| 300 | + version: str, |
| 301 | + skip_invalid: bool = False, |
| 302 | + include_dependencies: bool = True, |
| 303 | + ) -> None: |
297 | 304 | """Download a package from the registry and add its structure definitions to the registry.""" |
298 | 305 | for sd in self._package_client.load_resources_from_package( |
299 | | - "StructureDefinition", package_name, version |
| 306 | + "StructureDefinition", |
| 307 | + package_name, |
| 308 | + version, |
| 309 | + install_dependencies=include_dependencies, |
300 | 310 | ): |
301 | | - structure_definition = self._validate_structure_definition(sd) |
302 | | - self.add(structure_definition) |
| 311 | + try: |
| 312 | + structure_definition = self._validate_structure_definition(sd) |
| 313 | + self.add(structure_definition) |
| 314 | + except ValueError as e: |
| 315 | + if not skip_invalid: |
| 316 | + raise e |
| 317 | + else: |
| 318 | + warnings.warn( |
| 319 | + f"Skipping invalid structure definition {sd.get('url', 'unknown')} in package {package_name} version {version}:\n{e}" |
| 320 | + ) |
303 | 321 |
|
304 | 322 | def set_registry_base_url(self, base_url: str) -> None: |
305 | 323 | """Change the package registry base URL.""" |
|
0 commit comments