File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1
1
""" Generate modern Python clients from OpenAPI """
2
2
3
+ import os
3
4
import json
4
5
import mimetypes
5
6
import shutil
@@ -127,7 +128,21 @@ def update(self) -> Sequence[GeneratorError]:
127
128
if not self .package_dir .is_dir ():
128
129
return [GeneratorError (detail = f"Directory { self .package_dir } not found" )]
129
130
print (f"Updating { self .package_name } " )
130
- shutil .rmtree (self .package_dir )
131
+
132
+ if not self .config .protected_dirs :
133
+ shutil .rmtree (self .package_dir )
134
+ else :
135
+ files_and_dirs : List [str ] = os .listdir (self .package_dir )
136
+ for protected_dir in self .config .protected_dirs :
137
+ files_and_dirs .remove (protected_dir )
138
+
139
+ for file_or_dir in files_and_dirs :
140
+ path = os .path .join (self .package_dir , file_or_dir )
141
+ if os .path .isfile (path ):
142
+ os .remove (path )
143
+ if os .path .isdir (path ):
144
+ shutil .rmtree (path )
145
+
131
146
self ._create_package ()
132
147
self ._build_models ()
133
148
self ._build_api ()
@@ -170,7 +185,7 @@ def _get_errors(self) -> List[GeneratorError]:
170
185
return errors
171
186
172
187
def _create_package (self ) -> None :
173
- self .package_dir .mkdir ()
188
+ self .package_dir .mkdir (exist_ok = True )
174
189
# Package __init__.py
175
190
package_init = self .package_dir / "__init__.py"
176
191
Original file line number Diff line number Diff line change 1
1
import codecs
2
2
import pathlib
3
3
from pprint import pformat
4
- from typing import Optional , Sequence
4
+ from typing import Optional , List , Sequence
5
5
6
6
import typer
7
7
@@ -159,7 +159,7 @@ def update(
159
159
meta : MetaType = _meta_option ,
160
160
file_encoding : str = typer .Option ("utf-8" , help = "Encoding used when writing generated" ),
161
161
config_path : Optional [pathlib .Path ] = CONFIG_OPTION ,
162
- fail_on_warning : bool = False ,
162
+ fail_on_warning : bool = False
163
163
) -> None :
164
164
"""Update an existing OpenAPI Client library
165
165
@@ -188,6 +188,6 @@ def update(
188
188
meta = meta ,
189
189
custom_template_path = custom_template_path ,
190
190
file_encoding = file_encoding ,
191
- config = config ,
191
+ config = config
192
192
)
193
193
handle_errors (errors , fail_on_warning )
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class Config(BaseModel):
27
27
project_name_override : Optional [str ]
28
28
package_name_override : Optional [str ]
29
29
package_version_override : Optional [str ]
30
+ protected_dirs : Optional [List [str ]]
30
31
post_hooks : List [str ] = [
31
32
"autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports ." ,
32
33
"isort ." ,
You can’t perform that action at this time.
0 commit comments