Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate self.env if it was set. #916

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,8 @@ def to(
system = (
_get_cluster_from(system, dryrun=self.dryrun) if system else self.system
)
if not env:
if (
not self.env or (isinstance(self.env, Env) and not self.env.name)
) and system:
env = system.default_env
else:
env = self.env

env = self.env if not env else env

env = _get_env_from(env)

Expand All @@ -458,6 +453,9 @@ def to(
if isinstance(env, Env):
env = env.to(system, force_install=force_install)

if isinstance(env, Env) and not env.name:
env = system.default_env

# We need to backup the system here so the __getstate__ method of the cluster
# doesn't wipe the client of this function's cluster when deepcopy copies it.
hw_backup = self.system
Expand Down
11 changes: 11 additions & 0 deletions tests/test_resources/test_envs/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def np_summer(a, b):
return int(np.sum([a, b]))


def torch_import():
import torch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use a diff library that's not used in any other test env/function yet to make sure its standalone? aws_cpu fixture now uses a torch docker image


return str(torch.__version__)


@pytest.mark.envtest
class TestEnv(tests.test_resources.test_resource.TestResource):
MAP_FIXTURES = {"resource": "env"}
Expand Down Expand Up @@ -313,3 +319,8 @@ def test_env_to_with_provider_secret(self, cluster):
os.environ["HF_TOKEN"] = "test_hf_token"
env = rh.env(name="hf_env", secrets=["huggingface"])
env.to(cluster)

@pytest.mark.level("local")
def test_env_in_function_factory(self, cluster):
remote_function = rh.function(torch_import, env=["torch"]).to(system=cluster)
assert remote_function() is not None
Loading