Skip to content

Commit 011c435

Browse files
Copilotdbanty
andauthored
Create parent directories when creating project directory
Co-authored-by: dbanty <43723790+dbanty@users.noreply.github.com>
1 parent 6321ce4 commit 011c435

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

end_to_end_tests/generated_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def generate_client(
9494
"""Run the generator and return a GeneratedClientContext for accessing the generated code."""
9595
args = []
9696
if extra_args is not None:
97-
args = extra_args
97+
args = list(extra_args)
9898
full_output_path = Path(__file__).parent / "tmp" / output_path
9999

100100
if not overwrite:

openapi_python_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def build(self) -> Sequence[GeneratorError]:
118118

119119
print(f"Generating {self.project_dir}")
120120
try:
121-
self.project_dir.mkdir()
121+
self.project_dir.mkdir(parents=True)
122122
except FileExistsError:
123123
if not self.config.overwrite:
124124
return [GeneratorError(detail="Directory already exists. Delete it or use the --overwrite option.")]

tests/test___init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from pathlib import Path
2+
13
import pytest
24

3-
from openapi_python_client import Config, ErrorLevel, GeneratorData, Project
5+
from openapi_python_client import Config, ErrorLevel, GeneratorData, MetaType, Project
46
from openapi_python_client.config import ConfigFile
57
from openapi_python_client.schema.untrusted_string import UntrustedString
68

@@ -67,3 +69,22 @@ def test__run_post_hooks_reports_stderr_of_commands_that_error(self, project_wit
6769
assert error.level == ErrorLevel.ERROR
6870
assert error.header == "python3 failed"
6971
assert "some exception" in error.detail
72+
73+
def test_build_creates_parent_directories(self, tmp_path):
74+
fresh_config = Config.from_sources(
75+
ConfigFile(),
76+
MetaType.POETRY,
77+
document_source=Path("openapi.yaml"),
78+
file_encoding="utf-8",
79+
overwrite=False,
80+
output_path=None,
81+
)
82+
project = make_project(fresh_config)
83+
project.project_dir = tmp_path / "nested" / "dir" / "my-api-client"
84+
project.package_dir = project.project_dir / project.package_name
85+
86+
errors = project.build()
87+
88+
assert errors == []
89+
assert project.project_dir.exists()
90+
assert project.project_dir.is_dir()

0 commit comments

Comments
 (0)