@typespec/http-client-python 0.12.5 → 0.13.0-dev.1

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 (33) hide show
  1. package/dist/emitter/types.d.ts.map +1 -1
  2. package/dist/emitter/types.js +5 -12
  3. package/dist/emitter/types.js.map +1 -1
  4. package/emitter/src/types.ts +7 -14
  5. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  6. package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
  7. package/eng/scripts/setup/build_pygen_wheel.py +10 -9
  8. package/eng/scripts/setup/install.py +17 -13
  9. package/eng/scripts/setup/prepare.py +12 -4
  10. package/eng/scripts/setup/venvtools.py +42 -1
  11. package/generator/build/lib/pygen/codegen/models/property.py +0 -6
  12. package/generator/build/lib/pygen/codegen/templates/packaging_templates/README.md.jinja2 +0 -31
  13. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  14. package/generator/pygen/codegen/models/property.py +0 -6
  15. package/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +0 -31
  16. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_commonproperties_async.py +0 -31
  17. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py +0 -9
  18. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_usage_async.py +0 -7
  19. package/generator/test/azure/mock_api_tests/test_azure_arm_commonproperties.py +0 -29
  20. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_client_initialization.py +0 -8
  21. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_usage.py +0 -4
  22. package/generator/test/azure/requirements.txt +0 -4
  23. package/package.json +1 -1
  24. package/eng/scripts/setup/__pycache__/package_manager.cpython-39.pyc +0 -0
  25. package/eng/scripts/setup/package_manager.py +0 -139
  26. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_largeheader_async.py +0 -30
  27. package/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_nonresource_async.py +0 -36
  28. package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_deserialize_empty_string_as_null_async.py +0 -20
  29. package/generator/test/azure/mock_api_tests/asynctests/test_azure_encode_duration_async.py +0 -19
  30. package/generator/test/azure/mock_api_tests/test_azure_arm_largeheader.py +0 -27
  31. package/generator/test/azure/mock_api_tests/test_azure_arm_nonresource.py +0 -34
  32. package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_deserialize_empty_string_as_null.py +0 -19
  33. package/generator/test/azure/mock_api_tests/test_azure_encode_duration.py +0 -18
@@ -11,27 +11,28 @@ if not sys.version_info >= (3, 9, 0):
11
11
  raise Exception("Autorest for Python extension requires Python 3.9 at least")
12
12
 
13
13
  try:
14
- from package_manager import detect_package_manager, PackageManagerNotFoundError
15
- detect_package_manager() # Just check if we have a package manager
16
- except (ImportError, ModuleNotFoundError, PackageManagerNotFoundError):
17
- raise Exception("Your Python installation doesn't have a suitable package manager (pip or uv) available")
14
+ import pip
15
+ except (ImportError, ModuleNotFoundError):
16
+ raise Exception("Your Python installation doesn't have pip available")
18
17
 
19
18
 
20
- # Now we have a package manager (pip or uv) and Py >= 3.9, go to work
19
+ # Now we have pip and Py >= 3.9, go to work
21
20
 
22
21
  from pathlib import Path
23
22
 
24
- from venvtools import python_run
25
- from package_manager import install_packages, create_venv_with_package_manager
23
+ from venvtools import ExtendedEnvBuilder, python_run
26
24
 
27
25
  _ROOT_DIR = Path(__file__).parent.parent.parent.parent
28
26
 
29
27
 
30
28
  def main():
31
29
  venv_path = _ROOT_DIR / "venv_build_wheel"
32
- venv_context = create_venv_with_package_manager(venv_path)
30
+ env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True)
31
+ env_builder.create(venv_path)
32
+ venv_context = env_builder.context
33
33
 
34
- install_packages(["build"], venv_context)
34
+ python_run(venv_context, "pip", ["install", "-U", "pip"])
35
+ python_run(venv_context, "pip", ["install", "build"])
35
36
  python_run(venv_context, "build", ["--wheel"], additional_dir="generator")
36
37
 
37
38
 
@@ -13,11 +13,10 @@ if not sys.version_info >= (3, 9, 0):
13
13
  )
14
14
 
15
15
  try:
16
- from package_manager import detect_package_manager, PackageManagerNotFoundError
17
- detect_package_manager() # Just check if we have a package manager
18
- except (ImportError, ModuleNotFoundError, PackageManagerNotFoundError):
16
+ import pip
17
+ except (ImportError, ModuleNotFoundError):
19
18
  raise Warning(
20
- "Your Python installation doesn't have a suitable package manager (pip or uv) available. We will run your code with Pyodide since your Python environment isn't adequate."
19
+ "Your Python installation doesn't have pip available. We will run your code with Pyodide since your Python version isn't adequate."
21
20
  )
