@@ -114,3 +114,75 @@ def test_doc_examples(session: nox.Session, example: str) -> None:
114114 session .chdir (f"docs/examples/getting_started/{ example } " )
115115 session .install ("." , "--config-settings=cmake.verbose=true" )
116116 session .run ("python" , "../test.py" )
117+
118+
119+ @nox .session (reuse_venv = True )
120+ def downstream (session : nox .Session ) -> None :
121+ """
122+ Build a downstream project.
123+ """
124+
125+ # If running in manylinux:
126+ # docker run --rm -v $PWD:/sk -w /sk -t quay.io/pypa/manylinux2014_x86_64:latest \
127+ # pipx run --system-site-packages nox -s downstream -- https://github.com/...
128+ # (requires tomli, so allowing access to system-site-packages)
129+
130+ if sys .version_info < (3 , 11 ):
131+ import tomli as tomllib
132+ else :
133+ import tomllib
134+
135+ parser = argparse .ArgumentParser ()
136+ parser .add_argument ("project" , help = "A project to build" )
137+ parser .add_argument ("--subdir" , help = "A subdirectory to build" )
138+ args , remaining = parser .parse_known_args (session .posargs )
139+
140+ tmp_dir = Path (session .create_tmp ())
141+ proj_dir = tmp_dir / "_" .join (args .project .split ("/" ))
142+
143+ session .install ("build" , "hatch-vcs" , "hatchling" )
144+ session .install (".[pyproject]" , "--no-build-isolation" )
145+
146+ if proj_dir .is_dir ():
147+ session .chdir (proj_dir )
148+ session .run ("git" , "pull" , external = True )
149+ else :
150+ session .run (
151+ "git" ,
152+ "clone" ,
153+ args .project ,
154+ * remaining ,
155+ proj_dir ,
156+ "--recurse-submodules" ,
157+ external = True ,
158+ )
159+ session .chdir (proj_dir )
160+
161+ # Read and strip requirements
162+ pyproject_toml = Path ("pyproject.toml" )
163+ with pyproject_toml .open ("rb" ) as f :
164+ pyproject = tomllib .load (f )
165+ requires = [
166+ x
167+ for x in pyproject ["build-system" ]["requires" ]
168+ if "scikit-build-core" not in x .replace ("_" , "-" )
169+ ]
170+ if not shutil .which ("ninja" ):
171+ requires .append ("ninja" )
172+ if not shutil .which ("cmake" ):
173+ requires .append ("cmake" )
174+ if requires :
175+ session .install (* requires )
176+
177+ if args .subdir :
178+ session .chdir (args .subdir )
179+
180+ session .run (
181+ "python" ,
182+ "-m" ,
183+ "build" ,
184+ "--no-isolation" ,
185+ "--skip-dependency-check" ,
186+ "--wheel" ,
187+ "." ,
188+ )
0 commit comments