22import asyncio
33from pathlib import Path
44from dataclasses import dataclass
5- from typing import IO , TYPE_CHECKING , Any , Union , Literal , Optional , cast
5+ from typing import IO , TYPE_CHECKING , Any , Literal , cast
66
77from nb_cli import cache
88from jinja2 import Environment , FileSystemLoader
1414 get_default_python ,
1515 get_nonebot_config ,
1616 ensure_process_terminated ,
17+ probe_environment_manager ,
1718)
1819
1920from .exception import GetDriverTypeError , ComposeNotAvailable
@@ -67,11 +68,11 @@ async def get_compose_command() -> Compose:
6768
6869@ensure_process_terminated
6970async def call_compose (
70- compose_args : Optional [ list [str ]] = None ,
71- cwd : Optional [ Path ] = None ,
72- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
73- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
74- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
71+ compose_args : list [str ] | None = None ,
72+ cwd : Path | None = None ,
73+ stdin : IO [Any ] | int | None = None ,
74+ stdout : IO [Any ] | int | None = None ,
75+ stderr : IO [Any ] | int | None = None ,
7576) -> asyncio .subprocess .Process :
7677 if cwd is None :
7778 cwd = get_project_root ()
@@ -88,11 +89,11 @@ async def call_compose(
8889
8990
9091async def compose_up (
91- compose_args : Optional [ list [str ]] = None ,
92- cwd : Optional [ Path ] = None ,
93- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
94- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
95- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
92+ compose_args : list [str ] | None = None ,
93+ cwd : Path | None = None ,
94+ stdin : IO [Any ] | int | None = None ,
95+ stdout : IO [Any ] | int | None = None ,
96+ stderr : IO [Any ] | int | None = None ,
9697) -> asyncio .subprocess .Process :
9798 return await call_compose (
9899 ["up" , "-d" , "--build" , * (compose_args or [])],
@@ -104,11 +105,11 @@ async def compose_up(
104105
105106
106107async def compose_down (
107- compose_args : Optional [ list [str ]] = None ,
108- cwd : Optional [ Path ] = None ,
109- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
110- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
111- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
108+ compose_args : list [str ] | None = None ,
109+ cwd : Path | None = None ,
110+ stdin : IO [Any ] | int | None = None ,
111+ stdout : IO [Any ] | int | None = None ,
112+ stderr : IO [Any ] | int | None = None ,
112113) -> asyncio .subprocess .Process :
113114 return await call_compose (
114115 ["down" , * (compose_args or [])],
@@ -120,11 +121,11 @@ async def compose_down(
120121
121122
122123async def compose_build (
123- compose_args : Optional [ list [str ]] = None ,
124- cwd : Optional [ Path ] = None ,
125- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
126- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
127- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
124+ compose_args : list [str ] | None = None ,
125+ cwd : Path | None = None ,
126+ stdin : IO [Any ] | int | None = None ,
127+ stdout : IO [Any ] | int | None = None ,
128+ stderr : IO [Any ] | int | None = None ,
128129) -> asyncio .subprocess .Process :
129130 return await call_compose (
130131 ["build" , * (compose_args or [])],
@@ -136,11 +137,11 @@ async def compose_build(
136137
137138
138139async def compose_logs (
139- compose_args : Optional [ list [str ]] = None ,
140- cwd : Optional [ Path ] = None ,
141- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
142- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
143- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
140+ compose_args : list [str ] | None = None ,
141+ cwd : Path | None = None ,
142+ stdin : IO [Any ] | int | None = None ,
143+ stdout : IO [Any ] | int | None = None ,
144+ stderr : IO [Any ] | int | None = None ,
144145) -> asyncio .subprocess .Process :
145146 return await call_compose (
146147 ["logs" , * (compose_args or [])],
@@ -152,11 +153,11 @@ async def compose_logs(
152153
153154
154155async def compose_ps (
155- compose_args : Optional [ list [str ]] = None ,
156- cwd : Optional [ Path ] = None ,
157- stdin : Optional [ Union [ IO [Any ], int ]] = None ,
158- stdout : Optional [ Union [ IO [Any ], int ]] = None ,
159- stderr : Optional [ Union [ IO [Any ], int ]] = None ,
156+ compose_args : list [str ] | None = None ,
157+ cwd : Path | None = None ,
158+ stdin : IO [Any ] | int | None = None ,
159+ stdout : IO [Any ] | int | None = None ,
160+ stderr : IO [Any ] | int | None = None ,
160161) -> asyncio .subprocess .Process :
161162 return await call_compose (
162163 ["ps" , * (compose_args or [])],
@@ -169,10 +170,10 @@ async def compose_ps(
169170
170171@requires_nonebot
171172async def get_driver_type (
172- adapters : Optional [ list [SimpleInfo ]] = None ,
173- builtin_plugins : Optional [ list [str ]] = None ,
174- python_path : Optional [ str ] = None ,
175- cwd : Optional [ Path ] = None ,
173+ adapters : list [SimpleInfo ] | None = None ,
174+ builtin_plugins : list [str ] | None = None ,
175+ python_path : str | None = None ,
176+ cwd : Path | None = None ,
176177) -> bool :
177178 bot_config = get_nonebot_config ()
178179 if adapters is None :
@@ -206,23 +207,21 @@ async def get_driver_type(
206207
207208
208209async def get_build_backend (
209- config_manager : Optional [ ConfigManager ] = None ,
210- ) -> Optional [ Literal ["poetry" , "pdm" , "pip" ]] :
210+ config_manager : ConfigManager | None = None ,
211+ ) -> Literal ["poetry" , "pdm" , "uv" , " pip" ] | None :
211212 if config_manager is None :
212213 config_manager = GLOBAL_CONFIG
213214
214- if data := config_manager ._get_data ():
215- backend = data .get ("build-system" , {}).get ("build-backend" , "" )
216- if "poetry" in backend :
217- return "poetry"
218- elif "pdm" in backend :
219- return "pdm"
215+ inferred , _ = await probe_environment_manager (cwd = config_manager .working_dir )
216+
217+ if inferred != "pip" :
218+ return cast (Literal ["uv" , "pdm" , "poetry" ], inferred )
220219 if (config_manager .project_root / "requirements.txt" ).exists ():
221220 return "pip"
222221
223222
224223async def generate_dockerfile (
225- python_version : str , is_asgi : bool , build_backend : Optional [ str ]
224+ python_version : str , is_asgi : bool , build_backend : str | None
226225):
227226 t = templates .get_template (
228227 "docker/reverse.Dockerfile.jinja"
0 commit comments