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

Adopting a code formatting standard #511

Merged
merged 13 commits into from
Apr 18, 2024

Conversation

RandomDefaultUser
Copy link
Member

@RandomDefaultUser RandomDefaultUser commented Apr 17, 2024

This PR lays a foundation for having a proper code formatting standard within MALA. It employs black

It

  • provides a basic configuration of black
    • This also introduces a pyproject.toml file; it currently does not replace the setup.py, but complements it; I would postpone fully replacing it until the upcoming hackathon
  • "blackifies" the main code base (including examples and tests)
  • Provides a note in the documentation on using black
  • Gets rid of unused imports (not strictly a code formatting thing, but while I was at it...)

It does not implement automatic code formatting checks. As mentioned in #501 we can setup a CI for this, but I would also postpone this until the upcoming hackathon, when we wanted to tackle the CI anyway.

Closes #501 (except for the CI, which we will add with the coming CI improvements) and #507.

@RandomDefaultUser RandomDefaultUser marked this pull request as draft April 17, 2024 08:53
@RandomDefaultUser
Copy link
Member Author

Ah OK, so I think the pyproject.toml and setup.py did not completely work together yet. But according to this: https://packaging.python.org/en/latest/guides/modernize-setup-py-project/ they should work. I will investigate!

@RandomDefaultUser
Copy link
Member Author

I think I solved the issue with pyproject.toml for now. This is not a permanent solution, as we want to move towards pyproject.toml in full eventually, but it works for now and lets the toml based approach coexist with setup.py
.

Copy link
Member

@elcorto elcorto left a comment

Choose a reason for hiding this comment

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

I made small adjustment sugestions in docs/sourc[docs/source/CONTRIBUTE.md, else this looks good vis-à-vis formatting. Thanks. Please see my other comment re. unused imports.

docs/source/CONTRIBUTE.md Outdated Show resolved Hide resolved
docs/source/CONTRIBUTE.md Outdated Show resolved Hide resolved
@elcorto
Copy link
Member

elcorto commented Apr 17, 2024

Regarding #507, I found 3 left-over ones:

$ ruff check --select F401 $(find mala -name "*.py") | grep -v __init__
mala/descriptors/atomic_density.py:136:32: F401 [*] `lammps.lammps` imported but unused
mala/descriptors/bispectrum.py:141:32: F401 [*] `lammps.lammps` imported but unused
mala/descriptors/minterpy_descriptors.py:95:32: F401 [*] `lammps.lammps` imported but unused

All have the form

        # For version compatibility; older lammps versions (the serial version
        # we still use on some machines) have these constants as part of the
        # general LAMMPS import.
        try:
            from lammps import constants as lammps_constants
        except ImportError:
            from lammps import lammps

but the fallback module lammps is never used in the code. Given the comment, I suspect this to work:

        try:
            from lammps import constants as lammps_constants
        except ImportError:
            from lammps import lammps as lammps_constants

RandomDefaultUser and others added 2 commits April 17, 2024 23:08
Co-authored-by: Steve Schmerler <[email protected]>
Co-authored-by: Steve Schmerler <[email protected]>
@RandomDefaultUser
Copy link
Member Author

RandomDefaultUser commented Apr 17, 2024

You're right, there are three leftovers. I consciously left them in, because I am not entirely sure myself anymore how the old version handled lammps_constants. Looking at your suggestion and reflecting at what happens there made me realize there is no point in being compatible here. A LAMMPS version that old will not work with our current codebase anymore.
I will delete these lines, and then all unused imports should be gone.

@elcorto elcorto marked this pull request as ready for review April 18, 2024 06:48
Copy link
Member

@elcorto elcorto left a comment

Choose a reason for hiding this comment

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

Thanks, looks all good now.

@RandomDefaultUser RandomDefaultUser merged commit 8af3efe into develop Apr 18, 2024
6 checks passed
@RandomDefaultUser RandomDefaultUser deleted the code_formatting_standard branch April 18, 2024 07:13
@elcorto elcorto mentioned this pull request Apr 18, 2024
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.

Adopt a code formatting standard
2 participants