|
9 | 9 | import sys |
10 | 10 | from pathlib import Path |
11 | 11 | from subprocess import check_call |
12 | | -from typing import List, Optional |
| 12 | +from typing import TYPE_CHECKING, List, Optional |
13 | 13 |
|
14 | | -from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject |
15 | | -from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable |
| 14 | +from continuous_delivery_scripts.utils.configuration import ( |
| 15 | + configuration, |
| 16 | + ConfigurationVariable, |
| 17 | +) |
16 | 18 | from continuous_delivery_scripts.utils.definitions import CommitType |
17 | 19 | from continuous_delivery_scripts.utils.filesystem_helpers import TemporaryDirectory |
18 | 20 | from continuous_delivery_scripts.utils.filesystem_helpers import cd |
19 | | -from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name |
| 21 | +from continuous_delivery_scripts.utils.language_specifics_base import ( |
| 22 | + BaseLanguage, |
| 23 | + get_language_from_file_name, |
| 24 | +) |
20 | 25 | from continuous_delivery_scripts.utils.logging import log_exception |
21 | 26 | from continuous_delivery_scripts.utils.python.package_helpers import ( |
22 | 27 | CurrentPythonProjectMetadataFetcher, |
23 | 28 | generate_package_info, |
24 | 29 | ) |
25 | 30 |
|
| 31 | +if TYPE_CHECKING: |
| 32 | + from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject |
| 33 | + |
26 | 34 | ENVVAR_TWINE_USERNAME = "TWINE_USERNAME" |
27 | 35 | ENVVAR_TWINE_PASSWORD = "TWINE_PASSWORD" |
28 | 36 | OUTPUT_DIRECTORY = "release-dist" |
@@ -110,22 +118,34 @@ def _generate_pdoc_in_correct_structure(module_to_document: str, output_director |
110 | 118 | Pdoc nests its docs output in a folder with the module's name. |
111 | 119 | This process removes this unwanted folder. |
112 | 120 | """ |
113 | | - with TemporaryDirectory() as temp_dir: |
114 | | - _call_pdoc(temp_dir, module_to_document) |
115 | | - docs_contents_dir = temp_dir.joinpath(module_to_document) |
116 | | - if docs_contents_dir.exists() and docs_contents_dir.is_dir(): |
117 | | - for element in docs_contents_dir.iterdir(): |
118 | | - shutil.move(str(element), str(output_directory)) |
| 121 | + temp_directory = TemporaryDirectory() |
| 122 | + if hasattr(temp_directory, "__enter__") and hasattr(temp_directory, "__exit__"): |
| 123 | + with temp_directory as temp_dir: |
| 124 | + _call_pdoc(temp_dir, module_to_document) |
| 125 | + docs_contents_dir = temp_dir.joinpath(module_to_document) |
| 126 | + if docs_contents_dir.exists() and docs_contents_dir.is_dir(): |
| 127 | + for element in docs_contents_dir.iterdir(): |
| 128 | + shutil.move(str(element), str(output_directory)) |
| 129 | + return |
| 130 | + |
| 131 | + temp_dir = Path(str(temp_directory)) |
| 132 | + _call_pdoc(temp_dir, module_to_document) |
| 133 | + docs_contents_dir = temp_dir.joinpath(module_to_document) |
| 134 | + if docs_contents_dir.exists() and docs_contents_dir.is_dir(): |
| 135 | + for element in docs_contents_dir.iterdir(): |
| 136 | + shutil.move(str(element), str(output_directory)) |
119 | 137 |
|
120 | 138 |
|
121 | | -def _get_current_spdx_project() -> SpdxProject: |
| 139 | +def _get_current_spdx_project() -> "SpdxProject": |
122 | 140 | """Gets information about the current project/package.""" |
123 | 141 | logger.info("Generating package information.") |
124 | 142 | try: |
125 | 143 | # Trying to generate the egg for the package but this may fail. If so, continue. |
126 | 144 | generate_package_info() |
127 | 145 | except Exception as e: |
128 | 146 | log_exception(logger, e) |
| 147 | + from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject |
| 148 | + |
129 | 149 | return SpdxProject(CurrentPythonProjectMetadataFetcher()) |
130 | 150 |
|
131 | 151 |
|
@@ -174,6 +194,6 @@ def should_include_spdx_in_package(self) -> bool: |
174 | 194 | # FIXME Comment out SPDX package as no longer working |
175 | 195 | return False |
176 | 196 |
|
177 | | - def get_current_spdx_project(self) -> Optional[SpdxProject]: |
| 197 | + def get_current_spdx_project(self) -> Optional["SpdxProject"]: |
178 | 198 | """Gets the current SPDX description.""" |
179 | 199 | return _get_current_spdx_project() |
0 commit comments