diff --git a/sirepo/pkcli/nersc_test.py b/sirepo/pkcli/nersc_test.py index 17cc12fc42..b2c7db6c62 100644 --- a/sirepo/pkcli/nersc_test.py +++ b/sirepo/pkcli/nersc_test.py @@ -88,11 +88,11 @@ def __str__(self): return res def _render_resource(self, filename): - return sirepo.resource.render_resource( - filename, + return sirepo.resource.render( self.RESOURCE_DIR, - self.run_dir, - PKDict( + filename, + target_dir=self.run_dir, + j2_ctx=PKDict( job_cmd_file=self.get("job_cmd_file"), run_dir=self.run_dir, user=self.user, diff --git a/sirepo/resource.py b/sirepo/resource.py index c94aaa2188..9e3e30093b 100644 --- a/sirepo/resource.py +++ b/sirepo/resource.py @@ -45,22 +45,22 @@ def glob_paths(*paths): ) -def render_resource(template_name, resource_dir, run_dir, j2_ctx): - """Render a jinja resource from a package_data/resource_dir - into run_dir +def render(*paths, target_dir=None, j2_ctx=None): + """Render a jinja resource into target_dir Args: - resource_template (str): .jinja template basename - resource_dir (str): package_data dir that .jinja template lives in - run_dir (py.path): target directory for rendered file - jinja_params (PKDict): parameters to jinja file + paths (str): Path components of file + target_dir (py.path): target directory for rendered file + j2_ctx (PKDict): parameters to jinja file Returns: py.path: path to rendered file """ - res = run_dir.join(template_name) + res = target_dir.join(paths[-1]) + p = list(paths) + p[-1] += pykern.pkjinja.RESOURCE_SUFFIX pykern.pkjinja.render_file( - _resource_path(template_name, resource_dir), + file_path(*p), j2_ctx, output=res, ) @@ -133,10 +133,3 @@ def _join_paths(paths): a = [p for p in paths if os.path.isabs(p)] assert not a, f"absolute paths={a} in paths={paths}" return os.path.join(*paths) - - -def _resource_path(filename, resource_dir): - f = filename + pykern.pkjinja.RESOURCE_SUFFIX - if type(resource_dir) == str: - return file_path(resource_dir).join(f) - return resource_dir.join(f) diff --git a/tests/resource_test.py b/tests/resource_test.py index f3fd1c704f..1ddd62e7f0 100644 --- a/tests/resource_test.py +++ b/tests/resource_test.py @@ -28,11 +28,11 @@ def test_render_resource(): pkunit.pkre( 'var = "x"', pkio.read_text( - resource.render_resource( - "README.txt", + resource.render( "resource_test_data", - pkunit.work_dir(), - PKDict( + "README.txt", + target_dir=pkunit.work_dir(), + j2_ctx=PKDict( var="x", ), )