Skip to content

Commit

Permalink
Add patch file compatability (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Apr 3, 2020
1 parent 0c00071 commit a29a264
Show file tree
Hide file tree
Showing 57 changed files with 342 additions and 3 deletions.
8 changes: 7 additions & 1 deletion autorest/codegen/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def serialize(self, code_model: CodeModel) -> None:
Path(".") if code_model.options["no_namespace_folders"] else Path(*(code_model.namespace.split(".")))
)

# if there was a patch file before, we keep it
if self._autorestapi.read_file(namespace_path / "patch.py"):
self._autorestapi.write_file(
namespace_path / Path("patch.py"),
self._autorestapi.read_file(namespace_path / "patch.py")
)

if code_model.schemas or code_model.enums:
self._serialize_and_write_models_folder(code_model=code_model, env=env, namespace_path=namespace_path)

Expand Down Expand Up @@ -121,7 +128,6 @@ def _serialize_and_write_operations_folder(
)



def _serialize_and_write_version_file(
self, code_model: CodeModel, namespace_path: Path, general_serializer: GeneralSerializer
):
Expand Down
8 changes: 8 additions & 0 deletions autorest/codegen/templates/init.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ from ._version import VERSION
__version__ = VERSION
{% endif %}
__all__ = ['{{ code_model.class_name }}']
{% if not async_mode %}

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
{% endif %}
4 changes: 2 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def regen_expected(c, opts, debug):
cmd_line = '{} {}'.format(_AUTOREST_CMD_LINE, " ".join(args))
print(Fore.YELLOW + f'Queuing up: {cmd_line}')
cmds.append(cmd_line)
# Delete the old code, we can catch when it's not generating
shutil.rmtree(output_folder, ignore_errors=True)

if len(cmds) == 1:
success = run_autorest(cmds[0], debug=debug)
Expand All @@ -163,6 +161,8 @@ def regen_expected(c, opts, debug):
success = all(result)

if not success:
# Delete the old code, we can catch when it's not generating
shutil.rmtree(output_folder, ignore_errors=True)
raise SystemExit("Autorest generation fails")

def run_autorest(cmd_line, debug=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestDurationTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestParameterGroupingTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestReportServiceForAzure']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestAzureSpecialParametersTestClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestParameterizedHostTestClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestParameterizedHostTestPagingClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
6 changes: 6 additions & 0 deletions test/azure/Expected/AcceptanceTests/Head/head/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestHeadTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestHeadExceptionTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
6 changes: 6 additions & 0 deletions test/azure/Expected/AcceptanceTests/Lro/lro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestLongRunningOperationTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
6 changes: 6 additions & 0 deletions test/azure/Expected/AcceptanceTests/Paging/paging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestPagingTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['StorageManagementClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['MicrosoftAzureTestUrl']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._multiapi_service_client import MultiapiServiceClient
__all__ = ['MultiapiServiceClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
3 changes: 3 additions & 0 deletions test/vanilla/AcceptanceTests/asynctests/test_string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ async def test_enum_referenced(self, client):
async def test_enum_referenced_constant(self, client):
await client.enum.put_referenced_constant()
assert (await client.enum.get_referenced_constant()).color_constant == Colors.green_color.value

def test_patch_file(self):
from bodystring.models import PatchAddedModel
4 changes: 4 additions & 0 deletions test/vanilla/AcceptanceTests/test_string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ def test_enum_referenced(self, client):
def test_enum_referenced_constant(self, client):
client.enum.put_referenced_constant()
assert client.enum.get_referenced_constant().color_constant == Colors.green_color.value

def test_patch_file(self):
from bodystring.models import PatchAddedModel

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AdditionalPropertiesClient']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestSwaggerBATArrayService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestBoolTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestSwaggerBATByteService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestComplexTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestDateTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestDateTimeTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestRFC1123DateTimeTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestSwaggerBATDictionaryService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestDurationTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestSwaggerBATFileService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestIntegerTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@

__version__ = VERSION
__all__ = ['AutoRestNumberTestService']

try:
from .patch import patch_sdk
patch_sdk()
except ImportError:
pass
Loading

0 comments on commit a29a264

Please sign in to comment.