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

Accept directory instead of list of files in "multi_slice" converters #32

Open
balbasty opened this issue Nov 22, 2024 · 8 comments
Open
Labels
enhancement New feature or request

Comments

@balbasty
Copy link
Collaborator

Apparently windows does not automatically expand *.ext into list of files, which makes using the multi slice converters very painful. What we could do is, if the there is a single input and it is a directory, then we run the command on all files (with some filter?) in that directory.

@balbasty balbasty added the enhancement New feature or request label Nov 22, 2024
@chourroutm
Copy link

I personally use the built-in pathlib package with:

import pathlib

input_path = pathlib.Path("...")
if "*" in input_path.name:
    for file in input_path.parent.glob(input_path.name):
        # ...
elif input_path.is_dir():
    for file in input_path.glob("*"):
        # ....

@balbasty
Copy link
Collaborator Author

The one thing I am a bit scared of in this case is if the filename really contains a *.

On unix, I can do my_command "my*weird*file.tif" and the wildcards will not be extended, whereas my_command my*weird*file.tif would extend them. In your example, as soon as there's a * in the name, you extend it.

It's a very unlikely edge case, but thought it's worth mentioning.

What we could do is implement your trick only on windows system (where wildecard extension is lacking). There shouldn't be any need for it on unix, I think.

@chourroutm
Copy link

Oh I wasn't aware that * was a valid character in Unix paths!

@chourroutm
Copy link

What about this tweak?

import pathlib

input_path = pathlib.Path("...")
if "*" in input_path.name and not input_path.exists():
    for file in input_path.parent.glob(input_path.name):
        # ...
elif input_path.is_dir():
    for file in input_path.glob("*"):
        # ....

@chourroutm
Copy link

chourroutm commented Nov 26, 2024

Or maybe the other way around:

import pathlib

input_path = pathlib.Path("...")
if input_path.is_dir():
    for file in input_path.glob("*"):
        # ....
elif "*" in input_path.name and not input_path.exists():
    for file in input_path.parent.glob(input_path.name):
        # ...
else:
    # ...

@calvinchai
Copy link
Contributor

One consideration I had is to let the input be a static defined array instead of a directory or wildcard which might drive things to a wrong direction. As the users can always use the wildcard in cli and that would be extended automatically(and sorted). Another thing I can think of is that we might not want to hardcode the glob expression in the package. But I am open to the change.

@balbasty
Copy link
Collaborator Author

On principle I agree and that was the original design, but apparently wildcards are not expended on windows, and that made it difficult for MariPen to run the easily code during the hackathon. Hence the idea of parsing wildcards when they are not extended (with the caveat mentioned above)

@calvinchai
Copy link
Contributor

I see. I will think about how to deal with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants