Skip to content

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

@VeckoTheGecko VeckoTheGecko marked this pull request as ready for review August 14, 2024 10:28
VeckoTheGecko and others added 2 commits August 15, 2024 11:32
Co-authored-by: Erik van Sebille <e.vansebille@uu.nl>
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
@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.

3 participants