Skip to content
Open
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
19 changes: 13 additions & 6 deletions auto_dev/utils/rollback.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
"""Filesystem utilities for temporary backups and rollback mechanisms."""

import os
import shutil
import signal
import tempfile
from pathlib import Path
from contextlib import chdir, contextmanager
from contextlib import contextmanager

from auto_dev.utils import signals


# https://www.youtube.com/watch?v=0GRLhpMao3I
# async-signal safe is the strongest concept of reentrancy.
# async-signal safe implies thread safe.
Copy link
Owner Author

Choose a reason for hiding this comment

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

surprised the comments passed linters haha


# signal.SIGKILL cannot be intercepted
SIGNALS_TO_BLOCK = (signal.SIGINT, signal.SIGTERM)


@contextmanager
def chdir(new_dir):
"""Change the current working directory temporarily."""
old_dir = os.getcwd()
try:
os.chdir(new_dir)
yield
finally:
os.chdir(old_dir)
Comment on lines +16 to +24
Copy link
Collaborator

Choose a reason for hiding this comment

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

this has nothing to do with rollback. Now what?

from ... import rollback

with rollback.chdir(...):
    ....

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

besides this is not the first version of this context manager just to change dirs either. Why would we keep supporting 3.10?

Copy link
Owner Author

Choose a reason for hiding this comment

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

What exactly does the context lib version of chdir that this does not?
It can be used in the manner your suggesting?

I don't really understand why this specific function is so important?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Why wouldn't we support 3.10 if all it requires is not using this chdir thing?

Copy link
Collaborator

@Karrenbelt Karrenbelt Mar 14, 2025

Choose a reason for hiding this comment

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

well there are other limitations, such as StrEnum, IntEnum etc. and who knows what else. 3.10 is from 2021, pretty old by now. End of life support still 1 year 7 month tho



def _restore_from_backup(directory: Path, backup: Path):
for item in directory.rglob("*"):
backup_item = backup / item.relative_to(directory)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import tempfile
from pathlib import Path
from contextlib import chdir

import pytest

Expand All @@ -13,6 +12,7 @@
DEFAULT_PUBLIC_ID,
)
from auto_dev.cli_executor import CommandExecutor
from auto_dev.utils.rollback import chdir
from auto_dev.workflow_manager import Task
from scripts.generate_command_docs import generate_docs
from auto_dev.services.package_manager.index import PackageManager
Expand Down
Loading