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

chdir does not work as expected #44

Closed
DavidHuber-NOAA opened this issue Nov 14, 2024 · 1 comment
Closed

chdir does not work as expected #44

DavidHuber-NOAA opened this issue Nov 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@DavidHuber-NOAA
Copy link
Collaborator

Expected behavior
The fsutils.chdir contextmanager should navigate to the chosen directory for the duration of a with statement and then return to the previous working directory. If chdir is unable to navigate to the chosen directory, it should raise an exception. Also, tests should be in place to verify that chdir works as expected.

Current behavior
chdir does navigate to the chosen directory, but it always states

WARNING: Unable to chdir({path})

Additionally, when attempting to return to the previous working directory at the end of the with, it states it is unable to yield to it.
Lastly, there are no tests for the entirety of the fsutils module, including the chdir contextmanager.

Machines affected
All

To Reproduce

from wxflow import chdir

with chdir("/"):
    print("We are now in /")

Context
Found while attempting to engineer a solution for NOAA-EMC/global-workflow#2994, which requires navigating to HOMEgfs to run git commands.

Detailed Description
Nothing further.

Possible Implementation

    cwd = os.getcwd()
    # Try to change paths.
    try:
        os.chdir(path)
    except OSError:
        raise OSError(f"Failed to change directory to ({path})")

    # If successful, yield to the calling "with" statement.
    try:
        yield
    finally:
        # Once the with is complete, head back to the original working directory
        os.chdir(cwd)
@DavidHuber-NOAA DavidHuber-NOAA added the bug Something isn't working label Nov 14, 2024
@DavidHuber-NOAA DavidHuber-NOAA self-assigned this Nov 14, 2024
@DavidHuber-NOAA
Copy link
Collaborator Author

Resolved by #45.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant