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

Import slayer #3033

Merged
merged 11 commits into from Aug 23, 2023
Merged

Import slayer #3033

merged 11 commits into from Aug 23, 2023

Conversation

loriab
Copy link
Member

@loriab loriab commented Aug 21, 2023

Description

So in the course of working on DDD/pydantic, a fix I needed triggered the dreaded "circular import" error, which anyone who's tried to alter the driver's fragile import structure has probably seen, too. Being sick of this, I located https://medium.com/brexeng/avoiding-circular-imports-in-python-7c35ec8145ed with advice to do from .driver import energy, not from psi4.driver.driver import energy. So that's the first pass on the driver imports. This fixes my circular import problem and makes it easier to find others.

Since all the imports are churned anyways, I set up isort (that is, you can run isort on the repo, not that it's enforced on the repo). This is a utility (https://pycqa.github.io/isort/index.html) that sorts all the imports at the top of the file into stdlib, third_party, and first_party blocks and then alphabetizes the imports within. It also effectively tests the fragility of the import structure by jumbling them all into alphabetical order. Attempts in past years to run isort led to circular imports and a retreat. This time I was able to fix the single one that came about.

Third pass is that I ran autoflake on the driver to remove unused stdlib imports. It also removed some pass on empty fns that weren't needed because the docstring suffices for the syntax.

User notes

  • the import structure has changed. you might need to add standard library imports to your input files if you use them (e.g., import math before math.pi) that previously were preloaded by psi4.

Dev notes & details

Checklist

  • tests added for any new features
  • full tests pass

Status

  • Ready for review
  • Ready for merge

@loriab loriab added the cleanup For issues where the goal is to make Psi4 a little cleaner. label Aug 21, 2023
@loriab loriab added this to the Psi4 1.9 milestone Aug 22, 2023
Copy link
Contributor

@JonathonMisiewicz JonathonMisiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubber-stamped.

@loriab loriab added this pull request to the merge queue Aug 23, 2023
Merged via the queue into psi4:master with commit b5f5dea Aug 23, 2023
5 checks passed
This was referenced Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup For issues where the goal is to make Psi4 a little cleaner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants