-
Notifications
You must be signed in to change notification settings - Fork 129
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
REFACTOR: From os.path to pathlib #5495
base: main
Are you sure you want to change the base?
Conversation
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please Path
from pathlib
unless there is a reason not to ?
This would require to add imports in files such as from pathlib import Path
.
Also, could you join path instances with /
as follow:
path = Path("some/path/i/work")
other_path = path / "with"
other_path
will lead to "some/path/i/work/with"
Please not that the purpose of this draft was two fold:
Having said that, this is PR is nowhere near to be reviewed - that's why I hadn't assigned reviewers. With respect to your review: First point
which is simply an extension of what you requested. I just wanted to clarify the use of PurePath as well.
the project name needs to be converted to a string, otherwise it will break the examples. We should decide if we want to make the str casting in the example itself or in the member of the object itself. Second pointAlso, could you join path instances with
versus
In this example it's easier to read because it's a single line, but toss it into the rest of the code and sometimes it's hard to read, even more if you need to break the line and need to add . Granted you can also let pycharm add a line break but it would wrap things extra parentheses. Once again, it's about readability.
Let's take the following example The alternative would be
One last thing I want to mention is that as I said in the beginning, this PR is nowhere to be reviewed. The reason is because once I finish the trickier cases with .replace and such, I believe the best practice would be to refactor the way paths are defined all together with reusable functions/methods get/set path, extension, file name. Otherwise it'll be quite hard to maintain for any future changes that may occur adding to our technical debt. Please let me know if this addresses the points made, and you agree with my coding style. Otherwise, I'll just go ahead and make the requested changes. Let me know what you think. /Jon |
Honestly, what I'm thinking is to redo everything in reusable functions. Then the implementation would be ok either way. Some of the os.path methods are just very elaborate ways to do very simple tasks- like fetching the name of the file, or the extension of the file. I think it would be better if I just create some generic functions that can be used by others in the future. This way it's easier to maintain. That would imply closing this PR for now, and working on a new PR with a fresh commit. If you agree with this approach, where should I put these methods? Any thoughts on it? |
I'm not sure to understand everything about the method you mentioned. Could you elaborate ? |
Description
Refactoring pyaedt to use python's documentation suggested replacement of os.path, namely pathlib
Issue linked
#5180
Checklist