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

Enable Ruff formatting #1655

Merged
merged 7 commits into from
Aug 15, 2024
Merged

Enable Ruff formatting #1655

merged 7 commits into from
Aug 15, 2024

Conversation

VeckoTheGecko
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko commented Aug 13, 2024

Enable Ruff formatting for all Python files in codebase. Line length 88 for docs/*, 120 for the rest.

This PR is intended to isolate these changes (since they're non-breaking, but create a large diff), as well as to act as a place to flag any changes that are unreadable and would benefit from refactoring before being merged.

If a file is particularly bad, we can add them to an exclude list.

To disable the formatter for certain parts of the code, you can add comments to suppress the formatter.

See related discussion in #1653. Contributes to #1620

line-length=88 for docs, line-length=120 for everything else
@VeckoTheGecko VeckoTheGecko mentioned this pull request Aug 13, 2024
Copy link
Contributor Author

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

Just using this PR draft to look through changes and note blocks where code formatting should be disabled (e.g., visualising 2D arrays, or long equations) or code should be refactored.

Will force push and rework the commits in this PR with the changes after I've some some refactoring in fieldset.py in another PR

parcels/application_kernels/TEOSseawaterdensity.py Outdated Show resolved Hide resolved
tests/test_particlesets.py Outdated Show resolved Hide resolved
tests/test_particlesets.py Outdated Show resolved Hide resolved
parcels/fieldfilebuffer.py Show resolved Hide resolved
parcels/fieldfilebuffer.py Show resolved Hide resolved
parcels/kernel.py Outdated Show resolved Hide resolved
parcels/kernel.py Outdated Show resolved Hide resolved
parcels/fieldset.py Outdated Show resolved Hide resolved
parcels/grid.py Show resolved Hide resolved
@VeckoTheGecko VeckoTheGecko marked this pull request as ready for review August 14, 2024 10:28
docs/conf.py Outdated Show resolved Hide resolved
parcels/application_kernels/advection.py Outdated Show resolved Hide resolved
parcels/field.py Outdated Show resolved Hide resolved
parcels/interaction/interactionkernel.py Outdated Show resolved Hide resolved
parcels/interaction/interactionkernel.py Outdated Show resolved Hide resolved
tests/test_kernel_language.py Outdated Show resolved Hide resolved
parcels/particledata.py Outdated Show resolved Hide resolved
parcels/particledata.py Outdated Show resolved Hide resolved
parcels/particleset.py Outdated Show resolved Hide resolved
parcels/particleset.py Outdated Show resolved Hide resolved
VeckoTheGecko and others added 2 commits August 15, 2024 11:32
Co-authored-by: Erik van Sebille <[email protected]>
Technically ISC001 is "incompatible" with ruff format https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules, but this just means that running Ruff format can introduce an ISC001 error.

Bugfix ValueError message due to improper use of implicit concat
@VeckoTheGecko
Copy link
Contributor Author

@erikvansebille I was wanting to run some tests locally, but got an error about not finding the compiler. I exported CC to match clang --version but still get the error. Have you seen this before?


    def _create_compile_process_(self, cmd, src, log):
        with open(log, "w") as logfile:
            try:
                subprocess.check_call(cmd, stdout=logfile, stderr=logfile)
            except OSError:
>               raise RuntimeError(f"OSError during compilation. Please check if compiler exists: {self._cc}")
E               RuntimeError: OSError during compilation. Please check if compiler exists: arm64-apple-darwin23.6.0

parcels/compilation/codecompiler.py:240: RuntimeError

@VeckoTheGecko VeckoTheGecko merged commit fcb5c96 into master Aug 15, 2024
8 checks passed
@VeckoTheGecko VeckoTheGecko deleted the v/ruff branch August 15, 2024 16:30
@erikvansebille
Copy link
Member

@erikvansebille I was wanting to run some tests locally, but got an error about not finding the compiler. I exported CC to match clang --version but still get the error. Have you seen this before?


    def _create_compile_process_(self, cmd, src, log):
        with open(log, "w") as logfile:
            try:
                subprocess.check_call(cmd, stdout=logfile, stderr=logfile)
            except OSError:
>               raise RuntimeError(f"OSError during compilation. Please check if compiler exists: {self._cc}")
E               RuntimeError: OSError during compilation. Please check if compiler exists: arm64-apple-darwin23.6.0

parcels/compilation/codecompiler.py:240: RuntimeError

No, haven't seen his specific error before. But I normally do export CC=gcc when I encounter compiler problems on macOS; that often seems to do the trick

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

Successfully merging this pull request may close these issues.

2 participants