Skip to content

Commit eb60e2f

Browse files
♻️ Extract yaml codec to a variable.
1 parent 83b2a84 commit eb60e2f

File tree

7 files changed

+11
-27
lines changed

7 files changed

+11
-27
lines changed

src/lapidary/render/load.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
from pathlib import Path
55

66
import httpx
7-
import ruamel.yaml
87

98
from .config import Config
109

1110
logger = logging.getLogger(__name__)
1211

1312

1413
def load_document(root: Path, config: Config) -> Mapping:
15-
logger.info('Load OpenAPI document')
14+
from .yaml import yaml
1615

17-
yaml = ruamel.yaml.YAML(typ='safe')
16+
logger.info('Load OpenAPI document')
1817

1918
text = document_handler_for(root, config.document_path).load()
2019
return yaml.load(text)

src/lapidary/render/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import click
77
import pydantic
8-
import ruamel.yaml
98

109
from .config import Config, load_config
1110
from .load import document_handler_for, load_document
1211
from .model import conv_openapi, openapi, python
12+
from .yaml import yaml
1313

1414
logger = logging.getLogger(__name__)
1515

@@ -58,7 +58,6 @@ def init_project(
5858
package=package_name,
5959
)
6060

61-
yaml = ruamel.yaml.YAML(typ='safe')
6261
document = yaml.load(document_handler.load())
6362

6463
init_project(project_root, config, document)
@@ -95,7 +94,6 @@ def progress(module: python.AbstractModule) -> None:
9594
def dump_model(project_root: Path, process: bool, output: TextIO):
9695
config = load_config(project_root)
9796
oa_doc = load_document(project_root, config)
98-
yaml = ruamel.yaml.YAML(typ='safe')
9997

10098
if not process:
10199
yaml.dump(oa_doc, output)

src/lapidary/render/yaml.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ruamel.yaml
2+
3+
yaml = ruamel.yaml.YAML(typ='safe')

tests/process/test_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
from pathlib import Path
44

55
import pytest
6-
import ruamel.yaml
76
from openapi_pydantic.v3.v3_1 import schema as schema31
87

98
from lapidary.render import runtime
109
from lapidary.render.model import conv_openapi, conv_schema, metamodel, openapi, python, stack
10+
from lapidary.render.yaml import yaml
1111

1212
logging.basicConfig()
1313
logging.getLogger('lapidary').setLevel(logging.DEBUG)
1414

15-
yaml = ruamel.yaml.YAML(typ='safe')
16-
1715

1816
@pytest.fixture
1917
def document() -> openapi.OpenAPI:

tests/process/test_security_scheme.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
from pathlib import Path
22

33
import pytest
4-
import ruamel.yaml
54

65
from lapidary.render.model import conv_openapi, openapi, python
76
from lapidary.render.model.stack import Stack
8-
9-
10-
@pytest.fixture()
11-
def yaml():
12-
return ruamel.yaml.YAML(typ='safe')
7+
from lapidary.render.yaml import yaml
138

149

1510
@pytest.mark.parametrize('path', (Path(__file__).parent / 'security_schemes').glob('*'))
16-
def test_process_security_schemes(yaml: ruamel.yaml.YAML, path: Path):
11+
def test_process_security_schemes(path: Path):
1712
document = openapi.OpenAPI.model_validate(yaml.load(path.read_text()))
1813

1914
converter = conv_openapi.OpenApi30Converter(python.ModulePath('package', False), document, None)

tests/process/test_servers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from pathlib import Path
22

33
import pytest
4-
import ruamel.yaml
54

65
from lapidary.render.model import conv_openapi, openapi, python
76
from lapidary.render.model.stack import Stack
8-
9-
yaml = ruamel.yaml.YAML(typ='safe')
7+
from lapidary.render.yaml import yaml
108

119
yaml_home = Path(__file__).parent / 'servers'
1210
test_files = [

tests/test_e2e.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
from pathlib import Path
44

55
import pytest
6-
import ruamel.yaml
76

87
from lapidary.render.main import render_project
98

10-
11-
@pytest.fixture()
12-
def yaml():
13-
return ruamel.yaml.YAML(typ='safe')
14-
15-
169
e2e_root = Path(__file__).parent / 'e2e'
1710
e2e_tests = [path.name for path in (e2e_root / 'init').iterdir() if path.is_dir()]
1811

@@ -22,7 +15,7 @@ def yaml():
2215
e2e_tests,
2316
ids=e2e_tests,
2417
)
25-
def test_generate(yaml: ruamel.yaml.YAML, project_name: Path, tmp_path: Path) -> None:
18+
def test_generate(project_name: Path, tmp_path: Path) -> None:
2619
init_root = e2e_root / 'init' / project_name
2720
project_root = tmp_path / 'project'
2821

0 commit comments

Comments
 (0)