From 765ffb48a33142c73bbf803086ca9d5d69edc2ec Mon Sep 17 00:00:00 2001 From: iscai-msft <43154838+iscai-msft@users.noreply.github.com> Date: Tue, 21 May 2019 15:57:24 -0700 Subject: [PATCH] Fixes #77 Makes --keep-version-file work for Azure and Vanilla (#78) * initial keep file version working, will do more tests * Update .gitignore * Get latest tests to work * ChangeLog --- .gitignore | 2 +- ChangeLog.md | 3 +++ src/azure/CodeGeneratorPya.cs | 15 +++++++++++++-- .../operations_async/_header_operations_async.py | 2 +- .../header/operations/_header_operations.py | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ec2c1a9661..09e5782de8 100644 --- a/.gitignore +++ b/.gitignore @@ -302,4 +302,4 @@ package/ *.tgz src/obj/ *.log -.pytest_cache \ No newline at end of file +.pytest_cache diff --git a/ChangeLog.md b/ChangeLog.md index 09843db0c0..8761b9ef03 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ # Change Log +### 2019-05-21 - 4.0.70 + +- Beta version of --keep-version-file for ARM generator ### 2019-02-13 - 4.0.67 diff --git a/src/azure/CodeGeneratorPya.cs b/src/azure/CodeGeneratorPya.cs index 00b91fdfdf..110f85255e 100644 --- a/src/azure/CodeGeneratorPya.cs +++ b/src/azure/CodeGeneratorPya.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using AutoRest.Core.Model; +using AutoRest.Core; using AutoRest.Extensions.Azure; using AutoRest.Python.Model; using AutoRest.Python.Azure.Model; @@ -72,8 +73,18 @@ namespace AutoRest.Python.Azure await Write(serviceClientTemplateOpAsync, Path.Combine(folderName, "aio", "operations_async", "_" + codeModel.Name.ToPythonCase() + "_operations_async.py")); } - var versionTemplate = new VersionTemplate { Model = codeModel, }; - await Write(versionTemplate, Path.Combine(folderName, "version.py")); + // do we need to write out the version template file? + var versionPath = Path.Combine(folderName, "version.py"); + + // protect the version file + await Settings.Instance.Host.ProtectFiles(versionPath); + + if( true != await Settings.Instance.Host.GetValue("keep-version-file") || string.IsNullOrEmpty(await Settings.Instance.Host.ReadFile(versionPath)) ) { + var versionTemplate = new VersionTemplate { Model = codeModel }; + // if they didn't say to keep the old file (or it was not there/empty), write it out. + await Write(versionTemplate, versionPath); + } + //Models var models = codeModel.ModelTemplateModels.Where(each => !each.Extensions.ContainsKey(AzureExtensions.ExternalExtension)); diff --git a/test/vanilla/Expected/AcceptanceTests/Header/header/aio/operations_async/_header_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Header/header/aio/operations_async/_header_operations_async.py index 08a5233b0c..0a673a9642 100644 --- a/test/vanilla/Expected/AcceptanceTests/Header/header/aio/operations_async/_header_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Header/header/aio/operations_async/_header_operations_async.py @@ -1247,7 +1247,7 @@ class HeaderOperations: if raw: client_raw_response = ClientRawResponse(None, response) client_raw_response.add_headers({ - 'value': models.GreyscaleColors, + 'value': 'str', }) return client_raw_response response_enum.metadata = {'url': '/header/response/prim/enum'} diff --git a/test/vanilla/Expected/AcceptanceTests/Header/header/operations/_header_operations.py b/test/vanilla/Expected/AcceptanceTests/Header/header/operations/_header_operations.py index 03f06a55d3..91508f7f74 100644 --- a/test/vanilla/Expected/AcceptanceTests/Header/header/operations/_header_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Header/header/operations/_header_operations.py @@ -1247,7 +1247,7 @@ class HeaderOperations(object): if raw: client_raw_response = ClientRawResponse(None, response) client_raw_response.add_headers({ - 'value': models.GreyscaleColors, + 'value': 'str', }) return client_raw_response response_enum.metadata = {'url': '/header/response/prim/enum'}