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

Change out_dir to better reflect the fs needs #486

Merged
merged 6 commits into from
Feb 22, 2022

Conversation

emcastillo
Copy link
Contributor

@emcastillo emcastillo commented Jan 5, 2022

Closes #475

out_dir has now a default value of '.' since using an empty one required major changes.

I am not happy at all of how this PR turn out to be, I think we may need to rethink how fs and out_dir interact

@emcastillo emcastillo changed the title Change out_dir to better reflect the fs needs [WIP] Change out_dir to better reflect the fs needs Jan 6, 2022
@emcastillo emcastillo added the cat:enhancement New feature or request label Jan 6, 2022
@emcastillo emcastillo changed the title [WIP] Change out_dir to better reflect the fs needs Change out_dir to better reflect the fs needs Jan 7, 2022
@emcastillo
Copy link
Contributor Author

I think it looks a bit better now, but still not 100% happy

@belltailjp , do you have any suggestions 😇 ?

@belltailjp
Copy link
Member

belltailjp commented Jan 7, 2022

Thanks so much for the quick prototype!!
This branch worked well for me as expected.

I think we may need to rethink how fs and out_dir interact

Right... I feel that the responsibility to handle where to save things into is currently a bit diverged (fs vs out_dir to Writer.__init__ and Writer.save). IMHO the ideal situation would be to take all of the role over to the fs mechanism, so Writer (and extensions) can and should only concern about sub-directories visible through the fs, but I agree that it's gonna be a little too much breaking change, especially if users have their own extensions that rely on absolute paths.
In addition, doing so would force user to always make FS. Maybe this can be covered somehow as a special default case (e.g., apply urlparse and if no scheme found we can consider it as a posix filesystem path).

writer = SimpleWriter(PosixFileSystem("/path/to/some/dir"))

@kmaehashi kmaehashi modified the milestones: v0.5.6, v0.5.7 Jan 21, 2022
@@ -89,6 +93,7 @@ def list(
if path_or_prefix is None:
raise ValueError(
"'path_or_prefix' must not be None in recursive mode.")
path_or_prefix = self.get_actual_path(path_or_prefix)
Copy link
Member

Choose a reason for hiding this comment

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

Need to normalize path even if the recursive=False case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

return os.makedirs(file_path, mode, exist_ok)

def exists(self, file_path: str) -> bool:
file_path = self.get_actual_path(file_path)
return os.path.exists(file_path)

def rename(self, src: str, dst: str) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

get_actual_path needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, old code

@emcastillo
Copy link
Contributor Author

PTAL 😄

@@ -89,11 +89,11 @@ def list(
path_or_prefix: Optional[str] = None,
recursive: bool = False,
) -> Iterator[str]:
path_or_prefix = self.get_actual_path(path_or_prefix)
Copy link
Member

Choose a reason for hiding this comment

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

get_actual_path could be None here 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think this should fix it, get_actual_path fails and os.scandir admits None

@kmaehashi
Copy link
Member

/test mini

@kmaehashi kmaehashi merged commit 0ae1489 into pfnet:master Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement New feature or request no-compat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] don't pass out_dir to writers
3 participants