Skip to content

Commit bec0235

Browse files
authored
Merge pull request #952 from linsword13/object-imp
Support import same-directory sources from an object file
2 parents 01add89 + 2ff3a01 commit bec0235

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

lib/ramble/ramble/repository.py

+7
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,13 @@ def __init__(self, fullname, repo, object_name):
14931493
self.fullname = fullname
14941494
super().__init__(self.fullname, self.object_py, prepend=self._object_prepend)
14951495

1496+
def is_package(self, fullname):
1497+
parent_dir = os.path.dirname(self.path)
1498+
# Use the presence of __init__.py to determine if load it as a package.
1499+
# TODO: since every Ramble object already has a containing directory,
1500+
# it might make sense to treat all of them as python packages.
1501+
return os.path.isfile(os.path.join(parent_dir, "__init__.py"))
1502+
14961503

14971504
class RepositoryNamespaceLoader:
14981505
def create_module(self, spec):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022-2025 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
import os
10+
11+
import pytest
12+
13+
import ramble.workspace
14+
from ramble.main import RambleCommand
15+
16+
pytestmark = pytest.mark.usefixtures(
17+
"mutable_config", "mutable_mock_workspace_path", "mutable_mock_apps_repo"
18+
)
19+
20+
workspace = RambleCommand("workspace")
21+
22+
23+
def test_object_import_separate_python_source(request):
24+
ws_name = request.node.name
25+
ws = ramble.workspace.create(ws_name)
26+
global_args = ["-w", ws_name]
27+
28+
workspace(
29+
"manage",
30+
"experiments",
31+
"import-test",
32+
"-v",
33+
"n_nodes=1",
34+
"-v",
35+
"processes_per_node=1",
36+
global_args=global_args,
37+
)
38+
39+
workspace("setup", global_args=global_args)
40+
41+
rendered_script = os.path.join(
42+
ws.experiment_dir, "import-test", "test", "generated", "execute_experiment"
43+
)
44+
with open(rendered_script) as f:
45+
content = f.read()
46+
assert "echo 1" in content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2022-2025 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
# An empty file to signal to the loader that this is a Python package.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2022-2025 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
from ramble.app.builtin.mock.import_test import helpers
10+
from ramble.appkit import *
11+
12+
13+
class ImportTest(ExecutableApplication):
14+
"""An example application that imports a module"""
15+
16+
name = "import-test"
17+
18+
tags("test-app")
19+
20+
executable(
21+
"test",
22+
helpers.get_test_executable(),
23+
use_mpi=False,
24+
output_capture=OUTPUT_CAPTURE.ALL,
25+
)
26+
27+
workload("test", executable="test")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2022-2025 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
10+
def get_test_executable():
11+
return "echo 1"

0 commit comments

Comments
 (0)