@typespec/http-client-python 0.13.0-dev.3 → 0.13.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.
- package/eng/scripts/setup/__pycache__/package_manager.cpython-39.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
- package/eng/scripts/setup/build_pygen_wheel.py +1 -0
- package/eng/scripts/setup/install.py +4 -2
- package/eng/scripts/setup/package_manager.py +24 -22
- package/eng/scripts/setup/prepare.py +1 -1
- package/eng/scripts/setup/venvtools.py +1 -3
- package/generator/build/lib/pygen/codegen/models/client.py +3 -1
- package/generator/build/lib/pygen/codegen/models/operation_group.py +8 -2
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +2 -1
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -1
- package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +2 -0
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/client.py +3 -1
- package/generator/pygen/codegen/models/operation_group.py +8 -2
- package/generator/pygen/codegen/serializers/client_serializer.py +2 -1
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -1
- package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +2 -0
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
@@ -12,6 +12,7 @@ if not sys.version_info >= (3, 9, 0):
|
|
|
12
12
|
|
|
13
13
|
try:
|
|
14
14
|
from package_manager import detect_package_manager, PackageManagerNotFoundError
|
|
15
|
+
|
|
15
16
|
detect_package_manager() # Just check if we have a package manager
|
|
16
17
|
except (ImportError, ModuleNotFoundError, PackageManagerNotFoundError):
|
|
17
18
|
raise Exception("Your Python installation doesn't have a suitable package manager (pip or uv) available")
|
|
@@ -14,6 +14,7 @@ if not sys.version_info >= (3, 9, 0):
|
|
|
14
14
|
|
|
15
15
|
try:
|
|
16
16
|
from package_manager import detect_package_manager, PackageManagerNotFoundError
|
|
17
|
+
|
|
17
18
|
detect_package_manager() # Just check if we have a package manager
|
|
18
19
|
except (ImportError, ModuleNotFoundError, PackageManagerNotFoundError):
|
|
19
20
|
raise Warning(
|
|
@@ -37,11 +38,12 @@ _ROOT_DIR = Path(__file__).parent.parent.parent.parent
|
|
|
37
38
|
|
|
38
39
|
def main():
|
|
39
40
|
venv_path = _ROOT_DIR / "venv"
|
|
40
|
-
|
|
41
|
+
|
|
41
42
|
# Create virtual environment using package manager abstraction
|
|
42
43
|
from package_manager import create_venv_with_package_manager, install_packages
|
|
44
|
+
|
|
43
45
|
venv_context = create_venv_with_package_manager(venv_path)
|
|
44
|
-
|
|
46
|
+
|
|
45
47
|
# Install required packages - install_packages handles package manager logic
|
|
46
48
|
install_packages(["-U", "black"], venv_context)
|
|
47
49
|
install_packages(["-e", f"{_ROOT_DIR}/generator"], venv_context)
|
|
@@ -16,6 +16,7 @@ from venvtools import ExtendedEnvBuilder
|
|
|
16
16
|
|
|
17
17
|
class PackageManagerNotFoundError(Exception):
|
|
18
18
|
"""Raised when no suitable package manager is found."""
|
|
19
|
+
|
|
19
20
|
pass
|
|
20
21
|
|
|
21
22
|
|
|
@@ -30,41 +31,38 @@ def _check_command_available(command: str) -> bool:
|
|
|
30
31
|
|
|
31
32
|
def detect_package_manager() -> str:
|
|
32
33
|
"""Detect the best available package manager.
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
Returns:
|
|
35
36
|
str: The package manager command ('uv' or 'pip')
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
Raises:
|
|
38
39
|
PackageManagerNotFoundError: If no suitable package manager is found
|
|
39
40
|
"""
|
|
40
41
|
# Check for uv first since it's more modern and faster
|
|
41
42
|
if _check_command_available("uv"):
|
|
42
43
|
return "uv"
|
|
43
|
-
|
|
44
|
+
|
|
44
45
|
# Fall back to pip
|
|
45
46
|
if _check_command_available("pip"):
|
|
46
47
|
return "pip"
|
|
47
|
-
|
|
48
|
+
|
|
48
49
|
# As a last resort, try using python -m pip
|
|
49
50
|
try:
|
|
50
|
-
subprocess.run([sys.executable, "-m", "pip", "--version"],
|
|
51
|
-
capture_output=True, check=True)
|
|
51
|
+
subprocess.run([sys.executable, "-m", "pip", "--version"], capture_output=True, check=True)
|
|
52
52
|
return "python -m pip"
|
|
53
53
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
54
54
|
pass
|
|
55
|
-
|
|
56
|
-
raise PackageManagerNotFoundError(
|
|
57
|
-
"No suitable package manager found. Please install either uv or pip."
|
|
58
|
-
)
|
|
55
|
+
|
|
56
|
+
raise PackageManagerNotFoundError("No suitable package manager found. Please install either uv or pip.")
|
|
59
57
|
|
|
60
58
|
|
|
61
59
|
def get_install_command(package_manager: str, venv_context=None) -> list:
|
|
62
60
|
"""Get the install command for the given package manager.
|
|
63
|
-
|
|
61
|
+
|
|
64
62
|
Args:
|
|
65
63
|
package_manager: The package manager command ('uv', 'pip', or 'python -m pip')
|
|
66
64
|
venv_context: The virtual environment context (optional, used for pip)
|
|
67
|
-
|
|
65
|
+
|
|
68
66
|
Returns:
|
|
69
67
|
list: The base install command as a list
|
|
70
68
|
"""
|
|
@@ -89,7 +87,7 @@ def get_install_command(package_manager: str, venv_context=None) -> list:
|
|
|
89
87
|
|
|
90
88
|
def install_packages(packages: list, venv_context=None, package_manager: str = None) -> None:
|
|
91
89
|
"""Install packages using the available package manager.
|
|
92
|
-
|
|
90
|
+
|
|
93
91
|
Args:
|
|
94
92
|
packages: List of packages to install
|
|
95
93
|
venv_context: Virtual environment context (optional)
|
|
@@ -97,9 +95,9 @@ def install_packages(packages: list, venv_context=None, package_manager: str = N
|
|
|
97
95
|
"""
|
|
98
96
|
if package_manager is None:
|
|
99
97
|
package_manager = detect_package_manager()
|
|
100
|
-
|
|
98
|
+
|
|
101
99
|
install_cmd = get_install_command(package_manager, venv_context)
|
|
102
|
-
|
|
100
|
+
|
|
103
101
|
try:
|
|
104
102
|
subprocess.check_call(install_cmd + packages)
|
|
105
103
|
except subprocess.CalledProcessError as e:
|
|
@@ -108,25 +106,29 @@ def install_packages(packages: list, venv_context=None, package_manager: str = N
|
|
|
108
106
|
|
|
109
107
|
def create_venv_with_package_manager(venv_path):
|
|
110
108
|
"""Create virtual environment using the best available package manager.
|
|
111
|
-
|
|
109
|
+
|
|
112
110
|
Args:
|
|
113
111
|
venv_path: Path where to create the virtual environment
|
|
114
|
-
|
|
112
|
+
|
|
115
113
|
Returns:
|
|
116
114
|
venv_context: Virtual environment context object
|
|
117
115
|
"""
|
|
118
116
|
package_manager = detect_package_manager()
|
|
119
|
-
|
|
117
|
+
|
|
120
118
|
if package_manager == "uv":
|
|
121
119
|
# Use uv to create and manage the virtual environment
|
|
122
120
|
if not venv_path.exists():
|
|
123
121
|
subprocess.check_call(["uv", "venv", str(venv_path)])
|
|
124
|
-
|
|
122
|
+
|
|
125
123
|
# Create a mock venv_context for compatibility
|
|
126
124
|
class MockVenvContext:
|
|
127
125
|
def __init__(self, venv_path):
|
|
128
|
-
self.env_exe =
|
|
129
|
-
|
|
126
|
+
self.env_exe = (
|
|
127
|
+
str(venv_path / "bin" / "python")
|
|
128
|
+
if sys.platform != "win32"
|
|
129
|
+
else str(venv_path / "Scripts" / "python.exe")
|
|
130
|
+
)
|
|
131
|
+
|
|
130
132
|
return MockVenvContext(venv_path)
|
|
131
133
|
else:
|
|
132
134
|
# Use standard venv for pip
|
|
@@ -136,4 +138,4 @@ def create_venv_with_package_manager(venv_path):
|
|
|
136
138
|
else:
|
|
137
139
|
env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True)
|
|
138
140
|
env_builder.create(venv_path)
|
|
139
|
-
return env_builder.context
|
|
141
|
+
return env_builder.context
|
|
@@ -25,7 +25,7 @@ def main():
|
|
|
25
25
|
assert venv_preexists # Otherwise install was not done
|
|
26
26
|
|
|
27
27
|
venv_context = create_venv_with_package_manager(venv_path)
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
try:
|
|
30
30
|
install_packages(["-r", f"{_ROOT_DIR}/generator/dev_requirements.txt"], venv_context)
|
|
31
31
|
except FileNotFoundError as e:
|
|
@@ -29,12 +29,10 @@ class ExtendedEnvBuilder(venv.EnvBuilder):
|
|
|
29
29
|
return self.context
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
32
|
def python_run(venv_context, module, command=None, *, additional_dir="."):
|
|
35
33
|
try:
|
|
36
34
|
cmd_line = [venv_context.env_exe, "-m", module] + (command if command else [])
|
|
37
|
-
|
|
35
|
+
|
|
38
36
|
print("Executing: {}".format(" ".join(cmd_line)))
|
|
39
37
|
subprocess.run(
|
|
40
38
|
cmd_line,
|
|
@@ -322,11 +322,13 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
322
322
|
)
|
|
323
323
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
324
324
|
for og in self.operation_groups:
|
|
325
|
+
suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
|
|
325
326
|
file_import.add_submodule_import(
|
|
326
327
|
self.code_model.get_relative_import_path(
|
|
327
328
|
serialize_namespace,
|
|
328
329
|
self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
|
|
329
|
-
)
|
|
330
|
+
)
|
|
331
|
+
+ suffix,
|
|
330
332
|
og.class_name,
|
|
331
333
|
ImportType.LOCAL,
|
|
332
334
|
)
|
|
@@ -34,7 +34,6 @@ class OperationGroup(BaseModel):
|
|
|
34
34
|
) -> None:
|
|
35
35
|
super().__init__(yaml_data, code_model)
|
|
36
36
|
self.client = client
|
|
37
|
-
self.class_name: str = yaml_data["className"]
|
|
38
37
|
self.identify_name: str = yaml_data["identifyName"]
|
|
39
38
|
self.property_name: str = yaml_data["propertyName"]
|
|
40
39
|
self.operations = operations
|
|
@@ -51,6 +50,13 @@ class OperationGroup(BaseModel):
|
|
|
51
50
|
for og in self.operation_groups:
|
|
52
51
|
og.has_parent_operation_group = True
|
|
53
52
|
|
|
53
|
+
@property
|
|
54
|
+
def class_name(self) -> str:
|
|
55
|
+
"""The class name of the operation group."""
|
|
56
|
+
if self.is_mixin and not self.code_model.options["multiapi"]:
|
|
57
|
+
return "_" + self.yaml_data["className"]
|
|
58
|
+
return self.yaml_data["className"]
|
|
59
|
+
|
|
54
60
|
@property
|
|
55
61
|
def has_abstract_operations(self) -> bool:
|
|
56
62
|
return any(o for o in self.operations if o.abstract) or any(
|
|
@@ -89,7 +95,7 @@ class OperationGroup(BaseModel):
|
|
|
89
95
|
retval = add_to_pylint_disable(retval, "abstract-class-instantiated")
|
|
90
96
|
if len(self.operations) > 20:
|
|
91
97
|
retval = add_to_pylint_disable(retval, "too-many-public-methods")
|
|
92
|
-
if len(self.class_name) > NAME_LENGTH_LIMIT:
|
|
98
|
+
if len(self.class_name) > NAME_LENGTH_LIMIT and self.class_name[0] != "_":
|
|
93
99
|
retval = add_to_pylint_disable(retval, "name-too-long")
|
|
94
100
|
if len(self.operation_groups) > 6:
|
|
95
101
|
retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
|
|
@@ -50,7 +50,8 @@ class ClientSerializer:
|
|
|
50
50
|
class_name = self.client.name
|
|
51
51
|
base_class = ""
|
|
52
52
|
if self.client.has_mixin:
|
|
53
|
-
|
|
53
|
+
prefix = "" if self.client.code_model.options["multiapi"] else "_"
|
|
54
|
+
base_class = f"{prefix}{class_name}OperationsMixin"
|
|
54
55
|
pylint_disable = self.client.pylint_disable()
|
|
55
56
|
if base_class:
|
|
56
57
|
return f"class {class_name}({base_class}):{pylint_disable}"
|
|
@@ -26,7 +26,11 @@ class OperationsInitSerializer:
|
|
|
26
26
|
def _get_filename(operation_group: OperationGroup) -> str:
|
|
27
27
|
return "_operations" if self.code_model.options["combine-operation-files"] else operation_group.filename
|
|
28
28
|
|
|
29
|
-
return [
|
|
29
|
+
return [
|
|
30
|
+
f"from .{_get_filename(og)} import {og.class_name} # type: ignore"
|
|
31
|
+
for og in self.operation_groups
|
|
32
|
+
if not og.is_mixin or self.code_model.options["multiapi"]
|
|
33
|
+
]
|
|
30
34
|
|
|
31
35
|
def serialize(self) -> str:
|
|
32
36
|
operation_group_init_template = self.env.get_template("operations_folder_init.py.jinja2")
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
{{ keywords.patch_imports() }}
|
|
11
11
|
__all__ = [
|
|
12
12
|
{% for operation_group in operation_groups %}
|
|
13
|
+
{% if not operation_group.is_mixin or code_model.options["multiapi"] %}
|
|
13
14
|
'{{ operation_group.class_name }}',
|
|
15
|
+
{% endif %}
|
|
14
16
|
{% endfor %}
|
|
15
17
|
]
|
|
16
18
|
{{ keywords.extend_all }}
|
|
Binary file
|
|
@@ -322,11 +322,13 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
|
|
|
322
322
|
)
|
|
323
323
|
serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
|
|
324
324
|
for og in self.operation_groups:
|
|
325
|
+
suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
|
|
325
326
|
file_import.add_submodule_import(
|
|
326
327
|
self.code_model.get_relative_import_path(
|
|
327
328
|
serialize_namespace,
|
|
328
329
|
self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
|
|
329
|
-
)
|
|
330
|
+
)
|
|
331
|
+
+ suffix,
|
|
330
332
|
og.class_name,
|
|
331
333
|
ImportType.LOCAL,
|
|
332
334
|
)
|
|
@@ -34,7 +34,6 @@ class OperationGroup(BaseModel):
|
|
|
34
34
|
) -> None:
|
|
35
35
|
super().__init__(yaml_data, code_model)
|
|
36
36
|
self.client = client
|
|
37
|
-
self.class_name: str = yaml_data["className"]
|
|
38
37
|
self.identify_name: str = yaml_data["identifyName"]
|
|
39
38
|
self.property_name: str = yaml_data["propertyName"]
|
|
40
39
|
self.operations = operations
|
|
@@ -51,6 +50,13 @@ class OperationGroup(BaseModel):
|
|
|
51
50
|
for og in self.operation_groups:
|
|
52
51
|
og.has_parent_operation_group = True
|
|
53
52
|
|
|
53
|
+
@property
|
|
54
|
+
def class_name(self) -> str:
|
|
55
|
+
"""The class name of the operation group."""
|
|
56
|
+
if self.is_mixin and not self.code_model.options["multiapi"]:
|
|
57
|
+
return "_" + self.yaml_data["className"]
|
|
58
|
+
return self.yaml_data["className"]
|
|
59
|
+
|
|
54
60
|
@property
|
|
55
61
|
def has_abstract_operations(self) -> bool:
|
|
56
62
|
return any(o for o in self.operations if o.abstract) or any(
|
|
@@ -89,7 +95,7 @@ class OperationGroup(BaseModel):
|
|
|
89
95
|
retval = add_to_pylint_disable(retval, "abstract-class-instantiated")
|
|
90
96
|
if len(self.operations) > 20:
|
|
91
97
|
retval = add_to_pylint_disable(retval, "too-many-public-methods")
|
|
92
|
-
if len(self.class_name) > NAME_LENGTH_LIMIT:
|
|
98
|
+
if len(self.class_name) > NAME_LENGTH_LIMIT and self.class_name[0] != "_":
|
|
93
99
|
retval = add_to_pylint_disable(retval, "name-too-long")
|
|
94
100
|
if len(self.operation_groups) > 6:
|
|
95
101
|
retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
|
|
@@ -50,7 +50,8 @@ class ClientSerializer:
|
|
|
50
50
|
class_name = self.client.name
|
|
51
51
|
base_class = ""
|
|
52
52
|
if self.client.has_mixin:
|
|
53
|
-
|
|
53
|
+
prefix = "" if self.client.code_model.options["multiapi"] else "_"
|
|
54
|
+
base_class = f"{prefix}{class_name}OperationsMixin"
|
|
54
55
|
pylint_disable = self.client.pylint_disable()
|
|
55
56
|
if base_class:
|
|
56
57
|
return f"class {class_name}({base_class}):{pylint_disable}"
|
|
@@ -26,7 +26,11 @@ class OperationsInitSerializer:
|
|
|
26
26
|
def _get_filename(operation_group: OperationGroup) -> str:
|
|
27
27
|
return "_operations" if self.code_model.options["combine-operation-files"] else operation_group.filename
|
|
28
28
|
|
|
29
|
-
return [
|
|
29
|
+
return [
|
|
30
|
+
f"from .{_get_filename(og)} import {og.class_name} # type: ignore"
|
|
31
|
+
for og in self.operation_groups
|
|
32
|
+
if not og.is_mixin or self.code_model.options["multiapi"]
|
|
33
|
+
]
|
|
30
34
|
|
|
31
35
|
def serialize(self) -> str:
|
|
32
36
|
operation_group_init_template = self.env.get_template("operations_folder_init.py.jinja2")
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
{{ keywords.patch_imports() }}
|
|
11
11
|
__all__ = [
|
|
12
12
|
{% for operation_group in operation_groups %}
|
|
13
|
+
{% if not operation_group.is_mixin or code_model.options["multiapi"] %}
|
|
13
14
|
'{{ operation_group.class_name }}',
|
|
15
|
+
{% endif %}
|
|
14
16
|
{% endfor %}
|
|
15
17
|
]
|
|
16
18
|
{{ keywords.extend_all }}
|