22
21
 
23
22
  try:
@@ -28,23 +27,28 @@ except (ImportError, ModuleNotFoundError):
28
27
  )
29
28
 
30
29
 
31
- # Now we have a package manager (uv or pip) and Py >= 3.8, go to work
30
+ # Now we have pip and Py >= 3.8, go to work
32
31
 
33
32
  from pathlib import Path
34
33
 
34
+ from venvtools import ExtendedEnvBuilder, python_run
35
+
35
36
  _ROOT_DIR = Path(__file__).parent.parent.parent.parent
36
37
 
37
38
 
38
39
  def main():
39
40
  venv_path = _ROOT_DIR / "venv"
40
-
41
- # Create virtual environment using package manager abstraction
42
- from package_manager import create_venv_with_package_manager, install_packages
43
- venv_context = create_venv_with_package_manager(venv_path)
44
-
45
- # Install required packages - install_packages handles package manager logic
46
- install_packages(["-U", "black"], venv_context)
47
- install_packages(["-e", f"{_ROOT_DIR}/generator"], venv_context)
41
+ if venv_path.exists():
42
+ env_builder = venv.EnvBuilder(with_pip=True)
43
+ venv_context = env_builder.ensure_directories(venv_path)
44
+ else:
45
+ env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True)
46
+ env_builder.create(venv_path)
47
+ venv_context = env_builder.context
48
+
49
+ python_run(venv_context, "pip", ["install", "-U", "pip"])
50
+ python_run(venv_context, "pip", ["install", "-U", "black"])
51
+ python_run(venv_context, "pip", ["install", "-e", f"{_ROOT_DIR}/generator"])
48
52
 
49
53
 
50
54
  if __name__ == "__main__":
@@ -6,6 +6,8 @@
6
6
  # license information.
7
7
  # --------------------------------------------------------------------------
8
8
  import sys
9
+ import os
10
+ import argparse
9
11
 
10
12
  if not sys.version_info >= (3, 9, 0):
11
13
  raise Warning(
@@ -13,7 +15,9 @@ if not sys.version_info >= (3, 9, 0):
13
15
  )
14
16
 
15
17
  from pathlib import Path
16
- from package_manager import create_venv_with_package_manager, install_packages
18
+ import venv
19
+
20
+ from venvtools import python_run
17
21
 
18
22
  _ROOT_DIR = Path(__file__).parent.parent.parent.parent
19
23
 
@@ -24,10 +28,14 @@ def main():
24
28
 
25
29
  assert venv_preexists # Otherwise install was not done
26
30
 
27
- venv_context = create_venv_with_package_manager(venv_path)
28
-
31
+ env_builder = venv.EnvBuilder(with_pip=True)
32
+ venv_context = env_builder.ensure_directories(venv_path)
29
33
  try:
30
- install_packages(["-r", f"{_ROOT_DIR}/generator/dev_requirements.txt"], venv_context)
34
+ python_run(
35
+ venv_context,
36
+ "pip",
37
+ ["install", "-r", f"{_ROOT_DIR}/generator/dev_requirements.txt"],
38
+ )
31
39
  except FileNotFoundError as e:
32
40
  raise ValueError(e.filename)
33
41
 
@@ -3,6 +3,8 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ from contextlib import contextmanager
7
+ import tempfile
6
8
  import subprocess
7
9
  import venv
8
10
  import sys
@@ -29,12 +31,51 @@ class ExtendedEnvBuilder(venv.EnvBuilder):
29
31
  return self.context
30
32
 
31
33
 
