From 117ee31f93f7931ac3325caec75cb2842b854613 Mon Sep 17 00:00:00 2001 From: Simon Guigui Date: Wed, 28 Oct 2020 11:21:13 +0100 Subject: [PATCH 1/2] Prevent autoflake to clean imports in module init files --- .../golden-record/my_test_api_client/__init__.py | 1 + .../golden-record/my_test_api_client/models/__init__.py | 8 ++++++++ openapi_python_client/__init__.py | 2 +- tests/test___init__.py | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/__init__.py index c8d0f1760..0f240c245 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/__init__.py @@ -1 +1,2 @@ """ A client library for accessing My Test API """ +from .client import AuthenticatedClient, Client diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py index 9f38702e3..5cf14bb24 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py @@ -1 +1,9 @@ """ Contains all the data models used in inputs/outputs """ + +from .a_model import AModel +from .an_enum import AnEnum +from .an_int_enum import AnIntEnum +from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost +from .different_enum import DifferentEnum +from .http_validation_error import HTTPValidationError +from .validation_error import ValidationError diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 2fcca23b3..8d2f984a3 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -76,7 +76,7 @@ def update(self) -> Sequence[GeneratorError]: def _reformat(self) -> None: subprocess.run( - "autoflake -i -r --remove-all-unused-imports --remove-unused-variables .", + "autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports .", cwd=self.package_dir, shell=True, stdout=subprocess.PIPE, diff --git a/tests/test___init__.py b/tests/test___init__.py index d7970e054..aa5a3af43 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -382,7 +382,7 @@ def test__reformat(mocker): sub_run.assert_has_calls( [ mocker.call( - "autoflake -i -r --remove-all-unused-imports --remove-unused-variables .", + "autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports .", cwd=project.package_dir, shell=True, stdout=subprocess.PIPE, From 126021d82d2b38f51e7b12ae9c93a92466ee1eac Mon Sep 17 00:00:00 2001 From: Dylan Anthony Date: Tue, 3 Nov 2020 08:11:49 -0700 Subject: [PATCH 2/2] Added changelog note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 168dfb1dc..8ad2b75c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixes - Prefix generated identifiers to allow leading digits in field names (#206 - @kalzoo). +- Prevent autoflake from removing `__init__.py` imports during generation. (#223 - Thanks @fyhertz!) - Update minimum Pydantic version to support Python 3.9 ### Additions