Skip to content

Commit

Permalink
Merge pull request #682 from octue/switch-to-ruff-tooling
Browse files Browse the repository at this point in the history
Switch to ruff developer tooling
  • Loading branch information
thclark authored Sep 18, 2024
2 parents d948b8f + e203b0b commit 25b6c08
Show file tree
Hide file tree
Showing 23 changed files with 444 additions and 601 deletions.
20 changes: 4 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,19 @@
// Set *default* container specific settings.json values on container create.
"settings": {
"austin.mode": "Wall time",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"jupyter.widgetScriptSources": ["jsdelivr.com", "unpkg.com"],
"python.locator": "native",
"prettier.prettierPath": "/usr/local/prettier",
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.provider": "black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.languageServer": "Pylance",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.enabled": true,
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
// Line length to match black settings
// Disabling specific messages:
// - To find the details do: /usr/local/py-utils/bin/pylint --list-msgs
// - Disable missing-module-docstring (C0114) because we don't document modules routinely, just their members
// - Disable invalid-name (C0103) because pylint thinks that eg 'x', 'df', 'np' are invalid due to their lengths
"python.linting.pylintArgs": [
"--max-line-length=120",
"--disable=missing-module-docstring,invalid-name"
],
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.pythonPath": "/usr/local/bin/python",
"terminal.integrated.defaultProfile.linux": "zsh"
},
Expand All @@ -51,7 +38,8 @@
"ms-toolsai.jupyter-keymap",
"ms-vsliveshare.vsliveshare",
"p403n1x87.austin-vscode",
"ritwickdey.liveserver"
"ritwickdey.liveserver",
"charliermarsh.ruff"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ terraform/gcp-credentials.json
.terraform

*.jsonl

# Avoid committing ruff cache files
.ruff_cache
28 changes: 7 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,12 @@ repos:
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args: ["--line-length", "120"]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- "pep8-naming"
args:
- --ignore-names=setUp,tearDown,setUpClass,tearDownClass,asyncSetUp,asyncTearDown,setUpTestData,failureException,longMessage,maxDiff,startTestRun,stopTestRun
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
Expand All @@ -50,10 +36,10 @@ repos:
language_version: python3
additional_dependencies:
- "poetry==1.2.0b2"
- "Sphinx>=4,<5"
- "Sphinx>=5,<8"
- "sphinx-rtd-theme>=1,<2"
- "sphinx-tabs>=3,<4"
- "sphinx-toolbox==3.0.0"
- "sphinx-toolbox>=3"
- "git+https://github.com/octue/octue-sdk-python.git@main"

- repo: https://github.com/windpioneers/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion octue/cloud/pub_sub/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
retry_count,
timeout=60,
*args,
**kwargs
**kwargs,
):
super().__init__(*args, **kwargs)
self.question_uuid = question_uuid
Expand Down
1 change: 0 additions & 1 deletion octue/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def _upload_manifest(self, manifest_type, question_diagnostics_path):

# Upload each dataset and update its path in the manifest.
for dataset_name, dataset_path in manifest["datasets"].items():

# Handle manifests containing serialised datasets instead of just the datasets' paths. Datasets can be in
# this state when serialised if they were instantiated using the `files` argument.
if isinstance(dataset_path, dict):
Expand Down
1 change: 1 addition & 0 deletions octue/essentials/monitor_messages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""A module containing helper functions for sending monitor messages that conform to the Octue essential monitor
message schema https://jsonschema.registry.octue.com/octue/essential-monitors/0.0.2.json
"""

import logging
from datetime import datetime, timezone

Expand Down
1 change: 0 additions & 1 deletion octue/mixins/filterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def _split_filter_name(self, filter_name):
*attribute_names, filter_action = filter_name.split("__")

if not attribute_names:

raise exceptions.InvalidInputException(
f"Invalid filter name {filter_name!r}. Filter names should be in the form "
f"'<attribute_name_0>__<attribute_name_1>__<...>__<filter_kind>' with at least one attribute name "
Expand Down
1 change: 0 additions & 1 deletion octue/mixins/hashable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class Hashable:

_ATTRIBUTES_TO_HASH = None
_HASH_TYPE = "CRC32C"

Expand Down
2 changes: 0 additions & 2 deletions octue/resources/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def cloud_path(self, path):
:return None:
"""
if path is None:

if not self.exists_locally:
raise CloudLocationNotSpecified(
"The cloud path cannot be reset because this datafile only exists in the cloud."
Expand Down Expand Up @@ -732,7 +731,6 @@ def __exit__(self, *args):
self._fp.close()

if any(character in self.mode for character in self.MODIFICATION_MODES):

if self.datafile.exists_in_cloud:
self.datafile.upload(update_cloud_metadata=self._update_metadata)

Expand Down
2 changes: 0 additions & 2 deletions octue/resources/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ def add(self, datafile, path_in_dataset=None):

# Add a cloud datafile to a cloud dataset.
if datafile.exists_in_cloud:

if datafile.cloud_path != new_cloud_path and not datafile.cloud_path.startswith(self.path):
datafile.upload(new_cloud_path)

Expand Down Expand Up @@ -350,7 +349,6 @@ def download(self, local_directory=None):
datafiles_and_paths = []

for file in self.files:

if not file.exists_in_cloud:
continue

Expand Down
1 change: 1 addition & 0 deletions octue/resources/service_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
the "oneOf" field of the "backend" key of the children schema in `Twined`, which is located at
`twined/schema/children_schema.json`.
"""

from abc import ABC

from octue import exceptions
Expand Down
1 change: 0 additions & 1 deletion octue/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ def run(
analysis_log_level=analysis_log_level,
extra_log_handlers=extra_log_handlers,
):

analysis = Analysis(
id=analysis_id,
twine=self.twine,
Expand Down
1 change: 0 additions & 1 deletion octue/templates/template-fractal/fractal/mandelbrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def mandelbrot(width, height, x_range, y_range, n_iterations, c=None):
# Simple loop to render the fractal set. This is not efficient python and would be vectorised in production, but the
# purpose here is just to provide a simple demo.
for idx, a in numpy.ndenumerate(x):

# Get default constant c (Mandelbrot sets use spatial coordinates as constants)
if c is None:
b = y[idx]
Expand Down
Loading

0 comments on commit 25b6c08

Please sign in to comment.