Skip to content

Commit 5ba1bae

Browse files
committed
cc chaotic: do not import types, only modules
commit_hash:0af1f4eb5e5009957b04d3e7b46405d50e6556ec
1 parent 93a7c40 commit 5ba1bae

30 files changed

+306
-301
lines changed

chaotic-openapi/chaotic_openapi/back/cpp_client/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from chaotic.back.cpp import types as cpp_types
1010
from chaotic.front import parser as chaotic_parser
1111
from chaotic.front import ref
12-
from . import renderer
12+
from chaotic_openapi.back.cpp_client import renderer
1313

1414
TYPES_INCLUDES = [
1515
'cstdint',

chaotic-openapi/chaotic_openapi/back/cpp_client/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from chaotic import cpp_names
55
from chaotic import error
66
from chaotic.back.cpp import types as cpp_types
7-
from . import middleware
7+
from chaotic_openapi.back.cpp_client import middleware
88

99

1010
@dataclasses.dataclass

chaotic-openapi/chaotic_openapi/back/linter/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import yaml
66

7+
from chaotic_openapi.back.linter import validators
78
from chaotic_openapi.front import parser as front_parser
8-
from . import validators
99

1010

1111
def parse_args():

chaotic-openapi/chaotic_openapi/front/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any
55

66
from chaotic.front import types
7-
from . import base_model
7+
from chaotic_openapi.front import base_model
88

99

1010
class In(str, enum.Enum):

chaotic-openapi/chaotic_openapi/front/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pydantic
55

6-
from . import base_model
7-
from . import errors
6+
from chaotic_openapi.front import base_model
7+
from chaotic_openapi.front import errors
88

99

1010
# https://spec.openapis.org/oas/v3.0.0.html#info-object

chaotic-openapi/chaotic_openapi/front/parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from chaotic.front import parser as chaotic_parser
1111
from chaotic.front import ref
1212
from chaotic.front import types
13-
from . import base_model
14-
from . import errors
15-
from . import model
16-
from . import openapi
17-
from . import ref_resolver
18-
from . import swagger
13+
from chaotic_openapi.front import base_model
14+
from chaotic_openapi.front import errors
15+
from chaotic_openapi.front import model
16+
from chaotic_openapi.front import openapi
17+
from chaotic_openapi.front import ref_resolver
18+
from chaotic_openapi.front import swagger
1919

2020

2121
@dataclasses.dataclass

chaotic-openapi/chaotic_openapi/front/swagger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pydantic
55

6-
from . import base_model
7-
from . import errors
6+
from chaotic_openapi.front import base_model
7+
from chaotic_openapi.front import errors
88

99

1010
class Info(base_model.BaseModel):

chaotic/chaotic/compilers/dynamic_config.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
from chaotic import cpp_format
1111
from chaotic import cpp_names
12+
from chaotic import main
1213
from chaotic.back.cpp import renderer
1314
from chaotic.back.cpp import translator
14-
from chaotic.back.cpp import types
15+
from chaotic.back.cpp import types as cpp_types
1516
from chaotic.front import ref
16-
from chaotic.front.types import ResolvedSchemas
17-
from chaotic.main import generate_cpp_name_func
18-
from chaotic.main import NameMapItem
19-
from chaotic.main import read_schemas
17+
from chaotic.front import types as front_types
2018

2119
INCLUDE_DIRS = [
2220
str(pathlib.Path(__file__).parent.parent.parent / 'include'),
@@ -80,10 +78,10 @@ def enrich_jinja_env(env: jinja2.Environment) -> None:
8078

8179
class CompilerBase:
8280
def __init__(self) -> None:
83-
self._variables_types: dict[str, dict[str, types.CppType]] = {}
81+
self._variables_types: dict[str, dict[str, cpp_types.CppType]] = {}
8482
self._definitions: dict[
8583
str,
86-
tuple[ResolvedSchemas, dict[str, types.CppType]],
84+
tuple[front_types.ResolvedSchemas, dict[str, cpp_types.CppType]],
8785
] = {}
8886
self._defaults: dict[str, Any] = {}
8987
self.seen_includes: dict[str, set[str]] = {}
@@ -114,14 +112,14 @@ def _extract_definition_names(self, content: Any) -> list[str]:
114112

115113
return []
116114

117-
def extract_variable_type(self) -> types.CppType:
115+
def extract_variable_type(self) -> cpp_types.CppType:
118116
keys = list(self._variables_types.keys())
119117
assert len(keys) == 1
120118
name = keys[0]
121119

122120
name_lower = self.format_ns_name(name)
123-
types = self._variables_types[name]
124-
return types[f'::taxi_config::{name_lower}::VariableTypeRaw']
121+
var_types = self._variables_types[name]
122+
return var_types[f'::taxi_config::{name_lower}::VariableTypeRaw']
125123

126124
def format_ns_name(self, name: str) -> str:
127125
return name.lower().replace('/', '_').replace('-', '_').split('.')[0]
@@ -133,7 +131,7 @@ def parse_definition(
133131
include_dirs: list[str] = [],
134132
) -> None:
135133
name_lower = self.format_ns_name(name)
136-
name_map = [NameMapItem('/([^/]+)/={0}')]
134+
name_map = [main.NameMapItem('/([^/]+)/={0}')]
137135
# fname = f'taxi_config/definitions/{name}'
138136
fname = f'{name}'
139137

@@ -172,9 +170,9 @@ def parse_variable(
172170
name_lower = self.format_ns_name(name)
173171
name_map = [
174172
# Variable type
175-
NameMapItem('/schema/=VariableTypeRaw'),
173+
main.NameMapItem('/schema/=VariableTypeRaw'),
176174
# Aux. types
177-
NameMapItem('/schema/definitions/([^/]+)/={0}'),
175+
main.NameMapItem('/schema/definitions/([^/]+)/={0}'),
178176
]
179177
# The virtual name is used for generated filepath identification
180178
# fname = f'taxi_config/variables/{name}.types.yaml'
@@ -193,13 +191,13 @@ def parse_variable(
193191
self._defaults[name] = self._read_default(filepath)
194192
self.seen_includes[filepath] = seen_includes
195193

196-
def _collect_schemas(self) -> list[ResolvedSchemas]:
194+
def _collect_schemas(self) -> list[front_types.ResolvedSchemas]:
197195
schemas = []
198196
for def_schemas, _definitions in self._definitions.values():
199197
schemas.append(def_schemas)
200198
return schemas
201199

202-
def _collect_types(self) -> dict[str, types.CppType]:
200+
def _collect_types(self) -> dict[str, cpp_types.CppType]:
203201
types = {}
204202
for _def_schemas, definitions in self._definitions.values():
205203
types.update(definitions)
@@ -213,15 +211,15 @@ def _generate_types(
213211
name_map,
214212
fname: str,
215213
include_dirs: list[str],
216-
) -> tuple[ResolvedSchemas, dict[str, types.CppType], set[str]]:
217-
schemas = read_schemas(
214+
) -> tuple[front_types.ResolvedSchemas, dict[str, cpp_types.CppType], set[str]]:
215+
schemas = main.read_schemas(
218216
erase_path_prefix=erase_prefix,
219217
filepaths=[filepath],
220218
name_map=name_map,
221-
file_map=[NameMapItem(escape_re_pattern(filepath) + '=' + fname)],
219+
file_map=[main.NameMapItem(escape_re_pattern(filepath) + '=' + fname)],
222220
dependencies=self._collect_schemas(),
223221
)
224-
cpp_name_func = generate_cpp_name_func(
222+
cpp_name_func = main.generate_cpp_name_func(
225223
name_map=name_map,
226224
erase_prefix=erase_prefix,
227225
)
@@ -273,7 +271,7 @@ def _jinja(self) -> jinja2.Environment:
273271

274272
def create_aliases(
275273
self,
276-
types: dict[str, types.CppType],
274+
types: dict[str, cpp_types.CppType],
277275
) -> list[tuple[str, str]]:
278276
return []
279277

chaotic/chaotic/cpp_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import cpp_keywords
1+
from chaotic import cpp_keywords
22

33

44
def camel_case(string: str, no_lower_casing: bool = False) -> str:

chaotic/chaotic/front/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pydantic
99

1010
from chaotic import error
11-
from . import base_model
11+
from chaotic.front import base_model
1212

1313

1414
class FieldError(Exception):

0 commit comments

Comments
 (0)