Skip to content

Commit

Permalink
Extract Ruff config to won file and sync with skeleton (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Aug 24, 2024
1 parent 8cee312 commit c80f9b0
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 173 deletions.
30 changes: 20 additions & 10 deletions Dolphin scripts/typings/dolphin.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
"""
Aggregator module of all dolphin-provided modules.
It lets people import the dolphin-provided modules in a more
intuitive way. For example, people can then do this:
`from dolphin import event, memory`
```
from dolphin import event, memory
```
instead of:
`import dolphin_event as event`
`import dolphin_memory as memory`
```
import dolphin_event as event
import dolphin_memory as memory
```
Valid:
`import dolphin`
`from dolphin import *`
`from dolphin import event`
`import dolphin_event as event`
```
import dolphin
from dolphin import *
from dolphin import event
import dolphin_event as event
```
Invalid:
`import dolphin.event`
`from dolphin.event import ...`
""" # noqa: D400,D415 # Tries to add a . at the end of an import line
```
import dolphin.event
from dolphin.event import ...
```
"""

import dolphin_controller as controller
import dolphin_event as event
import dolphin_gui as gui
Expand Down
1 change: 1 addition & 0 deletions Dolphin scripts/typings/dolphin_controller.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Module for programmatic inputs.
Currently, only for GameCube, Wiimote, Nunchuck buttons and Wii IR (pointing).
No acceleration or other extensions data yet.
"""

from typing import TypedDict, type_check_only

@type_check_only
Expand Down
3 changes: 1 addition & 2 deletions Dolphin scripts/typings/dolphin_event.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Module for awaiting or registering callbacks on all events emitted by Dolphin.
The odd-looking Protocol classes are just a lot of syntax to essentially describe
the callback's signature. See https://www.python.org/dev/peps/pep-0544/#callback-protocols
"""

from collections.abc import Callable
from typing import Protocol, type_check_only

Expand All @@ -12,7 +13,6 @@ def on_frameadvance(callback: Callable[[], None] | None) -> None:

async def frameadvance() -> None:
"""Awaitable event that completes once the game has rendered a new frame."""

@type_check_only
class _MemorybreakpointCallback(Protocol):
def __call__(self, is_write: bool, addr: int, value: int) -> None:
Expand All @@ -34,7 +34,6 @@ def on_memorybreakpoint(callback: _MemorybreakpointCallback | None) -> None:

async def memorybreakpoint() -> tuple[bool, int, int]:
"""Awaitable event that completes once a previously added memory breakpoint is hit."""

@type_check_only
class _SaveStateCallback(Protocol):
def __call__(self, is_slot: bool, slot: int, /) -> None:
Expand Down
161 changes: 0 additions & 161 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,164 +1,3 @@
# The source skeleton for this configuration can be found at
# https://github.com/BesLogic/shared-configs/blob/main/ruff.toml
# Modifications to this file that are not project-specific should also be done upstream.
# These configs were last updated for ruff==0.3.7

# https://docs.astral.sh/ruff/configuration/
[tool.ruff]
line-length = 100
preview = true
# Change this to the oldest supported version by your application
# (same as https://github.com/Felk/dolphin/releases/tag/scripting-preview3 )
target-version = "py311"
# Exclude auto-generated files
# exclude = [""]

# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[tool.ruff.lint.flake8-implicit-str-concat]
allow-multiline = false

# https://docs.astral.sh/ruff/settings/#isort
[tool.ruff.lint.isort]
combine-as-imports = true
split-on-trailing-comma = false

# https://docs.astral.sh/ruff/settings/#mccabe
[tool.ruff.lint.mccabe]
# Hard limit, arbitrary to 4 bytes
# max-complexity = 31
# Arbitrary to 2 bytes, same as SonarLint
max-complexity = 15

[tool.ruff.lint.pylint]
# Arbitrary to 1 byte, same as SonarLint
max-args = 7
# At least same as max-complexity
max-branches = 15

[tool.ruff.lint]
select = ["ALL"]
# https://docs.astral.sh/ruff/rules/
ignore = [
###
# Not needed or wanted
###
"D1", # pydocstyle Missing doctring
"D401", # pydocstyle: non-imperative-mood
"EM", # flake8-errmsg
"EXE", # flake8-executable
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
"INP", # flake8-no-pep420
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
# Short messages are still considered "long" messages
"TRY003", # tryceratops : raise-vanilla-args
# Don't remove commented code, also too inconsistant
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Negative performance impact and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # non-pep604-isinstance
# Checked by type-checker (pyright/mypy)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
"TCH", # flake8-type-checking
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
"ARG002", # Unused method argument
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
"D203", # pydocstyle: one-blank-line-before-class
"D212", # pydocstyle: multi-line-summary-first-line
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
"TD001", # flake8-todos: invalid-todo-tag

###
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
###
"FIX", # flake8-fixme
# Not all TODOs are worth an issue, this would be better as a warning
"TD003", # flake8-todos: missing-todo-link

# False-positives
"TCH004", # https://github.com/astral-sh/ruff/issues/3821

###
# Conflict with formatter (you can remove this section if you don't use Ruff as a formatter)
###
# "COM812", # missing-trailing-comma
# "ISC001", # single-line-implicit-string-concatenation

###
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
###
"DOC201", # docstring-missing-returns
"DOC402", # docstring-missing-yields
"DOC501", # docstring-missing-exception
# "D406", # new-line-after-section-name, conflicts with DOC
# "D407", # dashed-underline-after-section, conflicts with DOC

###
# Specific to this project
###
# Slows down tuple comprehensions in --preview mode https://github.com/astral-sh/ruff/issues/12912
"C409", # unnecessary-literal-within-tuple-call
"CPY001", # missing-copyright-notice: Assume license from root
# This is a relatively small, low contributors project. Git blame suffice.
"TD002", # missing-todo-author

### FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
### https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
# "",
]

[tool.ruff.lint.per-file-ignores]
"**/typings/**/*.pyi" = [
"F811", # Re-exports false positives
# The following can't be controlled for external libraries:
"A", # Shadowing builtin names
"E741", # ambiguous variable name
"F403", # `from . import *` used; unable to detect undefined names
"FBT", # flake8-boolean-trap
"ICN001", # unconventional-import-alias
"N8", # Naming conventions
"PLC2701", # Private name import
"PLR0904", # Too many public methods
"PLR0913", # Argument count
"PLR0917", # Too many positional arguments
"PLW3201", # misspelled dunder method name
"PYI042", # CamelCase TypeAlias
# Stubs can sometimes re-export entire modules.
# Issues with using a star-imported name will be caught by type-checkers.
"F405", # may be undefined, or defined from star imports
]

###
# Specific to this project
###
"Dolphin scripts/Entrance Randomizer/**.py" = [
"F405", # Allow * import from constants since we use a lot, but not all
"PLW0603", # Using globals due to the nature of this script
# Print are used as debug logs
"T20", # flake8-print
# Project is too simple to create our own errors
"TRY002", # raise-vanilla-class
# We don't do cryptography in this project
"S311", # suspicious-non-cryptographic-random-usage
]
"Dolphin scripts/Entrance Randomizer/__main__.py" = [
"E402", # Python path must first be set in __main__
]
"Dolphin scripts/typings/*.pyi" = [
"D205", # External stubs, allow docstring w/o summary line
"E501", # External stubs, ignore line-length
"PYI021", # No source, keep docstrings
]

### Possible future ruff.pylint configurations
# https://github.com/charliermarsh/ruff/issues/970
# # Arbitrary to 2 bytes
# max-attributes = 15
# max-locals = 15

# https://github.com/hhatto/autopep8#usage
# https://github.com/hhatto/autopep8#more-advanced-usage
[tool.autopep8]
Expand Down
153 changes: 153 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# The source skeleton for this configuration can be found at
# https://github.com/BesLogic/shared-configs/blob/main/ruff.toml
# Modifications to this file that are not project-specific should also be done upstream.
# These configs are incompatible with ruff<0.5.7

# https://docs.astral.sh/ruff/configuration/
line-length = 100
preview = true
# Change this to the oldest supported version by your application
# (same as https://github.com/Felk/dolphin/releases/tag/scripting-preview3 )
target-version = "py311"
# Exclude auto-generated files
# exclude = [""]

# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[lint.flake8-implicit-str-concat]
allow-multiline = false

# https://docs.astral.sh/ruff/settings/#isort
[lint.isort]
combine-as-imports = true
split-on-trailing-comma = false

# https://docs.astral.sh/ruff/settings/#mccabe
[lint.mccabe]
# Arbitrary to 2 bytes, same as SonarLint
max-complexity = 15

[lint.pylint]
# Arbitrary to 1 byte, same as SonarLint
max-args = 7
# At least same as max-complexity
max-branches = 15

[lint]
select = ["ALL"]
# https://docs.astral.sh/ruff/rules/
ignore = [
###
# Not needed or wanted
###
"D1", # pydocstyle Missing doctring
"D401", # pydocstyle: non-imperative-mood
"EM", # flake8-errmsg
"EXE", # flake8-executable
# This is often something we can't control: https://github.com/astral-sh/ruff/issues/9497
# Also false-positive with positional-only arguments: https://github.com/astral-sh/ruff/issues/3247
"FBT003", # flake8-boolean-trap: boolean-positional-value-in-call
"INP", # flake8-no-pep420
"ISC003", # flake8-implicit-str-concat: explicit-string-concatenation
# Short messages are still considered "long" messages
"TRY003", # tryceratops : raise-vanilla-args
# Don't remove commented code, also too inconsistant
"ERA001", # eradicate: commented-out-code
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # flake8-simplify: use-contextlib-suppress
# Negative performance impact and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # non-pep604-isinstance
# deprecated and is actually slower for cases relevant to unpacking: https://github.com/astral-sh/ruff/issues/12754
"UP027", # unpacked-list-comprehension
# Checked by type-checker (pyright/mypy)
"ANN", # flake-annotations
"PGH003", # blanket-type-ignore
"TCH", # flake8-type-checking
# Already shown by Pylance, checked by pyright, and can be caused by overloads.
"ARG002", # Unused method argument
# We want D213: multi-line-summary-second-line and D211: no-blank-line-before-class
"D203", # pydocstyle: one-blank-line-before-class
"D212", # pydocstyle: multi-line-summary-first-line
# Allow differentiating between broken (FIXME) and to be done/added/completed (TODO)
"TD001", # flake8-todos: invalid-todo-tag

###
# These should be warnings (https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774)
###
"FIX", # flake8-fixme
# Not all TODOs are worth an issue, this would be better as a warning
"TD003", # flake8-todos: missing-todo-link

# False-positives
"TCH004", # https://github.com/astral-sh/ruff/issues/3821

###
# Conflict with formatter (you can remove this section if you don't use Ruff as a formatter)
###
# "COM812", # missing-trailing-comma
# "ISC001", # single-line-implicit-string-concatenation

###
# Rules about missing special documentation. Up to you if you wanna enable these, you must also disable D406, D407
###
"DOC201", # docstring-missing-returns
"DOC402", # docstring-missing-yields
"DOC501", # docstring-missing-exception
# "D406", # new-line-after-section-name, conflicts with DOC
# "D407", # dashed-underline-after-section, conflicts with DOC

###
# Specific to this project
###
# Slows down tuple comprehensions in --preview mode https://github.com/astral-sh/ruff/issues/12912
"C409", # unnecessary-literal-within-tuple-call
"CPY001", # missing-copyright-notice: Assume license from root
# This is a relatively small, low contributors project. Git blame suffice.
"TD002", # missing-todo-author

### FIXME/TODO: I'd normally set them as temporarily warnings, but no warnings in Ruff yet:
### https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
# "",
]

[lint.per-file-ignores]
"**/typings/**/*.pyi" = [
"F811", # Re-exports false positives
# The following can't be controlled for external libraries:
"A", # Shadowing builtin names
"E741", # ambiguous variable name
"F403", # `from . import *` used; unable to detect undefined names
"FBT", # flake8-boolean-trap
"ICN001", # unconventional-import-alias
"N8", # Naming conventions
"PLC2701", # Private name import
"PLR0904", # Too many public methods
"PLR0913", # Argument count
"PLR0917", # Too many positional arguments
"PLW3201", # misspelled dunder method name
"PYI042", # CamelCase TypeAlias
# Stubs can sometimes re-export entire modules.
# Issues with using a star-imported name will be caught by type-checkers.
"F405", # may be undefined, or defined from star imports
]

###
# Specific to this project
###
"Dolphin scripts/Entrance Randomizer/**.py" = [
"F405", # Allow * import from constants since we use a lot, but not all
"PLW0603", # Using globals due to the nature of this script
# Print are used as debug logs
"T20", # flake8-print
# Project is too simple to create our own errors
"TRY002", # raise-vanilla-class
# We don't do cryptography in this project
"S311", # suspicious-non-cryptographic-random-usage
]
"Dolphin scripts/Entrance Randomizer/__main__.py" = [
"E402", # Python path must first be set in __main__
]
"Dolphin scripts/typings/*.pyi" = [
"D205", # External stubs, allow docstring w/o summary line
"E501", # External stubs, ignore line-length
"PYI021", # No source, keep docstrings
]

0 comments on commit c80f9b0

Please sign in to comment.