34
+ def create(
35
+ env_dir,
36
+ system_site_packages=False,
37
+ clear=False,
38
+ symlinks=False,
39
+ with_pip=False,
40
+ prompt=None,
41
+ upgrade_deps=False,
42
+ ):
43
+ """Create a virtual environment in a directory."""
44
+ builder = ExtendedEnvBuilder(
45
+ system_site_packages=system_site_packages,
46
+ clear=clear,
47
+ symlinks=symlinks,
48
+ with_pip=with_pip,
49
+ prompt=prompt,
50
+ upgrade_deps=upgrade_deps,
51
+ )
52
+ builder.create(env_dir)
53
+ return builder.context
54
+
55
+
56
+ @contextmanager
57
+ def create_venv_with_package(packages):
58
+ """Create a venv with these packages in a temp dir and yield the env.
59
+
60
+ packages should be an iterable of pip version instruction (e.g. package~=1.2.3)
61
+ """
62
+ with tempfile.TemporaryDirectory() as tempdir:
63
+ my_env = create(tempdir, with_pip=True, upgrade_deps=True)
64
+ pip_call = [
65
+ my_env.env_exe,
66
+ "-m",
67
+ "pip",
68
+ "install",
69
+ ]
70
+ subprocess.check_call(pip_call + ["-U", "pip"])
71
+ if packages:
72
+ subprocess.check_call(pip_call + packages)
73
+ yield my_env
32
74
 
33
75
 
34
76
  def python_run(venv_context, module, command=None, *, additional_dir="."):
35
77
  try:
36
78
  cmd_line = [venv_context.env_exe, "-m", module] + (command if command else [])
37
-
38
79
  print("Executing: {}".format(" ".join(cmd_line)))
