@autorest/python 5.12.6 → 5.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.
Files changed (69) hide show
  1. package/ChangeLog.md +205 -125
  2. package/autorest/black/__init__.py +3 -0
  3. package/autorest/codegen/__init__.py +120 -48
  4. package/autorest/codegen/models/__init__.py +2 -1
  5. package/autorest/codegen/models/base_schema.py +2 -6
  6. package/autorest/codegen/models/client.py +6 -0
  7. package/autorest/codegen/models/code_model.py +43 -74
  8. package/autorest/codegen/models/constant_schema.py +7 -7
  9. package/autorest/codegen/models/credential_model.py +47 -0
  10. package/autorest/codegen/models/credential_schema.py +5 -4
  11. package/autorest/codegen/models/dictionary_schema.py +7 -7
  12. package/autorest/codegen/models/enum_schema.py +8 -39
  13. package/autorest/codegen/models/imports.py +3 -1
  14. package/autorest/codegen/models/list_schema.py +18 -8
  15. package/autorest/codegen/models/lro_operation.py +3 -3
  16. package/autorest/codegen/models/lro_paging_operation.py +3 -3
  17. package/autorest/codegen/models/object_schema.py +17 -13
  18. package/autorest/codegen/models/operation.py +38 -10
  19. package/autorest/codegen/models/operation_group.py +7 -2
  20. package/autorest/codegen/models/paging_operation.py +3 -3
  21. package/autorest/codegen/models/parameter.py +71 -22
  22. package/autorest/codegen/models/parameter_list.py +11 -5
  23. package/autorest/codegen/models/primitive_schemas.py +15 -25
  24. package/autorest/codegen/models/property.py +5 -5
  25. package/autorest/codegen/models/request_builder.py +4 -4
  26. package/autorest/codegen/models/request_builder_parameter.py +17 -5
  27. package/autorest/codegen/models/schema_response.py +23 -10
  28. package/autorest/codegen/models/utils.py +20 -0
  29. package/autorest/codegen/serializers/__init__.py +184 -87
  30. package/autorest/codegen/serializers/builder_serializer.py +113 -47
  31. package/autorest/codegen/serializers/client_serializer.py +16 -6
  32. package/autorest/codegen/serializers/general_serializer.py +28 -4
  33. package/autorest/codegen/serializers/import_serializer.py +1 -1
  34. package/autorest/codegen/serializers/metadata_serializer.py +1 -1
  35. package/autorest/codegen/serializers/model_base_serializer.py +8 -0
  36. package/autorest/codegen/serializers/model_python3_serializer.py +2 -2
  37. package/autorest/codegen/serializers/operation_groups_serializer.py +1 -0
  38. package/autorest/codegen/serializers/patch_serializer.py +12 -3
  39. package/autorest/codegen/serializers/utils.py +29 -4
  40. package/autorest/codegen/templates/CHANGELOG.md.jinja2 +6 -0
  41. package/autorest/codegen/templates/LICENSE.jinja2 +21 -0
  42. package/autorest/codegen/templates/MANIFEST.in.jinja2 +7 -0
  43. package/autorest/codegen/templates/README.md.jinja2 +105 -0
  44. package/autorest/codegen/templates/config.py.jinja2 +4 -4
  45. package/autorest/codegen/templates/dev_requirements.txt.jinja2 +10 -0
  46. package/autorest/codegen/templates/enum.py.jinja2 +1 -1
  47. package/autorest/codegen/templates/enum_container.py.jinja2 +0 -1
  48. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  49. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  50. package/autorest/codegen/templates/lro_operation.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +1 -1
  52. package/autorest/codegen/templates/metadata.json.jinja2 +3 -3
  53. package/autorest/codegen/templates/model.py.jinja2 +1 -6
  54. package/autorest/codegen/templates/model_init.py.jinja2 +7 -4
  55. package/autorest/codegen/templates/operation.py.jinja2 +2 -3
  56. package/autorest/codegen/templates/operation_group.py.jinja2 +20 -17
  57. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +0 -1
  58. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  59. package/autorest/codegen/templates/paging_operation.py.jinja2 +1 -1
  60. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  61. package/autorest/codegen/templates/request_builder.py.jinja2 +4 -6
  62. package/autorest/codegen/templates/setup.py.jinja2 +79 -20
  63. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  64. package/autorest/multiapi/models/imports.py +21 -11
  65. package/autorest/multiapi/serializers/import_serializer.py +3 -1
  66. package/autorest/namer/name_converter.py +1 -1
  67. package/package.json +2 -2
  68. package/run-python3.js +1 -7
  69. package/venvtools.py +2 -2
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from enum import Enum
7
- from typing import Dict, Optional, Set
7
+ from typing import Dict, Optional, Set, Union, Tuple
8
8
 
9
9
 
10
10
  class ImportType(str, Enum):
@@ -21,29 +21,39 @@ class TypingSection(str, Enum):
21
21
 
22
22
  class FileImport:
