Skip to content

Commit 1535826

Browse files
committed
- Removed formatter option, as it seems a bit unnecessary
1 parent 473d10e commit 1535826

File tree

6 files changed

+22
-74
lines changed

6 files changed

+22
-74
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pydantic = "^1.9.1"
2323
orjson = "^3.7.2"
2424
openapi-schema-pydantic = "^1.2.3"
2525
Jinja2 = "^3.1.2"
26-
autopep8 = "^1.6.0"
2726
click = "^8.1.3"
2827
black = ">=21.10b0"
2928

src/openapi_python_generator/__main__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44

55
from openapi_python_generator import __version__
6-
from openapi_python_generator.common import HTTPLibrary, AutoFormat
6+
from openapi_python_generator.common import HTTPLibrary
77
from openapi_python_generator.generate_data import generate_data
88

99

@@ -16,15 +16,9 @@
1616
type=HTTPLibrary,
1717
help="HTTP library to use in the generation of the client.",
1818
)
19-
@click.option(
20-
"--autoformat",
21-
default=AutoFormat.black,
22-
type=AutoFormat,
23-
help="Option to choose which auto formatter is applied.",
24-
)
2519
@click.option(
2620
"--env-token-name",
27-
default=None,
21+
default="access_token",
2822
help="Name of the environment variable that contains the token. If you set this, the code expects this environment "
2923
"variable to be set and will raise an error if it is not.",
3024
)
@@ -33,7 +27,6 @@ def main(
3327
source: str,
3428
output: str,
3529
library: Optional[HTTPLibrary] = HTTPLibrary.httpx,
36-
autoformat: Optional[AutoFormat] = AutoFormat.black,
3730
env_token_name: Optional[str] = None,
3831
) -> None:
3932
"""
@@ -42,7 +35,7 @@ def main(
4235
Provide a SOURCE (file or URL) containing the OpenAPI 3 specification and
4336
an OUTPUT path, where the resulting client is created.
4437
"""
45-
generate_data(source, output, library, autoformat, env_token_name)
38+
generate_data(source, output, library, env_token_name)
4639

4740

4841
if __name__ == "__main__": # pragma: no cover

src/openapi_python_generator/common.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ class HTTPLibrary(str, Enum):
1414
aiohttp = "aiohttp"
1515

1616

17-
class AutoFormat(str, Enum):
18-
"""
19-
Enum for the available autoformat options
20-
"""
21-
22-
autopep8 = "autopep8"
23-
black = "black"
24-
none = "none"
25-
26-
2717
library_config_dict: Dict[Optional[HTTPLibrary], LibraryConfig] = {
2818
HTTPLibrary.httpx: LibraryConfig(
2919
name="httpx",

src/openapi_python_generator/generate_data.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@
77
from httpx import ConnectError, ConnectTimeout
88
import orjson
99
from pydantic import ValidationError
10-
import autopep8
1110

1211
from openapi_schema_pydantic import OpenAPI
13-
from .common import HTTPLibrary, library_config_dict, AutoFormat
12+
from .common import HTTPLibrary, library_config_dict
1413
from .language_converters.python.generator import generator
1514
from .language_converters.python.jinja_config import JINJA_ENV, SERVICE_TEMPLATE
1615
from .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

4132
def 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 *\nfrom .services import *\nfrom .api_config import *",
136-
autoformat,
137120
)
138121

139122

140123
def 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)

tests/test_generate_data.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from httpx import ConnectError
33

4-
from openapi_python_generator.common import library_config_dict, HTTPLibrary, AutoFormat
4+
from openapi_python_generator.common import library_config_dict, HTTPLibrary
55
from openapi_python_generator.generate_data import (
66
get_open_api,
77
write_data,
@@ -43,12 +43,9 @@ def test_generate_data(model_data_with_cleanup):
4343
assert (test_result_path / "__init__.py").is_file()
4444

4545

46-
@pytest.mark.parametrize(
47-
"autoformat", [AutoFormat.black, AutoFormat.autopep8, AutoFormat.none]
48-
)
49-
def test_write_data(model_data_with_cleanup, autoformat):
46+
def test_write_data(model_data_with_cleanup):
5047
result = generator(model_data_with_cleanup, library_config_dict[HTTPLibrary.httpx])
51-
write_data(result, test_result_path, autoformat)
48+
write_data(result, test_result_path)
5249

5350
assert test_result_path.exists()
5451
assert test_result_path.is_dir()

tests/test_main.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from click.testing import CliRunner
44

55
from openapi_python_generator.__main__ import main
6-
from openapi_python_generator.common import HTTPLibrary, AutoFormat
6+
from openapi_python_generator.common import HTTPLibrary
77
from tests.conftest import test_data_path, test_result_path
88

99

@@ -14,29 +14,16 @@ def runner() -> CliRunner:
1414

1515

1616
@pytest.mark.parametrize(
17-
"library,autoformat",
17+
"library",
1818
[
19-
(HTTPLibrary.httpx, AutoFormat.black),
20-
(HTTPLibrary.httpx, AutoFormat.autopep8),
21-
(HTTPLibrary.httpx, AutoFormat.none),
22-
(HTTPLibrary.requests, AutoFormat.black),
23-
(HTTPLibrary.requests, AutoFormat.autopep8),
24-
(HTTPLibrary.requests, AutoFormat.none),
19+
HTTPLibrary.httpx,
20+
HTTPLibrary.requests,
2521
],
2622
)
27-
def test_main_succeeds(
28-
runner: CliRunner, model_data_with_cleanup, library, autoformat
29-
) -> None:
23+
def test_main_succeeds(runner: CliRunner, model_data_with_cleanup, library) -> None:
3024
"""It exits with a status code of zero."""
3125
result = runner.invoke(
3226
main,
33-
[
34-
str(test_data_path),
35-
str(test_result_path),
36-
"--library",
37-
library.value,
38-
"--autoformat",
39-
autoformat.value,
40-
],
27+
[str(test_data_path), str(test_result_path), "--library", library.value],
4128
)
4229
assert result.exit_code == 0

0 commit comments

Comments
 (0)