1919 dependency_graph ,
2020 external_commands ,
2121 packagesettings ,
22- request_session ,
2322)
2423
2524if typing .TYPE_CHECKING :
3534class WorkContext :
3635 def __init__ (
3736 self ,
37+ * ,
3838 active_settings : packagesettings .Settings | None ,
39- constraints_file : str | None ,
4039 patches_dir : pathlib .Path ,
4140 sdists_repo : pathlib .Path ,
4241 wheels_repo : pathlib .Path ,
4342 work_dir : pathlib .Path ,
43+ constraints_files : tuple [str , ...] = (),
4444 cleanup : bool = True ,
4545 variant : str = "cpu" ,
4646 network_isolation : bool = False ,
@@ -59,13 +59,6 @@ def __init__(
5959 max_jobs = max_jobs ,
6060 )
6161 self .settings = active_settings
62- self .input_constraints_uri : str | None
63- self .constraints = constraints .Constraints ()
64- if constraints_file is not None :
65- self .input_constraints_uri = constraints_file
66- self .constraints .load_constraints_file (constraints_file )
67- else :
68- self .input_constraints_uri = None
6962 self .sdists_repo = pathlib .Path (sdists_repo ).resolve ()
7063 self .sdists_downloads = self .sdists_repo / "downloads"
7164 self .sdists_builds = self .sdists_repo / "builds"
@@ -76,6 +69,7 @@ def __init__(
7669 self .wheel_server_dir = self .wheels_repo / "simple"
7770 self .work_dir = pathlib .Path (work_dir ).resolve ()
7871 self .graph_file = self .work_dir / "graph.json"
72+ self .merged_constraints = self .work_dir / "merged-constraints.txt"
7973 self .uv_cache = self .work_dir / "uv-cache"
8074 self .wheel_server_url = wheel_server_url
8175 self .logs_dir = self .work_dir / "logs"
@@ -86,10 +80,13 @@ def __init__(
8680 self .network_isolation = network_isolation
8781 self .settings_dir = settings_dir
8882
89- self ._constraints_filename = self .work_dir / "constraints.txt"
90-
9183 self .dependency_graph = dependency_graph .DependencyGraph ()
9284
85+ self .constraints = constraints .Constraints ()
86+ self .input_constraints_files = constraints_files
87+ for constraints_file in self .input_constraints_files :
88+ self .constraints .load_constraints_file (constraints_file )
89+
9390 # storing metrics
9491 self .time_store : dict [str , dict [str , float ]] = collections .defaultdict (
9592 dict [str , float ]
@@ -135,19 +132,9 @@ def pip_wheel_server_args(self) -> list[str]:
135132
136133 @property
137134 def pip_constraint_args (self ) -> list [str ]:
138- if not self .input_constraints_uri :
135+ if not self .constraints :
139136 return []
140-
141- if self .input_constraints_uri .startswith (("https://" , "http://" , "file://" )):
142- path_to_constraints_file = self .work_dir / "input-constraints.txt"
143- if not path_to_constraints_file .exists ():
144- response = request_session .session .get (self .input_constraints_uri )
145- path_to_constraints_file .write_text (response .text )
146- else :
147- path_to_constraints_file = pathlib .Path (self .input_constraints_uri )
148-
149- path_to_constraints_file = path_to_constraints_file .absolute ()
150- return ["--constraint" , os .fspath (path_to_constraints_file )]
137+ return ["--constraint" , os .fspath (self .merged_constraints )]
151138
152139 def uv_clean_cache (self , * reqs : Requirement ) -> None :
153140 """Invalidate and clean uv cache for requirements
@@ -201,6 +188,25 @@ def setup(self) -> None:
201188 if not p .exists ():
202189 logger .debug ("creating %s" , p )
203190 p .mkdir (parents = True )
191+ self .write_constraints ()
192+
193+ def write_constraints (self ) -> None :
194+ """Write combined constraints to disk"""
195+ if self .constraints :
196+ with self .merged_constraints .open ("w" , encoding = "utf-8" ) as f :
197+ f .write ("# auto-generated constraints file\n " )
198+ for constraints_file in self .input_constraints_files :
199+ f .write (f"# { constraints_file } \n " )
200+ f .write ("\n " )
201+ self .constraints .dump_constraints (f )
202+ logger .debug (
203+ "generated %s with content %s" ,
204+ self .merged_constraints ,
205+ self .merged_constraints .read_text (),
206+ )
207+ else :
208+ logger .debug ("no constraints configured" )
209+ self .merged_constraints .unlink (missing_ok = True )
204210
205211 def clean_build_dirs (
206212 self ,
0 commit comments