-
Notifications
You must be signed in to change notification settings - Fork 38
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
Replace os by pathlib to avoid OS related errors and improve code maintenance #427
Conversation
Excellent, thanks! However, I got: AttributeError: module 'os' has no attribute 'mkdirs' |
I have changed some os calls by pathlib. This is very easy to maintain as all OS related specificities are automatically handled. |
I am solving all errors caught by the tests |
There are still places expecting string paths instead of path objects. As a rule, you can't pass strings to methods expecting paths, as it's very difficult to maintain. This is why pathlib is preferred. path1 = "/some/path"
path2 = "/some/path/"
# adding a file pathlib way
file1 = Path(path1) / "myfile"
file2 = Path(path2) / "myfile"
assert(str(file1) == str(file2)) # returns true
# os way
file1 = os.path.join(path1, "myfile")
file2 = os.path.join(path2, "myfile")
assert(file1== file2) # returns false
# file1 is "/some/path/myfile" in Nix and "/some/path\myfile" in Windows
# file2 is "/some/path//myfile" in Nix and "/some/path/\myfile" in Windows |
I see some merge conflicts with the last pull in wget. @tbaudier may you please review? |
The only error remaining in test040_gan_phsp_pet_gan.py
|
3a174b7
to
84f1aff
Compare
@tbaudier : all tests are passing now |
@tbaudier : my tests didn't show any errors, see https://github.com/BishopWolf/opengate/actions/runs/10093731109/job/27911347164 Something is weird |
I will look at your PR, I think it's due to the rebasing of the branch. Do not modify it for the moment and I will try to do the necessary. |
This error is because filename shall be Path:
and user_info.output is just a filename string without path |
replace os by pathlib in all data setup utilities replace ".." by parent as pathlib standard handle bug in get test path fix errors shown by tests
Select onlyfiles avoiding glob because it select *.pyc files wich do not exist parent / opengate / tests / data does not exists and it will be created during the downloading ct_4mm.raw cannot be find in data_location.iterdir() [pre-commit.ci] Automatic python and c++ formatting
This PR fixes fresh installations errors when parent folders are not created by default giving
These errors were triggered by some tests and are all solved by this PR. The change ensures the folders AND all their parents are created.