-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[DRAFT] Explore skipping graph checks #10425
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from . import locked | ||
|
||
if TYPE_CHECKING: | ||
from dvc.output import Output | ||
from dvc.repo import Repo | ||
from dvc.stage import Stage | ||
from dvc.types import StrOrBytesPath | ||
|
@@ -50,11 +51,39 @@ def get_or_create_stage( | |
to_remote: bool = False, | ||
force: bool = False, | ||
) -> StageInfo: | ||
""" | ||
Adds a new tracked file or update an existing one. | ||
|
||
Used in the context of dvc-add. | ||
|
||
Args: | ||
target : an expression that resolves to a ... | ||
out : if specified, what does this to? | ||
to_remote : if True, what does this to? | ||
force : what does this to? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the cli options in https://dvc.org/doc/command-reference/add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I add explicit documentation here? Alternatively, can I include docs that point to references on where these concepts are enumerated explicitly? Or would it be better to have code with no docs here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong opinion but maybe @skshetry can weigh in |
||
""" | ||
|
||
import xdev | ||
|
||
xdev.embed() | ||
|
||
if out: | ||
target = resolve_output(target, out, force=force) | ||
path, wdir, out = resolve_paths(repo, target, always_local=to_remote and not out) | ||
|
||
try: | ||
# How best to disable this line? With Skip Graph Checks Flag? | ||
# repo._skip_graph_checks = True | ||
if getattr(repo, "_skip_graph_checks", False): | ||
print( | ||
"WARNING: partial or virtual add does not work when --skip-graph-checks are enabled" | ||
) | ||
# FIXME: this probably is not the correct implementation. when | ||
# skip_graph_checks is enabled, we just want to avoid touching the | ||
# graph. The output might already exist and need to be updated. | ||
raise OutputNotFoundError(path) | ||
|
||
out_obj: Output | ||
(out_obj,) = repo.find_outs_by_path(target, strict=False) | ||
stage = out_obj.stage | ||
if not stage.is_data_source: | ||
|
@@ -187,6 +216,31 @@ def _add( | |
stage.dump() | ||
|
||
|
||
class _contextual_setattr: | ||
""" | ||
Sets an attribute on an object within the context and then restores it. | ||
""" | ||
|
||
def __init__(self, obj, attr_name, attr_value): | ||
self.obj = obj | ||
self.attr_name = attr_name | ||
self.attr_value = attr_value | ||
self._prev_value = None | ||
self._had_prev_value = None | ||
|
||
def __enter__(self): | ||
self._had_prev_value = hasattr(self.obj, self.attr_name) | ||
if self._had_prev_value: | ||
self._prev_value = getattr(self.obj, self.attr_name) | ||
setattr(self.obj, self.attr_name, self.attr_value) | ||
|
||
def __exit__(self, ex_type, ex_value, ex_traceback): | ||
if self._had_prev_value: | ||
setattr(self.obj, self.attr_name, self._prev_value) | ||
else: | ||
delattr(self.obj, self.attr_name) | ||
|
||
|
||
@locked | ||
@scm_context | ||
def add( | ||
|
@@ -200,26 +254,36 @@ def add( | |
remote_jobs: Optional[int] = None, | ||
force: bool = False, | ||
relink: bool = True, | ||
skip_graph_checks: bool = False, | ||
) -> list["Stage"]: | ||
add_targets = find_targets(targets, glob=glob) | ||
if not add_targets: | ||
return [] | ||
|
||
stages_with_targets = { | ||
target: get_or_create_stage( | ||
repo, | ||
target, | ||
out=out, | ||
to_remote=to_remote, | ||
force=force, | ||
) | ||
for target in add_targets | ||
} | ||
print("ABOUT TO GET OR CREATE STAGE") | ||
attr_context = _contextual_setattr(repo, "_skip_graph_checks", skip_graph_checks) | ||
with attr_context: | ||
stages_with_targets = { | ||
target: get_or_create_stage( | ||
repo, | ||
target, | ||
out=out, | ||
to_remote=to_remote, | ||
force=force, | ||
) | ||
for target in add_targets | ||
} | ||
print(f"stages_with_targets={stages_with_targets}") | ||
print("FINISHED GET OR CREATE STAGE") | ||
|
||
attr_context = _contextual_setattr(repo, "_skip_graph_checks", skip_graph_checks) | ||
stages = [stage for stage, _ in stages_with_targets.values()] | ||
msg = "Collecting stages from the workspace" | ||
with translate_graph_error(stages), ui.status(msg) as st: | ||
print("ABOUT TO ENTER CHECK THE GRAPH CONTEXT") | ||
with attr_context, translate_graph_error(stages), ui.status(msg) as st: | ||
print("ABOUT TO CHECK THE GRAPH") | ||
repo.check_graph(stages=stages, callback=lambda: st.update("Checking graph")) | ||
print("FINISHED CHECK THE GRAPH CONTEXT") | ||
|
||
if to_remote or out: | ||
assert len(stages_with_targets) == 1, "multiple targets are unsupported" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine if an option like this is long since we want people to be very explicit in choosing this option.