23
23
  def __init__(
24
- self, imports: Dict[TypingSection, Dict[ImportType, Dict[str, Set[Optional[str]]]]] = None
24
+ self,
25
+ imports: Dict[
26
+ TypingSection, Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
27
+ ] = None
25
28
  ) -> None:
26
29
  # Basic implementation
27
30
  # First level dict: TypingSection
28
31
  # Second level dict: ImportType
29
32
  # Third level dict: the package name.
30
33
  # Fourth level set: None if this import is a "import", the name to import if it's a "from"
31
- self._imports: Dict[TypingSection, Dict[ImportType, Dict[str, Set[Optional[str]]]]] = imports or dict()
34
+ self._imports: Dict[
35
+ TypingSection, Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
36
+ ] = imports or dict()
32
37
 
33
38
  def _add_import(
34
39
  self,
35
40
  from_section: str,
36
41
  import_type: ImportType,
37
- name_import: Optional[str] = None,
42
+ name_import: Optional[Union[str, Tuple[str, str]]] = None,
38
43
  typing_section: TypingSection = TypingSection.REGULAR
39
44
  ) -> None:
45
+ name_input: Optional[Union[str, Tuple[str, str]]] = None
46
+ if isinstance(name_import, list):
47
+ name_input = tuple(name_import)
48
+ else:
49
+ name_input = name_import
40
50
  self._imports.setdefault(
41
- typing_section, dict()
42
- ).setdefault(
43
- import_type, dict()
44
- ).setdefault(
45
- from_section, set()
46
- ).add(name_import)
51
+ typing_section, dict()
52
+ ).setdefault(
53
+ import_type, dict()
54
+ ).setdefault(
55
+ from_section, set()
56
+ ).add(name_input)
47
57
 
48
58
  def add_submodule_import(
49
59
  self,
@@ -66,7 +76,7 @@ class FileImport:
66
76
  self._add_import(name_import, import_type, None, typing_section)
67
77
 
68
78
  @property
69
- def imports(self) -> Dict[TypingSection, Dict[ImportType, Dict[str, Set[Optional[str]]]]]:
79
+ def imports(self) -> Dict[TypingSection, Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]]:
70
80
  return self._imports
71
81
 
72
82
  def merge(self, file_import: "FileImport") -> None:
@@ -14,7 +14,9 @@ def _serialize_package(package_name: str, module_list: Set[Optional[str]], delim
14
14
  if module_list != {None}:
15
15
  buffer.append(
16
16
  "from {} import {}".format(
17
- package_name, ", ".join(sorted([mod for mod in module_list if mod is not None]))
17
+ package_name, ", ".join(sorted([
18
+ mod if isinstance(mod, str) else f"{mod[0]} as {mod[1]}" for mod in module_list if mod is not None
19
+ ]))
18
20
  )
19
21
  )
20
22
  return delimiter.join(buffer)
@@ -373,7 +373,7 @@ class NameConverter:
373
373
  # check to see if name is reserved for the type of name we are converting
374
374
  pad_string = cast(PadType, pad_string)
375
375
  # there are some private variables, such as grouped parameters
376
- # that are private. We still want to escape them for LLC
376
+ # that are private. We still want to escape them for DPG
377
377
  name_prefix = ""
378
378
  if name[0] == "_":
379
379
  # i am private
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "5.12.6",
3
+ "version": "5.15.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "scripts": {
6
6
  "prepare": "node run-python3.js prepare.py",
@@ -27,7 +27,7 @@
27
27
  "@azure-tools/extension": "~3.2.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@microsoft.azure/autorest.testserver": "^3.1.13"
30
+ "@microsoft.azure/autorest.testserver": "3.3.23"
31
31
  },
32
32
  "files": [
33
33
  "autorest/**/*.py",
package/run-python3.js CHANGED
@@ -18,12 +18,6 @@ async function runPython3(scriptName, debug = "") {
18
18
  }
19
19
 
20
20
  runPython3(...process.argv.slice(2)).catch(err => {
21
- const error = err.toString();
22
-
23
- // Python script errors are already written out via stderr so don't
24
- // write them twice. Write out all other errors to stderr.
25
- if (!error.startsWith("Error: Command failed")) {
26
- console.error(error);
27
- }
21
+ console.error(err.toString());
28
22
  process.exit(1);
29
23
  });
package/venvtools.py CHANGED
@@ -62,13 +62,13 @@ def python_run(venv_context, module, command=None, *, additional_dir=".", error_
62
62
  venv_context.env_exe,
63
63
  "-m", module
64
64
  ] + (command if command else [])
65
- print("Executing: {}".format(" ".join(cmd_line)), file=sys.stderr)
65
+ print("Executing: {}".format(" ".join(cmd_line)))
66
66
  subprocess.run(
67
67
  cmd_line,
68
68
  cwd=_ROOT_DIR / additional_dir,
69
69
  check=True,
70
70
  )
71
71
  except subprocess.CalledProcessError as err:
72
- print(err, file=sys.stderr)
72
+ print(err)
73
73
  if not error_ok:
74
74
  sys.exit(1)