-
Notifications
You must be signed in to change notification settings - Fork 875
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
Chargemol autodownloads #3474
Chargemol autodownloads #3474
Conversation
# mock getenv to simulate that DDEC6_ATOMIC_DENSITIES_DIR is not set | ||
monkeypatch.setattr(os, "getenv", lambda *args, **kwargs: None) | ||
def fake_download(self, version: str = "latest", verbose: bool = True) -> None: | ||
extraction_path = "~/.cache/pymatgen/ddec" |
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.
Be careful with path handling. You don't want to impose a given OS.
I recommend using the pathlib
library instead.
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.
Actually, forward slashes work under windows. I've only encountered a few arcane cases where they cause problems. See the pmg
test suite. Runs on Windows in GHA and it's all forward slashes.
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.
The ~
is not valid on Windows, although I guess you get out of that pickle by doing os.path.expanduser
.
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.
Doing os.path.expanduser(extraction_path)
expands to 'C:\\Users\\asros/.cache/pymatgen/ddec'
which will work with os.makedir
since os
is smart. So, tests will pass, but you're playing with fire a bit... 😅
Guess this is more personal preference because I'm a Windows user tired of opening PRs to fix paths, although it's indeed fine here after closer inspection.
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.
Yeah, i'm running a live experiment. So far it's only caused issues 2 or 3 times and they were niche. Feel like so far the readability gain from not using os.path.join
was well worth it. Need to reconsider if sth non-niche comes up.
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.
Feel free to ignore these comments then @chiang-yuan. Good to know, @janosh.
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.
Thanks @Andrew-S-Rosen . I actually prefer pathlib
since it is a newer standard over os.path
. I was just following what we already have in the code 😉 Will change it whenever appropriate :)
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.
Seems it doesn't really matter :)
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.
while pathlib
has some nice features, i find it a bit too OOP with resulting perf overhead compared to os.path
(see e.g. https://youtu.be/tFrh9hKMS6Y). although admittedly the speed diff doesn't matter in practice.
fake_zip_path = os.path.expanduser(f"{extraction_path}/fake_file.zip") | ||
fake_folder_path = os.path.expanduser(f"{extraction_path}/atomic_densities") |
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.
Same comments here regarding path handling. Do not hard-code slashes. There are more below. You get the idea.
@janosh I use monkeypatch to mock the class method directly (rather than through module namespace) and add
|
65eb4fe
to
8090776
Compare
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.
@chiang-yuan thanks! i think there are a lot of unintended white space/indentation changes from trailing commas in this PR?
pymatgen/core/structure.py
Outdated
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.
can you revert the trailing comma insertions in this file and tests/command_line/test_chargemol_caller.py
? makes it hard to spot meaningful changes
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.
hmmm sorry let me check... perhaps my ruff is not working correctly
@chiang-yuan I would like to merge this, but no tests are being run for some reason. Only pre-commit was run. Pls make sure the test suite is run properly. Thanks. |
i'll close this for the same reason as #3465 (i.e. stalled). feel free to re-open if you want to resolve merge conflicts @chiang-yuan. |
Try to close #3465
Checklist
ruff
.mypy
.If applicable, new classes/functions/modules haveduecredit
@due.dcite
decorators to reference relevant papers by DOI (example)Tip: Install
pre-commit
hooks to auto-check types and linting before every commit: