Skip to content

Commit ae8adde

Browse files
committed
Add .gitignore to generated projects
Closes #14
1 parent 3bbb641 commit ae8adde

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ dist/
44
*.egg-info/
55
.pytest_cache/
66

7-
# Sphinx documentation
8-
docs/_build/
9-
107
# pyenv
118
.python-version
129

@@ -22,7 +19,5 @@ dmypy.json
2219
# JetBrains
2320
.idea/
2421

25-
# Terraform
26-
.terraform
2722
/coverage.xml
2823
/.coverage

openapi_python_client/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ def _build_metadata(self) -> None:
110110
)
111111
)
112112

113+
# .gitignore
114+
git_ignore_path = self.project_dir / ".gitignore"
115+
git_ignore_template = self.env.get_template(".gitignore")
116+
git_ignore_path.write_text(git_ignore_template.render())
117+
113118
def _build_models(self) -> None:
114119
# Generate models
115120
models_dir = self.package_dir / "models"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__pycache__/
2+
build/
3+
dist/
4+
*.egg-info/
5+
.pytest_cache/
6+
7+
# pyenv
8+
.python-version
9+
10+
# Environments
11+
.env
12+
.venv
13+
14+
# mypy
15+
.mypy_cache/
16+
.dmypy.json
17+
dmypy.json
18+
19+
# JetBrains
20+
.idea/
21+
22+
/coverage.xml
23+
/.coverage

tests/test___init__.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pathlib
22

3+
import jinja2
34
import pytest
45

56

@@ -205,18 +206,34 @@ def test__build_metadata(self, mocker):
205206

206207
project = _Project(openapi=mocker.MagicMock(title="My Test API"))
207208
project.project_dir = mocker.MagicMock()
208-
pyproject_path = mocker.MagicMock()
209-
readme_path = mocker.MagicMock()
210-
project.project_dir.__truediv__.side_effect = [pyproject_path, readme_path]
209+
pyproject_path = mocker.MagicMock(autospec=pathlib.Path)
210+
readme_path = mocker.MagicMock(autospec=pathlib.Path)
211+
git_ignore_path = mocker.MagicMock(autospec=pathlib.Path)
212+
paths = {
213+
"pyproject.toml": pyproject_path,
214+
"README.md": readme_path,
215+
".gitignore": git_ignore_path,
216+
}
217+
project.project_dir.__truediv__.side_effect = lambda x: paths[x]
211218

212-
pyproject_template = mocker.MagicMock()
213-
readme_template = mocker.MagicMock()
214-
project.env = mocker.MagicMock()
215-
project.env.get_template.side_effect = [pyproject_template, readme_template]
219+
pyproject_template = mocker.MagicMock(autospec=jinja2.Template)
220+
readme_template = mocker.MagicMock(autospec=jinja2.Template)
221+
git_ignore_template = mocker.MagicMock(autospec=jinja2.Template)
222+
project.env = mocker.MagicMock(autospec=jinja2.Environment)
223+
templates = {
224+
"pyproject.toml": pyproject_template,
225+
"README.md": readme_template,
226+
".gitignore": git_ignore_template,
227+
}
228+
project.env.get_template.side_effect = lambda x: templates[x]
216229

217230
project._build_metadata()
218231

219-
project.env.get_template.assert_has_calls([mocker.call("pyproject.toml"), mocker.call("README.md")])
232+
project.env.get_template.assert_has_calls([
233+
mocker.call("pyproject.toml"),
234+
mocker.call("README.md"),
235+
mocker.call(".gitignore"),
236+
])
220237

221238
pyproject_template.render.assert_called_once_with(
222239
project_name=project.project_name,
@@ -230,6 +247,8 @@ def test__build_metadata(self, mocker):
230247
package_name=project.package_name,
231248
)
232249
readme_path.write_text.assert_called_once_with(readme_template.render())
250+
git_ignore_template.render.assert_called_once()
251+
git_ignore_path.write_text.assert_called_once_with(git_ignore_template.render())
233252

234253
def test__build_models(self, mocker):
235254
from openapi_python_client import _Project, OpenAPI

0 commit comments

Comments
 (0)