@typespec/http-client-python 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,7 +60,7 @@ class BlackScriptPlugin(Plugin):
60
60
  except:
61
61
  _LOGGER.error("Error: failed to format %s", file)
62
62
  raise
63
- if len(file_content.splitlines()) > 1000:
63
+ if len(file_content.splitlines()) > 1000 and "pylint: disable=too-many-lines" not in file_content:
64
64
  file_content = "# pylint: disable=too-many-lines\n" + file_content
65
65
  self.write_file(file, file_content)
66
66
 
@@ -155,7 +155,7 @@ class TokenCredentialType(CredentialType[Union[BearerTokenCredentialPolicyType,
155
155
 
156
156
  @property
157
157
  def type_description(self) -> str:
158
- return "TokenCredential"
158
+ return "token credential"
159
159
 
160
160
  @property
161
161
  def credentials_subfolder(self) -> str:
@@ -5,6 +5,7 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
7
  from collections import namedtuple
8
+ import re
8
9
  from typing import List, Any, Union
9
10
  from pathlib import Path
10
11
  from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
@@ -94,6 +95,19 @@ class JinjaSerializer(ReaderAndWriter):
94
95
  async_loop = AsyncInfo(async_mode=True, async_path="aio/")
95
96
  return [sync_loop, async_loop] if self.has_aio_folder else [sync_loop]
96
97
 
98
+ @property
99
+ def keep_version_file(self) -> bool:
100
+ if self.options.get("keep_version_file"):
101
+ return True
102
+ # If the version file is already there and the version is greater than the current version, keep it.
103
+ try:
104
+ serialized_version_file = self.read_file(self.exec_path(self.code_model.namespace) / "_version.py")
105
+ match = re.search(r'VERSION\s*=\s*"([^"]+)"', str(serialized_version_file))
106
+ serialized_version = match.group(1) if match else ""
107
+ except (FileNotFoundError, IndexError):
108
+ serialized_version = ""
109
+ return serialized_version > self.code_model.options["package_version"]
110
+
97
111
  def serialize(self) -> None:
98
112
  env = Environment(
99
113
  loader=PackageLoader("pygen.codegen", "templates"),
@@ -193,6 +207,9 @@ class JinjaSerializer(ReaderAndWriter):
193
207
  file = template_name.replace(".jinja2", "")
194
208
  output_name = root_of_sdk / file
195
209
  if not self.read_file(output_name) or file in _REGENERATE_FILES:
210
+ if self.keep_version_file and file == "setup.py":
211
+ # don't regenerate setup.py file if the version file is more up to date
212
+ continue
196
213
  self.write_file(
197
214
  output_name,
198
215
  serializer.serialize_package_file(template_name, **params),
@@ -329,10 +346,9 @@ class JinjaSerializer(ReaderAndWriter):
329
346
  _read_version_file(original_version_file_name),
330
347
  )
331
348
 
332
- keep_version_file = self.code_model.options["keep_version_file"]
333
- if keep_version_file and _read_version_file("_version.py"):
349
+ if self.keep_version_file and _read_version_file("_version.py"):
334
350
  _write_version_file(original_version_file_name="_version.py")
335
- elif keep_version_file and _read_version_file("version.py"):
351
+ elif self.keep_version_file and _read_version_file("version.py"):
336
352
  _write_version_file(original_version_file_name="version.py")
337
353
  elif self.code_model.options["package_version"]:
338
354
  self.write_file(
@@ -116,7 +116,7 @@ class _ModelSerializer(BaseSerializer, ABC):
116
116
  def initialize_properties(self, model: ModelType) -> List[str]: ...
117
117
 
118
118
  def need_init(self, model: ModelType) -> bool:
119
- return (not model.internal) and bool(self.init_line(model) or model.discriminator)
119
+ return bool(self.init_line(model) or model.discriminator)
120
120
 
121
121
  def pylint_disable_items(self, model: ModelType) -> List[str]:
122
122
  if model.flattened_property or self.initialize_properties(model):
@@ -123,9 +123,9 @@
123
123
  "implementation_version": "3.8.10",
124
124
  "os_name": "posix",
125
125
  "platform_machine": "x86_64",
126
- "platform_release": "5.15.0-1075-azure",
126
+ "platform_release": "5.15.0-1078-azure",
127
127
  "platform_system": "Linux",
128
- "platform_version": "#84~20.04.1-Ubuntu SMP Mon Nov 4 18:58:41 UTC 2024",
128
+ "platform_version": "#87~20.04.1-Ubuntu SMP Wed Dec 18 20:14:54 UTC 2024",
129
129
  "python_full_version": "3.8.10",
130
130
  "platform_python_implementation": "CPython",
131
131
  "python_version": "3.8",
@@ -60,7 +60,7 @@ class BlackScriptPlugin(Plugin):
60
60
  except:
61
61
  _LOGGER.error("Error: failed to format %s", file)
62
62
  raise
63
- if len(file_content.splitlines()) > 1000:
63
+ if len(file_content.splitlines()) > 1000 and "pylint: disable=too-many-lines" not in file_content:
64
64
  file_content = "# pylint: disable=too-many-lines\n" + file_content
65
65
  self.write_file(file, file_content)
66
66
 
@@ -155,7 +155,7 @@ class TokenCredentialType(CredentialType[Union[BearerTokenCredentialPolicyType,
155
155
 
156
156
  @property
157
157
  def type_description(self) -> str:
158
- return "TokenCredential"
158
+ return "token credential"
159
159
 
160
160
  @property
161
161
  def credentials_subfolder(self) -> str:
@@ -5,6 +5,7 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
7
  from collections import namedtuple
8
+ import re
8
9
  from typing import List, Any, Union
9
10
  from pathlib import Path
10
11
  from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
@@ -94,6 +95,19 @@ class JinjaSerializer(ReaderAndWriter):
94
95
  async_loop = AsyncInfo(async_mode=True, async_path="aio/")
95
96
  return [sync_loop, async_loop] if self.has_aio_folder else [sync_loop]
96
97
 
98
+ @property
99
+ def keep_version_file(self) -> bool:
100
+ if self.options.get("keep_version_file"):
101
+ return True
102
+ # If the version file is already there and the version is greater than the current version, keep it.
103
+ try:
104
+ serialized_version_file = self.read_file(self.exec_path(self.code_model.namespace) / "_version.py")
105
+ match = re.search(r'VERSION\s*=\s*"([^"]+)"', str(serialized_version_file))
106
+ serialized_version = match.group(1) if match else ""
107
+ except (FileNotFoundError, IndexError):
108
+ serialized_version = ""
109
+ return serialized_version > self.code_model.options["package_version"]
110
+
97
111
  def serialize(self) -> None:
98
112
  env = Environment(
99
113
  loader=PackageLoader("pygen.codegen", "templates"),
@@ -193,6 +207,9 @@ class JinjaSerializer(ReaderAndWriter):
193
207
  file = template_name.replace(".jinja2", "")
194
208
  output_name = root_of_sdk / file
195
209
  if not self.read_file(output_name) or file in _REGENERATE_FILES:
210
+ if self.keep_version_file and file == "setup.py":
211
+ # don't regenerate setup.py file if the version file is more up to date
212
+ continue
196
213
  self.write_file(
197
214
  output_name,
198
215
  serializer.serialize_package_file(template_name, **params),
@@ -329,10 +346,9 @@ class JinjaSerializer(ReaderAndWriter):
329
346
  _read_version_file(original_version_file_name),
330
347
  )
331
348
 
332
- keep_version_file = self.code_model.options["keep_version_file"]
333
- if keep_version_file and _read_version_file("_version.py"):
349
+ if self.keep_version_file and _read_version_file("_version.py"):
334
350
  _write_version_file(original_version_file_name="_version.py")
335
- elif keep_version_file and _read_version_file("version.py"):
351
+ elif self.keep_version_file and _read_version_file("version.py"):
336
352
  _write_version_file(original_version_file_name="version.py")
337
353
  elif self.code_model.options["package_version"]:
338
354
  self.write_file(
@@ -116,7 +116,7 @@ class _ModelSerializer(BaseSerializer, ABC):
116
116
  def initialize_properties(self, model: ModelType) -> List[str]: ...
117
117
 
118
118
  def need_init(self, model: ModelType) -> bool:
119
- return (not model.internal) and bool(self.init_line(model) or model.discriminator)
119
+ return bool(self.init_line(model) or model.discriminator)
120
120
 
121
121
  def pylint_disable_items(self, model: ModelType) -> List[str]:
122
122
  if model.flattened_property or self.initialize_properties(model):
@@ -92,7 +92,7 @@ async def test_operation(client: AccessClient):
92
92
  @pytest.mark.asyncio
93
93
  async def test_discriminator(client: AccessClient):
94
94
  result = await client.relative_model_in_operation._discriminator(kind="real")
95
- assert result == models._models.RealModel(name="Madge", kind="real")
95
+ assert result == models._models.RealModel(name="Madge")
96
96
 
97
97
  with pytest.raises(ImportError):
98
98
  from specs.azure.clientgenerator.core.access.models import RealModel
@@ -83,7 +83,7 @@ def test_operation(client: AccessClient):
83
83
 
84
84
  def test_discriminator(client: AccessClient):
85
85
  result = client.relative_model_in_operation._discriminator(kind="real")
86
- assert result == models._models.RealModel(name="Madge", kind="real")
86
+ assert result == models._models.RealModel(name="Madge")
87
87
 
88
88
  with pytest.raises(ImportError):
89
89
  from specs.azure.clientgenerator.core.access.models import RealModel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",