39
80
  subprocess.run(
40
81
  cmd_line,
@@ -87,17 +87,11 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
87
87
  def is_enum_discriminator(self) -> bool:
88
88
  return self.is_discriminator and self.type.type == "enum"
89
89
 
90
- @property
91
- def is_combined_discriminator(self) -> bool:
92
- return self.is_discriminator and self.type.type == "combined"
93
-
94
90
  @property
95
91
  def is_base_discriminator(self) -> bool:
96
92
  """If this discriminator is on the base model for polymorphic inheritance"""
97
93
  if self.is_enum_discriminator:
98
94
  return self.is_polymorphic and self.client_default_value is None
99
- if self.is_combined_discriminator:
100
- return True
101
95
  return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
102
96
 
103
97
  @property
@@ -104,35 +104,4 @@ additional questions or comments.
104
104
  [pip]: https://pypi.org/project/pip/
105
105
  [azure_sub]: https://azure.microsoft.com/free/
106
106
  {% endif %}
107
- {% else %}
108
- # Overview
109
-
110
- This package is generated by `@typespec/http-client-python` with Typespec.
111
-
112
- ## Getting started
113
-
114
- ### Prequisites
115
-
116
- - Python 3.9 or later is required to use this package.
117
-
118
- ### Install the package
119
-
120
- Step into folder where setup.py is then run:
121
-
122
- ```bash
123
- pip install -e .
124
- ```
125
-
126
- ### Examples
127
-
128
- ```python
129
- >>> from {{ code_model.namespace }} import {{ client_name }}
130
- >>> from {{ code_model.core_library }}.exceptions import HttpResponseError
131
-
132
- >>> client = {{ client_name }}(endpoint='<endpoint>')
133
- >>> try:
134
- <!-- write code here -->
135
- except HttpResponseError as e:
136
- print('service responds error: {}'.format(e.response.json()))
137
- ```
138
107
  {% endif %}
@@ -87,17 +87,11 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
87
87
  def is_enum_discriminator(self) -> bool:
88
88
  return self.is_discriminator and self.type.type == "enum"
89
89
 
90
- @property
91
- def is_combined_discriminator(self) -> bool:
92
- return self.is_discriminator and self.type.type == "combined"
93
-
94
90
  @property
95
91
  def is_base_discriminator(self) -> bool:
96
92
  """If this discriminator is on the base model for polymorphic inheritance"""
97
93
  if self.is_enum_discriminator:
98
94
  return self.is_polymorphic and self.client_default_value is None
99
- if self.is_combined_discriminator:
100
- return True
101
95
  return self.is_discriminator and self.is_polymorphic and cast(ConstantType, self.type).value is None
102
96
 
103
97
  @property
@@ -104,35 +104,4 @@ additional questions or comments.
104
104
  [pip]: https://pypi.org/project/pip/
105
105
  [azure_sub]: https://azure.microsoft.com/free/
106
106
  {% endif %}
107
- {% else %}
108
- # Overview
109
-
110
- This package is generated by `@typespec/http-client-python` with Typespec.
111
-
112
- ## Getting started
113
-
114
- ### Prequisites
115
-
116
- - Python 3.9 or later is required to use this package.
117
-
118
- ### Install the package
119
-
120
- Step into folder where setup.py is then run:
121
-
122
- ```bash
123
- pip install -e .
124
- ```
125
-
126
- ### Examples
127
-
128
- ```python
129
- >>> from {{ code_model.namespace }} import {{ client_name }}
130
- >>> from {{ code_model.core_library }}.exceptions import HttpResponseError
131
-
132
- >>> client = {{ client_name }}(endpoint='<endpoint>')
133
- >>> try:
134
- <!-- write code here -->
135
- except HttpResponseError as e:
136
- print('service responds error: {}'.format(e.response.json()))
137
- ```
138
107
  {% endif %}
@@ -6,7 +6,6 @@
6
6
  import pytest
7
7
  from azure.resourcemanager.commonproperties.aio import CommonPropertiesClient
8
8
  from azure.resourcemanager.commonproperties import models
9
- from azure.core import exceptions
10
9
 
11
10
  SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
12
11
  RESOURCE_GROUP_NAME = "test-rg"
@@ -62,33 +61,3 @@ async def test_managed_identity_update_with_user_assigned_and_system_assigned(cl
62
61
  assert result.location == "eastus"
63
62
  assert result.identity.type == "SystemAssigned,UserAssigned"
64
63
  assert result.properties.provisioning_state == "Succeeded"
65
-
66
-
67
- @pytest.mark.asyncio
68
- async def test_error_get_for_predefined_error(client):
69
- try:
70
- await client.error.get_for_predefined_error(
71
- resource_group_name=RESOURCE_GROUP_NAME,
72
- confidential_resource_name="confidential",
73
- )
74
- except exceptions.ResourceNotFoundError as e:
75
- assert e.status_code == 404
76
- assert (
77
- e.error.message
78
- == "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
79
- )
80
-
81
-
82
- @pytest.mark.asyncio
83
- async def test_error_create_for_user_defined_error(client):
84
- try:
85
- await client.error.create_for_user_defined_error(
86
- resource_group_name=RESOURCE_GROUP_NAME,
87
- confidential_resource_name="confidential",
88
- resource=models.ConfidentialResource(
89
- location="eastus", properties=models.ConfidentialResourceProperties(username="00")
90
- ),
91
- )
92
- except exceptions.HttpResponseError as e:
93
- assert e.status_code == 400
94
- assert e.error.message == "Username should not contain only numbers."
@@ -10,7 +10,6 @@ from specs.azure.clientgenerator.core.clientinitialization.aio import (
10
10
  MixedParamsClient,
11
11
  PathParamClient,
12
12
  ParamAliasClient,
13
- ParentClient,
14
13
  )
15
14
  from specs.azure.clientgenerator.core.clientinitialization.models import Input
16
15
 
@@ -49,11 +48,3 @@ async def test_param_alias_client():
49
48
  async with ParamAliasClient("sample-blob") as client:
50
49
  await client.with_aliased_name()
51
50
  await client.with_original_name()
52
-
53
-
54
- # @pytest.mark.asyncio
55
- # async def test_parent_child_client():
56
- # async with ParentClient() as client:
57
- # await client.child_client.with_query()
58
- # await client.child_client.get_standalone()
59
- # await client.child_client.delete_standalone()
@@ -29,10 +29,3 @@ async def test_model_usage(client: UsageClient):
29
29
  assert models.RoundTripModel(
30
30
  result=models.ResultModel(name="Madge")
31
31
  ) == await client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())
32
-
33
-
34
- # @pytest.mark.asyncio
35
- # async def test_orphan_model_serializable(client: UsageClient):
36
- # await client.model_in_operation.orphan_model_serializable(
37
- # body=models.OrphanModel(model_name="name", description="desc")
38
- # )
@@ -6,7 +6,6 @@
6
6
  import pytest
7
7
  from azure.resourcemanager.commonproperties import CommonPropertiesClient
8
8
  from azure.resourcemanager.commonproperties import models
9
- from azure.core import exceptions
10
9
 
11
10
  SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
12
11
  RESOURCE_GROUP_NAME = "test-rg"
@@ -59,31 +58,3 @@ def test_managed_identity_update_with_user_assigned_and_system_assigned(client):
59
58
  assert result.location == "eastus"
60
59
  assert result.identity.type == "SystemAssigned,UserAssigned"
61
60
  assert result.properties.provisioning_state == "Succeeded"
62
-
63
-
64
- def test_error_get_for_predefined_error(client):
65
- try:
66
- client.error.get_for_predefined_error(
67
- resource_group_name=RESOURCE_GROUP_NAME,
68
- confidential_resource_name="confidential",
69
- )
70
- except exceptions.ResourceNotFoundError as e:
71
- assert e.status_code == 404
72
- assert (
73
- e.error.message
74
- == "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
75
- )
76
-
77
-
78
- def test_error_create_for_user_defined_error(client):
79
- try:
80
- client.error.create_for_user_defined_error(
81
- resource_group_name=RESOURCE_GROUP_NAME,
82
- confidential_resource_name="confidential",
83
- resource=models.ConfidentialResource(
84
- location="eastus", properties=models.ConfidentialResourceProperties(username="00")
85
- ),
86
- )
87
- except exceptions.HttpResponseError as e:
88
- assert e.status_code == 400
89
- assert e.error.message == "Username should not contain only numbers."
@@ -9,7 +9,6 @@ from specs.azure.clientgenerator.core.clientinitialization import (
9
9
  MixedParamsClient,
10
10
  PathParamClient,
11
11
  ParamAliasClient,
12
- ParentClient,
13
12
  )
14
13
  from specs.azure.clientgenerator.core.clientinitialization.models import Input
15
14
 
@@ -43,10 +42,3 @@ def test_param_alias_client():
43
42
  with ParamAliasClient("sample-blob") as client:
44
43
  client.with_aliased_name()
45
44
  client.with_original_name()
46
-
47
-
48
- # def test_parent_child_client():
49
- # with ParentClient() as client:
50
- # client.child_client.with_query()
51
- # client.child_client.get_standalone()
52
- # client.child_client.delete_standalone()
@@ -26,7 +26,3 @@ def test_model_usage(client: UsageClient):
26
26
  assert models.RoundTripModel(
27
27
  result=models.ResultModel(name="Madge")
28
28
  ) == client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())
29
-
30
-
31
- # def test_orphan_model_serializable(client: UsageClient):
32
- # client.model_in_operation.orphan_model_serializable(body=models.OrphanModel(model_name="name", description="desc"))
@@ -5,7 +5,6 @@ azure-mgmt-core==1.5.0
5
5
  # only for azure
6
6
  -e ./generated/azure-client-generator-core-access
7
7
  -e ./generated/azure-client-generator-core-client-initialization
8
- -e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
9
8
  -e ./generated/azure-client-generator-core-flatten-property
10
9
  -e ./generated/azure-client-generator-core-usage
11
10
  -e ./generated/azure-core-basic
@@ -15,12 +14,9 @@ azure-mgmt-core==1.5.0
15
14
  -e ./generated/azure-core-model
16
15
  -e ./generated/azure-core-traits
17
16
  -e ./generated/azure-core-page
18
- -e ./generated/azure-encode-duration
19
17
  -e ./generated/azure-special-headers-client-request-id/
20
18
  -e ./generated/azure-example-basic
21
19
  -e ./generated/azure-resource-manager-common-properties
22
- -e ./generated/azure-resource-manager-large-header
23
- -e ./generated/azure-resource-manager-non-resource
24
20
  -e ./generated/azure-resource-manager-operation-templates
25
21
  -e ./generated/azure-resource-manager-resources
26
22
  # -e ./generated/client-namespace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.12.5",
