-
Notifications
You must be signed in to change notification settings - Fork 174
Apply some refactors to code base #1303
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
Conversation
Sweet! I was going to open some PRs for sourcery refactorings but now I don't have to 😄 |
Unfortunately, most of the parsers of https://github.com/cclib/cclib/tree/master/cclib/parser cannot be optimized by It might be worse to think about totally refactoring these functions with code patterns like adapter or factory; see also https://github.com/faif/python-patterns. |
@Anselmoo: Interesting. Are you relying on the cloud version or did you try running The unwieldy |
@Andrew-S-Rosen thx for question
I run locally ... |
Ooof! Oh well... 😅 |
|
|
One cautionary point: Did you set the minimum Python version when you ran sourcery locally (e.g. via the |
I realized that a little later during the PR. I was taking a look at the Lines 1 to 3 in 8800925
where the definitions stay at I am more curious about |
Yup, I just raised that issue in #1305. |
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.
Apologies for not responding to this on time, especially since a lot of good discussion has happened here. Rather than just say this is a "drive by", I'll try and respond to everything here and provide some reasoning for why things are the way they are, for better or for worse.
First, the PR itself. This is difficult to review because of its size and how many files it touches, but the whole thing doesn't need review for us to discuss it. It looks like there are at least three kinds of changes here:
- Positive stylistic changes that are more than just formatting.
- Formatting changes like we'd get with Black or Ruff.
- Some stylistic changes that are harmful.
I've left comments about the kinds of stylistic changes are (not so) good. I'd expect many but not necessarily all of these to be cause by pylint or Ruff, and wouldn't be added as part of reformatting. We would be open to these changes, separate from any formatting changes.
The idea with #1122 is that we would do reformatting in one pass once ~most of the open PRs have been merged, so it can be contained in a single PR with a .git-blame-ignore-revs
that keeps git blame
helpful and doesn't hurt contributors. It turns out that PRs are not getting merged and we're hurting contributors anyway. A reason we are not doing an implementation refactor is that we are working on version 2.0 of the library based on small parser combinators. It's a WIP in the main
branch which will be changed to the default once everything is done. We'll run Black on all the new code as we develop and I'm not sure yet what we'll do on all the old code. It will not be a full rewrite since all the nitty-gritty for each attribute will be taken out of the individual extract
methods.
For versioning, currently supported versions are visible in our CI image repository (https://github.com/shivupa/cclib-ci). There is no particular reason why cclib shouldn't currently work with 3.11 or 3.12. We'll remove 3.7 and 3.8 from CI once 3.11 and 3.12 are added. The full pyproject.toml
migration (#1180) will also happen soon.
Back to this PR. If you are willing to make smaller PRs with some of these non-formatting changes, that would be helpful. I'll close this one once the discussion reaches some conclusion.
@@ -95,22 +95,18 @@ def write_trajectory(filename, ccdata, popname="mulliken", index=None): | |||
|
|||
properties = {} | |||
if hasattr(ccdata, "scfenergies"): | |||
properties.update({"energy": ccdata.scfenergies[i]}) | |||
properties["energy"] = ccdata.scfenergies[i] |
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.
Some groups are against these sorts of changes, but we do think these are positive.
@@ -85,7 +86,7 @@ def makeopenbabel( | |||
obmol.ConnectTheDots() | |||
obmol.PerceiveBondOrders() | |||
obmol.SetTotalSpinMultiplicity(mult) | |||
obmol.SetTotalCharge(int(charge)) | |||
obmol.SetTotalCharge(charge) |
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.
missing = [x for x in required_attrs if not hasattr(data, x)] | ||
|
||
if missing: | ||
if missing := [x for x in required_attrs if not hasattr(data, x)]: |
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.
It isn't written anywhere (yet), and we are still discussing it, but we are generally not going to use the walrus, and it is not due to Python version requirements, but rather readability reasons.
if self.identified_program is None: | ||
self.identified_program = program | ||
if do_break: | ||
break | ||
else: |
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.
This is an an example of a negative change: the comment means something and was accidentally tossed as though the branch was
else:
pass
self.identified_program = None | ||
if do_break: | ||
break | ||
if self.identified_program == None: |
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.
A positive change.
]) | ||
# fmt: on | ||
return atomradius | ||
return np.array( |
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.
This is...not good. It is trashing comments that contain Black directives.
@berquist thx, for your very detailed answer!
I would prefer to use Using https://github.com/chartboost/ruff-action as a GitHub Action allows building dependent CI pipelines and quickly rejecting So, maybe first taking care about the |
I am going to use https://pre-commit.ci/. Local development should allow as close to the same workflow as CI as possible. |
The great thing about https://pre-commit.ci is that it can automatically create pull requests to fix some issues. |
See also: #1307 (comment) |
Closing because #1307 will make this a mess and we have some understanding of the kinds of changes we're looking for. |
Expect the files of
cclibparser
Via https://docs.sourcery.ai applied some basic refactors to make the code a little bit more pythonic