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

Chargemol autodownloads #3474

Open
wants to merge 5 commits into
base: chargemol-auto-download
Choose a base branch
from

Conversation

chiang-yuan
Copy link
Contributor

@chiang-yuan chiang-yuan commented Nov 15, 2023

Try to close #3465

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

# 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"
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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 :)

Copy link
Member

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 :)

Copy link
Member

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.

Comment on lines +99 to +100
fake_zip_path = os.path.expanduser(f"{extraction_path}/fake_file.zip")
fake_folder_path = os.path.expanduser(f"{extraction_path}/atomic_densities")
Copy link
Member

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.

@chiang-yuan
Copy link
Contributor Author

chiang-yuan commented Jan 4, 2024

@janosh I use monkeypatch to mock the class method directly (rather than through module namespace) and add fake_path to atomic_densities_path to force the mock download function to be called. I think this work minimally already. Let me know what you think.

atomic_densities_path="fake_path", # force _download_and_unzip_atomic_densities to be called

Copy link
Member

@janosh janosh left a 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?

Copy link
Member

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

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

None yet

3 participants