3
+ "version": "0.13.0-dev.1",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",
@@ -1,139 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- # -------------------------------------------------------------------------
4
- # Copyright (c) Microsoft Corporation. All rights reserved.
5
- # Licensed under the MIT License. See License.txt in the project root for
6
- # license information.
7
- # --------------------------------------------------------------------------
8
- """Package manager utilities for detecting and using pip or uv."""
9
-
10
- import subprocess
11
- import sys
12
- import venv
13
- from pathlib import Path
14
- from venvtools import ExtendedEnvBuilder
15
-
16
-
17
- class PackageManagerNotFoundError(Exception):
18
- """Raised when no suitable package manager is found."""
19
- pass
20
-
21
-
22
- def _check_command_available(command: str) -> bool:
23
- """Check if a command is available in the environment."""
24
- try:
25
- subprocess.run([command, "--version"], capture_output=True, check=True)
26
- return True
27
- except (subprocess.CalledProcessError, FileNotFoundError):
28
- return False
29
-
30
-
31
- def detect_package_manager() -> str:
32
- """Detect the best available package manager.
33
-
34
- Returns:
35
- str: The package manager command ('uv' or 'pip')
36
-
37
- Raises:
38
- PackageManagerNotFoundError: If no suitable package manager is found
39
- """
40
- # Check for uv first since it's more modern and faster
41
- if _check_command_available("uv"):
42
- return "uv"
43
-
44
- # Fall back to pip
45
- if _check_command_available("pip"):
46
- return "pip"
47
-
48
- # As a last resort, try using python -m pip
49
- try:
50
- subprocess.run([sys.executable, "-m", "pip", "--version"],
51
- capture_output=True, check=True)
52
- return "python -m pip"
53
- except (subprocess.CalledProcessError, FileNotFoundError):
54
- pass
55
-
56
- raise PackageManagerNotFoundError(
57
- "No suitable package manager found. Please install either uv or pip."
58
- )
59
-
60
-
61
- def get_install_command(package_manager: str, venv_context=None) -> list:
62
- """Get the install command for the given package manager.
63
-
64
- Args:
65
- package_manager: The package manager command ('uv', 'pip', or 'python -m pip')
66
- venv_context: The virtual environment context (optional, used for pip)
67
-
68
- Returns:
69
- list: The base install command as a list
70
- """
71
- if package_manager == "uv":
72
- cmd = ["uv", "pip", "install"]
73
- if venv_context:
74
- cmd.extend(["--python", venv_context.env_exe])
75
- return cmd
76
- elif package_manager == "pip":
77
- if venv_context:
78
- return [venv_context.env_exe, "-m", "pip", "install"]
79
- else:
80
- return ["pip", "install"]
81
- elif package_manager == "python -m pip":
82
- if venv_context:
83
- return [venv_context.env_exe, "-m", "pip", "install"]
84
- else:
85
- return [sys.executable, "-m", "pip", "install"]
86
- else:
87
- raise ValueError(f"Unknown package manager: {package_manager}")
88
-
89
-
90
- def install_packages(packages: list, venv_context=None, package_manager: str = None) -> None:
91
- """Install packages using the available package manager.
92
-
93
- Args:
94
- packages: List of packages to install
95
- venv_context: Virtual environment context (optional)
96
- package_manager: Package manager to use (auto-detected if None)
97
- """
98
- if package_manager is None:
99
- package_manager = detect_package_manager()
100
-
101
- install_cmd = get_install_command(package_manager, venv_context)
102
-
103
- try:
104
- subprocess.check_call(install_cmd + packages)
105
- except subprocess.CalledProcessError as e:
106
- raise RuntimeError(f"Failed to install packages with {package_manager}: {e}")
107
-
108
-
109
- def create_venv_with_package_manager(venv_path):
110
- """Create virtual environment using the best available package manager.
111
-
112
- Args:
113
- venv_path: Path where to create the virtual environment
114
-
115
- Returns:
116
- venv_context: Virtual environment context object
117
- """
118
- package_manager = detect_package_manager()
119
-
120
- if package_manager == "uv":
121
- # Use uv to create and manage the virtual environment
122
- if not venv_path.exists():
123
- subprocess.check_call(["uv", "venv", str(venv_path)])
124
-
125
- # Create a mock venv_context for compatibility
126
- class MockVenvContext:
127
- def __init__(self, venv_path):
128
- self.env_exe = str(venv_path / "bin" / "python") if sys.platform != "win32" else str(venv_path / "Scripts" / "python.exe")
129
-
130
- return MockVenvContext(venv_path)
131
- else:
132
- # Use standard venv for pip
133
- if venv_path.exists():
134
- env_builder = venv.EnvBuilder(with_pip=True)
135
- return env_builder.ensure_directories(venv_path)
136
- else:
137
- env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True)
138
- env_builder.create(venv_path)
139
- return env_builder.context
@@ -1,30 +0,0 @@
1
- # -------------------------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # Licensed under the MIT License. See License.txt in the project root for
4
- # license information.
5
- # --------------------------------------------------------------------------
6
- import pytest
7
- from azure.resourcemanager.largeheader.aio import LargeHeaderClient
8
- from azure.resourcemanager.largeheader import models
9
-
10
- SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11
- RESOURCE_GROUP_NAME = "test-rg"
12
-
13
-
14
- @pytest.fixture
15
- async def client(credential, authentication_policy):
16
- async with LargeHeaderClient(
17
- credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18
- ) as client:
19
- yield client
20
-
21
-
22
- @pytest.mark.asyncio
23
- async def test_large_headers_begin_two6_k(client: LargeHeaderClient):
24
- result = await (
25
- await client.large_headers.begin_two6_k(
26
- resource_group_name=RESOURCE_GROUP_NAME,
27
- large_header_name="header1",
28
- )
29
- ).result()
30
- assert result == models.CancelResult(succeeded=True)