Skip to content

Commit

Permalink
Prepare environment before generating build hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Feb 17, 2025
1 parent ad4ab6b commit bf9a4f2
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/py_build_cmake/export/editable/build_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def write_build_hook(
pkg_hook = staging_dir / fname
pkg_hook.mkdir(parents=True, exist_ok=True)
cwd = cmaker.get_working_dir()
env = cmaker.conf_settings.environment or {}
env = cmaker.prepare_environment()
env = {k: v for k, v in env.items() if k in cmaker.conf_settings.environment}
cmd = list(cmaker.get_build_commands()) + list(cmaker.get_install_commands())
content = f"""\
import sys, inspect, os
from importlib.machinery import PathFinder
from string import Template
import subprocess
class BuilderPathFinder(PathFinder):
Expand All @@ -53,9 +53,7 @@ def find_spec(self, name, path=None, target=None):
return None
def prepare_environment(self):
env = os.environ.copy()
for k, v in self.env.items():
templ = Template(v)
env[k] = templ.substitute(env)
env.update(self.env)
env["PY_BUILD_CMAKE_BUILD_HOOK"] = self.name
return env
def build(self):
Expand Down

0 comments on commit bf9a4f2

Please sign in to comment.