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

fix: perform proper provision in an annex remote #79

Merged
merged 3 commits into from
Jan 7, 2025
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
38 changes: 38 additions & 0 deletions datalad_remake/annexremotes/tests/test_hierarchies.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,41 @@ def test_end_to_end(tmp_path, cfgman, monkeypatch, output_pattern):
monkeypatch.chdir(root_dataset.pathobj)
datalad_Get()('d2_subds0/d2_subds1/a1.txt')
_check_content(root_dataset, test_file_content)


@skip_if_on_windows
def test_input_subdatasets(tmp_path, cfgman):
simple_test_method = """
parameters = ['first', 'second', 'third']
command = ["bash", "-c", "echo content: {first} > 'a0.txt'"]
"""

root_dataset = create_simple_computation_dataset(
tmp_path, 'd3', 1, simple_test_method
)

# run `make` command
root_dataset.make(
template='test_method',
parameter=[
'first=first',
'second=second',
'third=third',
],
input=['d3_subds0/a.txt'],
output=['a0.txt'],
result_renderer='disabled',
allow_untrusted_execution=True,
)

_drop_files(root_dataset, ['a0.txt'])

with cfgman.overrides(
{
# Allow the special remote to execute untrusted operations on the
# dataset `root_dataset`
allow_untrusted_execution_key
+ Dataset(root_dataset.pathobj).id: ConfigItem('true'),
}
):
root_dataset.get('a0.txt', result_renderer='disabled')
4 changes: 3 additions & 1 deletion datalad_remake/commands/provision_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from datalad_remake.commands.make_cmd import read_list
from datalad_remake.utils.chdir import chdir
from datalad_remake.utils.glob import glob
from datalad_remake.utils.patched_env import patched_env

if TYPE_CHECKING:
from collections.abc import Generator, Iterable
Expand Down Expand Up @@ -390,7 +391,8 @@ def install_subdataset(
absolute_path.as_uri(),
]
call_git_lines(args)
worktree.get(str(subdataset_path), get_data=False, result_renderer='disabled')
with patched_env(remove=['GIT_DIR', 'GIT_WORK_TREE']):
worktree.get(str(subdataset_path), get_data=False, result_renderer='disabled')
uninstalled_subdatasets.remove(subdataset_path)
uninstalled_subdatasets.update(get_uninstalled_subdatasets(worktree))

Expand Down
41 changes: 41 additions & 0 deletions datalad_remake/utils/patched_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations

from contextlib import contextmanager


@contextmanager
def patched_env(
add: dict | None = None,
remove: list[str] | None = None,
):
"""
Patch the environment for the duration of the context manager.

Parameters
----------
add : dict
The environment variables to add.
remove : list[str]
The environment variables to remove.

Yields
-------
None
"""
import os

# Store the original environment
original_env = dict(os.environ)

# Update the environment
os.environ.update(add or {})
for var in remove or []:
if var in os.environ:
del os.environ[var]

try:
yield
finally:
# Restore the original environment
os.environ.clear()
os.environ.update(original_env)
Loading