77from httpx import ConnectError , ConnectTimeout
88import orjson
99from pydantic import ValidationError
10- import autopep8
1110
1211from openapi_schema_pydantic import OpenAPI
13- from .common import HTTPLibrary , library_config_dict , AutoFormat
12+ from .common import HTTPLibrary , library_config_dict
1413from .language_converters .python .generator import generator
1514from .language_converters .python .jinja_config import JINJA_ENV , SERVICE_TEMPLATE
1615from .models import ConversionResult
1716
1817
19- def write_code (
20- path : Path , content , autoformat : Optional [AutoFormat ] = AutoFormat .black
21- ) -> None :
18+ def write_code (path : Path , content ) -> None :
2219 """
2320 Write the content to the file at the given path.
2421 :param autoformat: The autoformat applied to the code written.
2522 :param path: The path to the file.
2623 :param content: The content to write.
2724 """
2825 with open (path , "w" ) as f :
29- if autoformat == AutoFormat .black :
30- f .write (
31- black .format_file_contents (
32- content , fast = False , mode = black .FileMode (line_length = 120 )
33- )
34- )
35- elif autoformat == AutoFormat .autopep8 :
36- f .write (autopep8 .fix_code (content , options = {"max_line_length" : 120 }))
37- else :
38- f .write (content )
26+ formatted_contend = black .format_file_contents (
27+ content , fast = False , mode = black .FileMode (line_length = 120 )
28+ )
29+ f .write (formatted_contend )
3930
4031
4132def get_open_api (source : Union [str , Path ]) -> OpenAPI :
@@ -67,11 +58,7 @@ def get_open_api(source: Union[str, Path]) -> OpenAPI:
6758 raise
6859
6960
70- def write_data (
71- data : ConversionResult ,
72- output : Union [str , Path ],
73- autoformat : Optional [AutoFormat ] = AutoFormat .black ,
74- ) -> None :
61+ def write_data (data : ConversionResult , output : Union [str , Path ]) -> None :
7562 """
7663 This function will firstly create the folderstrucutre of output, if it doesn't exist. Then it will create the
7764 models from data.models into the models sub module of the output folder. After this, the services will be created
@@ -97,13 +84,12 @@ def write_data(
9784 # Write the models.
9885 for model in data .models :
9986 files .append (model .file_name )
100- write_code (models_path / f"{ model .file_name } .py" , model .content , autoformat )
87+ write_code (models_path / f"{ model .file_name } .py" , model .content )
10188
10289 # Create models.__init__.py file containing imports to all models.
10390 write_code (
10491 models_path / "__init__.py" ,
10592 "\n " .join ([f"from .{ file } import *" for file in files ]),
106- autoformat ,
10793 )
10894
10995 files = []
@@ -116,32 +102,28 @@ def write_data(
116102 write_code (
117103 services_path / f"{ service .file_name } .py" ,
118104 JINJA_ENV .get_template (SERVICE_TEMPLATE ).render (** service .dict ()),
119- autoformat ,
120105 )
121106
122107 # Create services.__init__.py file containing imports to all services.
123108 write_code (
124109 services_path / "__init__.py" ,
125110 "\n " .join ([f"from .{ file } import *" for file in files ]),
126- autoformat ,
127111 )
128112
129113 # Write the api_config.py file.
130- write_code (Path (output ) / "api_config.py" , data .api_config .content , autoformat )
114+ write_code (Path (output ) / "api_config.py" , data .api_config .content )
131115
132116 # Write the __init__.py file.
133117 write_code (
134118 Path (output ) / "__init__.py" ,
135119 "from .models import *\n from .services import *\n from .api_config import *" ,
136- autoformat ,
137120 )
138121
139122
140123def generate_data (
141124 source : Union [str , Path ],
142125 output : Union [str , Path ],
143126 library : Optional [HTTPLibrary ] = HTTPLibrary .httpx ,
144- autoformat : Optional [AutoFormat ] = AutoFormat .black ,
145127 env_token_name : Optional [str ] = None ,
146128) -> None :
147129 """
@@ -150,4 +132,4 @@ def generate_data(
150132 data = get_open_api (source )
151133 click .echo (f"Generating data from { source } " )
152134 result = generator (data , library_config_dict [library ], env_token_name )
153- write_data (result , output , autoformat )
135+ write_data (result , output )
0 commit comments