Skip to content

Commit b77a789

Browse files
committed
format
1 parent 2193c39 commit b77a789

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

packages/typespec-python/scripts/install.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
try:
1414
from package_manager import detect_package_manager, PackageManagerNotFoundError
15+
1516
detect_package_manager() # Just check if we have a package manager
1617
except (ImportError, ModuleNotFoundError, PackageManagerNotFoundError):
1718
raise Exception("Your Python installation doesn't have a suitable package manager (pip or uv) available")
@@ -31,11 +32,12 @@
3132

3233
def main():
3334
venv_path = _ROOT_DIR / "venv"
34-
35+
3536
# Create virtual environment using package manager abstraction
3637
from package_manager import create_venv_with_package_manager, install_packages
38+
3739
venv_context = create_venv_with_package_manager(venv_path)
38-
40+
3941
# Install required packages - install_packages handles package manager logic
4042
install_packages(["-U", "black"], venv_context)
4143

packages/typespec-python/scripts/package_manager.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
class PackageManagerNotFoundError(Exception):
1818
"""Raised when no suitable package manager is found."""
19+
1920
pass
2021

2122

@@ -30,41 +31,38 @@ def _check_command_available(command: str) -> bool:
3031

3132
def detect_package_manager() -> str:
3233
"""Detect the best available package manager.
33-
34+
3435
Returns:
3536
str: The package manager command ('uv' or 'pip')
36-
37+
3738
Raises:
3839
PackageManagerNotFoundError: If no suitable package manager is found
3940
"""
4041
# Check for uv first since it's more modern and faster
4142
if _check_command_available("uv"):
4243
return "uv"
43-
44+
4445
# Fall back to pip
4546
if _check_command_available("pip"):
4647
return "pip"
47-
48+
4849
# As a last resort, try using python -m pip
4950
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)
5252
return "python -m pip"
5353
except (subprocess.CalledProcessError, FileNotFoundError):
5454
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.")
5957

6058

6159
def get_install_command(package_manager: str, venv_context=None) -> list:
6260
"""Get the install command for the given package manager.
63-
61+
6462
Args:
6563
package_manager: The package manager command ('uv', 'pip', or 'python -m pip')
6664
venv_context: The virtual environment context (optional, used for pip)
67-
65+
6866
Returns:
6967
list: The base install command as a list
7068
"""
@@ -89,17 +87,17 @@ def get_install_command(package_manager: str, venv_context=None) -> list:
8987

9088
def install_packages(packages: list, venv_context=None, package_manager: str = None) -> None:
9189
"""Install packages using the available package manager.
92-
90+
9391
Args:
9492
packages: List of packages to install
9593
venv_context: Virtual environment context (optional)
9694
package_manager: Package manager to use (auto-detected if None)
9795
"""
9896
if package_manager is None:
9997
package_manager = detect_package_manager()
100-
98+
10199
install_cmd = get_install_command(package_manager, venv_context)
102-
100+
103101
try:
104102
subprocess.check_call(install_cmd + packages)
105103
except subprocess.CalledProcessError as e:
@@ -108,25 +106,29 @@ def install_packages(packages: list, venv_context=None, package_manager: str = N
108106

109107
def create_venv_with_package_manager(venv_path):
110108
"""Create virtual environment using the best available package manager.
111-
109+
112110
Args:
113111
venv_path: Path where to create the virtual environment
114-
112+
115113
Returns:
116114
venv_context: Virtual environment context object
117115
"""
118116
package_manager = detect_package_manager()
119-
117+
120118
if package_manager == "uv":
121119
# Use uv to create and manage the virtual environment
122120
if not venv_path.exists():
123121
subprocess.check_call(["uv", "venv", str(venv_path)])
124-
122+
125123
# Create a mock venv_context for compatibility
126124
class MockVenvContext:
127125
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-
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+
130132
return MockVenvContext(venv_path)
131133
else:
132134
# Use standard venv for pip
@@ -136,4 +138,4 @@ def __init__(self, venv_path):
136138
else:
137139
env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True)
138140
env_builder.create(venv_path)
139-
return env_builder.context
141+
return env_builder.context

packages/typespec-python/scripts/prepare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def main():
2323
assert venv_preexists # Otherwise install was not done
2424

2525
venv_context = create_venv_with_package_manager(venv_path)
26-
26+
2727
try:
2828
install_packages(["-r", f"{_ROOT_DIR}/dev_requirements.txt"], venv_context)
2929
except FileNotFoundError as e:

packages/typespec-python/scripts/venvtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def ensure_directories(self, env_dir):
2929
def python_run(venv_context, module, command=None, *, additional_dir="."):
3030
try:
3131
cmd_line = [venv_context.env_exe, "-m", module] + (command if command else [])
32-
32+
3333
print("Executing: {}".format(" ".join(cmd_line)))
3434
subprocess.run(
3535
cmd_line,

0 commit comments

Comments
 (0)