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

Request: avoid adding extensions to filepaths which already contain them. #62

Open
lukethehuman opened this issue Jul 3, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@lukethehuman
Copy link
Collaborator

lukethehuman commented Jul 3, 2024

When using blobmaker in an optimisation workflow, we already need to track the majority of filepaths. Thus, it's more straightforward to pass the full filepath directly to methods such as GeometryMaker.export_exodus. However, currently this causes filenames with two extensions like so: filename.e.e. This can be avoided by removing the extension when passing to such methods, but it would be preferable if blobmaker could check for the extension before adding it.

Consider the following code block to achieve this:

from pathlib import Path

# Get required extension, e.g. for exodus:
ext = ".e"

# Add required extension if it is not already present.
filepath = Path(filepath)  # Ensure path is a pathlib.Path object
if filepath.suffix != ext:  # Check for extension
    filepath = filepath.parent / (filepath.name + ext)  # Add the extension

# If you need the filepath as a string again, just pass it like so:
str(filepath)

As shown, pathlib makes it quite easy to check the file extension (or suffix) and is a built-in module for python so doesn't require adding a dependency.

@lukethehuman lukethehuman added the enhancement New feature or request label Jul 3, 2024
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

1 participant