@typespec/http-client-python 0.14.3-dev.1 → 0.15.0

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.
@@ -46,7 +46,7 @@ class OptionsDict(MutableMapping):
46
46
  self._data = options.copy() if options else {}
47
47
  self._validate_combinations()
48
48
 
49
- def __getitem__(self, key: str) -> Any:
49
+ def __getitem__(self, key: str) -> Any: # pylint: disable=too-many-return-statements
50
50
  if key == "head-as-boolean" and self.get("azure-arm"):
51
51
  # override to always true if azure-arm is set
52
52
  return True
@@ -61,6 +61,15 @@ class OptionsDict(MutableMapping):
61
61
  if key == "package-mode" and self._data.get("packaging-files-dir"):
62
62
  # if packaging-files-dir is set, use it as package-mode
63
63
  return self._data["packaging-files-dir"]
64
+ if key == "generation-subdir":
65
+ data = self._data.get("generation-subdir")
66
+ if data:
67
+ # Remove leading dot or ./ from generation-subdir
68
+ if data.startswith("./"):
69
+ data = data[2:]
70
+ elif data.startswith("."):
71
+ data = data[1:]
72
+ return data
64
73
  return self._get_default(key)
65
74
 
66
75
  def __setitem__(self, key: str, value: Any) -> None:
@@ -52,7 +52,10 @@ class EnumValue(BaseType):
52
52
  """The python type used for RST syntax input and type annotation."""
53
53
 
54
54
  type_annotation = self.value_type.type_annotation(**kwargs)
55
- enum_type_annotation = f"{self.enum_type.client_namespace}.models.{self.name}"
55
+ client_namespace = self.enum_type.client_namespace
56
+ if self.code_model.options.get("generation-subdir"):
57
+ client_namespace += f".{self.code_model.options['generation-subdir']}"
58
+ enum_type_annotation = f"{client_namespace}.models.{self.name}"
56
59
  return f"{type_annotation} or ~{enum_type_annotation}"
57
60
 
58
61
  def get_json_template_representation(
@@ -292,7 +292,10 @@ class GeneratedModelType(ModelType):
292
292
 
293
293
  def docstring_type(self, **kwargs: Any) -> str:
294
294
  type_annotation = self.type_annotation(need_model_alias=False, skip_quote=True, **kwargs)
295
- return f"~{self.client_namespace}.models.{type_annotation}"
295
+ client_namespace = self.client_namespace
296
+ if self.code_model.options.get("generation-subdir"):
297
+ client_namespace += f".{self.code_model.options['generation-subdir']}"
298
+ return f"~{client_namespace}.models.{type_annotation}"
296
299
 
297
300
  def docstring_text(self, **kwargs: Any) -> str:
298
301
  return self.name
@@ -7,7 +7,7 @@ import logging
7
7
  import json
8
8
  from collections import namedtuple
9
9
  import re
10
- from typing import List, Any, Union
10
+ from typing import List, Any, Union, Optional
11
11
  from pathlib import Path
12
12
  from packaging.version import parse as parse_version
13
13
  from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
@@ -165,7 +165,7 @@ class JinjaSerializer(ReaderAndWriter):
165
165
  # add _metadata.json
166
166
  if self.code_model.metadata:
167
167
  self.write_file(
168
- generation_path / Path("_metadata.json"),
168
+ Path("./_metadata.json"),
169
169
  json.dumps(self.code_model.metadata, indent=2),
170
170
  )
171
171
  elif client_namespace_type.clients:
@@ -376,8 +376,12 @@ class JinjaSerializer(ReaderAndWriter):
376
376
  def _serialize_and_write_version_file(
377
377
  self,
378
378
  general_serializer: GeneralSerializer,
379
+ namespace: Optional[str] = None,
379
380
  ):
380
- generation_path = self.code_model.get_root_dir()
381
+ if namespace:
382
+ generation_path = self.code_model.get_generation_dir(namespace)
383
+ else:
384
+ generation_path = self.code_model.get_root_dir()
381
385
 
382
386
  def _read_version_file(original_version_file_name: str) -> str:
383
387
  return self.read_file(generation_path / original_version_file_name)
@@ -472,6 +476,9 @@ class JinjaSerializer(ReaderAndWriter):
472
476
 
473
477
  # write _version.py
474
478
  self._serialize_and_write_version_file(general_serializer)
479
+ # if there's a subdir, we need to write another version file in the subdir
480
+ if self.code_model.options.get("generation-subdir"):
481
+ self._serialize_and_write_version_file(general_serializer, namespace)
475
482
 
476
483
  # write the empty py.typed file
477
484
  pytyped_value = "# Marker file for PEP 561."
@@ -46,7 +46,7 @@ class OptionsDict(MutableMapping):
46
46
  self._data = options.copy() if options else {}
47
47
  self._validate_combinations()
48
48
 
49
- def __getitem__(self, key: str) -> Any:
49
+ def __getitem__(self, key: str) -> Any: # pylint: disable=too-many-return-statements
50
50
  if key == "head-as-boolean" and self.get("azure-arm"):
51
51
  # override to always true if azure-arm is set
52
52
  return True
@@ -61,6 +61,15 @@ class OptionsDict(MutableMapping):
61
61
  if key == "package-mode" and self._data.get("packaging-files-dir"):
62
62
  # if packaging-files-dir is set, use it as package-mode
63
63
  return self._data["packaging-files-dir"]
64
+ if key == "generation-subdir":
65
+ data = self._data.get("generation-subdir")
66
+ if data:
67
+ # Remove leading dot or ./ from generation-subdir
68
+ if data.startswith("./"):
69
+ data = data[2:]
70
+ elif data.startswith("."):
71
+ data = data[1:]
72
+ return data
64
73
  return self._get_default(key)
65
74
 
66
75
  def __setitem__(self, key: str, value: Any) -> None:
@@ -52,7 +52,10 @@ class EnumValue(BaseType):
52
52
  """The python type used for RST syntax input and type annotation."""
53
53
 
54
54
  type_annotation = self.value_type.type_annotation(**kwargs)
55
- enum_type_annotation = f"{self.enum_type.client_namespace}.models.{self.name}"
55
+ client_namespace = self.enum_type.client_namespace
56
+ if self.code_model.options.get("generation-subdir"):
57
+ client_namespace += f".{self.code_model.options['generation-subdir']}"
58
+ enum_type_annotation = f"{client_namespace}.models.{self.name}"
56
59
  return f"{type_annotation} or ~{enum_type_annotation}"
57
60
 
58
61
  def get_json_template_representation(
@@ -292,7 +292,10 @@ class GeneratedModelType(ModelType):
292
292
 
293
293
  def docstring_type(self, **kwargs: Any) -> str:
294
294
  type_annotation = self.type_annotation(need_model_alias=False, skip_quote=True, **kwargs)
295
- return f"~{self.client_namespace}.models.{type_annotation}"
295
+ client_namespace = self.client_namespace
296
+ if self.code_model.options.get("generation-subdir"):
297
+ client_namespace += f".{self.code_model.options['generation-subdir']}"
298
+ return f"~{client_namespace}.models.{type_annotation}"
296
299
 
297
300
  def docstring_text(self, **kwargs: Any) -> str:
298
301
  return self.name
@@ -7,7 +7,7 @@ import logging
7
7
  import json
8
8
  from collections import namedtuple
9
9
  import re
10
- from typing import List, Any, Union
10
+ from typing import List, Any, Union, Optional
11
11
  from pathlib import Path
12
12
  from packaging.version import parse as parse_version
13
13
  from jinja2 import PackageLoader, Environment, FileSystemLoader, StrictUndefined
@@ -165,7 +165,7 @@ class JinjaSerializer(ReaderAndWriter):
165
165
  # add _metadata.json
166
166
  if self.code_model.metadata:
167
167
  self.write_file(
168
- generation_path / Path("_metadata.json"),
168
+ Path("./_metadata.json"),
169
169
  json.dumps(self.code_model.metadata, indent=2),
170
170
  )
171
171
  elif client_namespace_type.clients:
@@ -376,8 +376,12 @@ class JinjaSerializer(ReaderAndWriter):
376
376
  def _serialize_and_write_version_file(
377
377
  self,
378
378
  general_serializer: GeneralSerializer,
379
+ namespace: Optional[str] = None,
379
380
  ):
380
- generation_path = self.code_model.get_root_dir()
381
+ if namespace:
382
+ generation_path = self.code_model.get_generation_dir(namespace)
383
+ else:
384
+ generation_path = self.code_model.get_root_dir()
381
385
 
382
386
  def _read_version_file(original_version_file_name: str) -> str:
383
387
  return self.read_file(generation_path / original_version_file_name)
@@ -472,6 +476,9 @@ class JinjaSerializer(ReaderAndWriter):
472
476
 
473
477
  # write _version.py
474
478
  self._serialize_and_write_version_file(general_serializer)
479
+ # if there's a subdir, we need to write another version file in the subdir
480
+ if self.code_model.options.get("generation-subdir"):
481
+ self._serialize_and_write_version_file(general_serializer, namespace)
475
482
 
476
483
  # write the empty py.typed file
477
484
  pytyped_value = "# Marker file for PEP 561."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.14.3-dev.1",
3
+ "version": "0.15.0",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",