Skip to content

Large code refactor to enable a bunch of additional ruff rulesets #1421

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

Merged
merged 79 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
916386a
Renamed a couple things which needlessely shadowed built-in functions
tleonhardt May 22, 2025
cdab429
Added make commands for format and lint
tleonhardt May 22, 2025
b2beaae
Enable ruff DTZ rules and all datetime calls now use an explicit time…
tleonhardt May 22, 2025
5667864
Enabled ruff EXE ruleset and fixed files with inconsisentcy between e…
tleonhardt May 22, 2025
9c035e4
Enable ruff FIX ruleset that warns about FIXME or TODO in code
tleonhardt May 22, 2025
704c5b0
Enabled ruff FURB ruleset
tleonhardt May 22, 2025
53d97a2
Enable ruff ISC ruleset that warns about implict string concatenation
tleonhardt May 22, 2025
f0ab9b9
Enable ruff LOG ruleset which warns about logger issues
tleonhardt May 22, 2025
e1b2cd8
Enabled ruff PLC ruleset for Pylint naming conventions and exempted o…
tleonhardt May 22, 2025
a09ca98
Accepted a few recommended refactorings from ruff PLR ruleset
tleonhardt May 22, 2025
a130889
Accepted one automated change from ruff PT ruleset
tleonhardt May 22, 2025
1733245
Unabled ruff PYI ruleset for type hint best practices
tleonhardt May 22, 2025
b4f143c
Accept various automated refactorings from ruff RET ruleset that elim…
tleonhardt May 22, 2025
263aa3f
Accepted some automated refactorings from the ruff RUF ruleset
tleonhardt May 22, 2025
374a885
Enable ruff TC type checking ruleset and accept automated refactorings
tleonhardt May 23, 2025
1dc5cc8
Enable ruff TD ruleset
tleonhardt May 23, 2025
9930765
Enable ruff YTT ruleset and fix the one warning
tleonhardt May 23, 2025
bf519a0
Applied a number of automated refactorings from ruff UP ruleset
tleonhardt May 23, 2025
25ecd04
Revert "Applied a number of automated refactorings from ruff UP ruleset"
tleonhardt May 23, 2025
6111972
Add a ruff ignore rule for something requiring Python >= 3.10
tleonhardt May 23, 2025
9007cc7
Apply refactorings from ruff UP ruleset that are safe for Python 3.9+
tleonhardt May 23, 2025
7cad725
Revert "Enable ruff TC type checking ruleset and accept automated ref…
tleonhardt May 23, 2025
5490ed6
Finish reverting ruff rule TC006 changes and added that to the ignore…
tleonhardt May 23, 2025
0c35da8
Enabled ruff PERF ruleset for performance checking
tleonhardt May 23, 2025
336502a
Enabled ruff C4 ruleset and applied fixes
tleonhardt May 23, 2025
d82f215
Add ignore all ruff lint rules that can interfere with ruff format
tleonhardt May 23, 2025
97f921d
Enabled ruff A ruleset for finding symbols shadowing built-in functions
tleonhardt May 24, 2025
96731e8
Moved per-file exemption for A002 to per-line
tleonhardt May 24, 2025
b82c8e9
Eliminated a couple per-file ruff lint exemptions and replaced one wi…
tleonhardt May 24, 2025
27d1ed9
Enabled ruff COM ruleset for forcing commas at the end of container l…
tleonhardt May 24, 2025
7f0a47f
Enabled ruff INP ruleset for warning about modules in an implicit nam…
tleonhardt May 24, 2025
43d6867
Removed unnecessary stuff from top of cmd2/__init__.py
tleonhardt May 24, 2025
4049c1d
Removed stuff from top of argparse_completer that was preventing ruff…
tleonhardt May 24, 2025
6d00a49
Bunch of random clenaups and fixes
tleonhardt May 24, 2025
7f824e2
Applied a few more fixes
tleonhardt May 24, 2025
a727f5a
Enabled ruff PGH ruleset for pygrep-hooks
tleonhardt May 24, 2025
ada27c5
Fix bug in tasks.py do to renaming a built-in to prevent shadowing
tleonhardt May 24, 2025
1a4b13c
Removed unnecessary use of pass
tleonhardt May 24, 2025
47a52ad
Enable ruff PIE ruleset and fix related issues
tleonhardt May 24, 2025
bbba040
Enabled ruff PLW ruleset for PyLint warnings
tleonhardt May 24, 2025
35dc644
Disable framework-specific ruff rulesets for Airflow, Django, FastAPI…
tleonhardt May 24, 2025
9d71795
Applied automated fixes from ruff PT pytest ruleset
tleonhardt May 24, 2025
bab4e67
isort fixes
tleonhardt May 24, 2025
72ff51c
Fixed a bunch of unit test best practices warnings from ruff PT ruleset
tleonhardt May 24, 2025
1c62075
Enabled ruff PT ruleset for pytest best practices
tleonhardt May 24, 2025
a2da48a
Try to fix failing test on Windows
tleonhardt May 24, 2025
05dc6fb
Try to fix path on Windows so test passes
tleonhardt May 24, 2025
c54c9ea
Allow two different types of exceptions for one test since windows te…
tleonhardt May 24, 2025
2e30808
Split test with if for windows vs other
tleonhardt May 24, 2025
9184b5f
Split problematic test into two separate tests and skip one on Windows
tleonhardt May 24, 2025
74b21c8
Recombine test and skip both parts on Windows
tleonhardt May 24, 2025
884758d
Cleaned up remaining import of Dict and List from Typing
tleonhardt May 24, 2025
2c56efa
Enable ruff Q ruleset for quote checking, though many rules are ignor…
tleonhardt May 24, 2025
d503ef9
Enabled ruff SLOT ruleset
tleonhardt May 24, 2025
c9fa34d
Do a bunch of automated refactoring using ruff UP ruleset to do thing…
tleonhardt May 24, 2025
e15c209
Automated refactoring to replace ancient print % formatting with f-st…
tleonhardt May 24, 2025
916802d
Enable ruff UP ruleset for pyupgrade
tleonhardt May 24, 2025
881a985
Automatically applied return type of None for functions/methods that …
tleonhardt May 24, 2025
fd2603e
Replace typing.Never with typing.NoReturn since Never wasn't introduc…
tleonhardt May 24, 2025
0d48428
Apply automated docstring refactoring
tleonhardt May 24, 2025
a86a047
Automatically remove whitespace at top of files
tleonhardt May 24, 2025
c82aecd
Refactor a conditional for readability
tleonhardt May 24, 2025
7b6247f
Move a comment back to where it belongs
tleonhardt May 24, 2025
2dd2909
Removed some else cases that were not needed due to a return in the i…
tleonhardt May 24, 2025
29e64d6
Enable ruff RET ruleset
tleonhardt May 24, 2025
abb8579
Applied some list performance optimizations from ruff RUF ruleset
tleonhardt May 24, 2025
b5a8eeb
Applied automated pydocstyle refactoring outside of test directories
tleonhardt May 24, 2025
c171aaa
Also ignore pydocstyle in examples and plugins directories
tleonhardt May 24, 2025
d67c73d
Disable missing type annotation warnings in test directories
tleonhardt May 24, 2025
a232620
Apply a couple automated ruff SIM refactorings
tleonhardt May 24, 2025
9db905e
Apply some more ruff SIM automated simplifications
tleonhardt May 24, 2025
980d893
Ignore warning about private/protected member access in test directories
tleonhardt May 24, 2025
3f7f318
Apply a few tryceratops automated refactorings
tleonhardt May 24, 2025
f589404
Enable ruff BLE ruleset
tleonhardt May 24, 2025
26cf7b9
Enabled ruff ERA ruleset for eradicating commented-out code
tleonhardt May 24, 2025
88e31eb
Enabled ruff S ruleset for security checks
tleonhardt May 24, 2025
62802c8
Enable ruff N ruleset for pep8 naming conventions
tleonhardt May 24, 2025
9e750bb
Renamed functions in cmd2.ansi.Cursor to be pep8 compliant
tleonhardt May 24, 2025
096d8de
Renamed functions in cmd2.ansi.Cursor to start with underscore to mak…
tleonhardt May 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Breaking Change
- `cmd2` 2.6 supports Python 3.9+ (removed support for Python 3.8)
- Renamed methods in `cmd2.ansi.Cursor` to make it clear they are intended for internal use only as was documented
- Enhancements
- Add support for Python 3.14

Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ check: ## Run code quality tools.
@echo "🚀 Static type checking: Running mypy"
@uv run mypy

.PHONY: format
format: ## Perform ruff formatting
@uv run ruff format

.PHONY: lint
lint: ## Perform ruff linting
@uv run ruff check --fix

.PHONY: typecheck
typecheck: ## Perform type checking
@uv run mypy

.PHONY: test
test: ## Test the code with pytest.
@echo "🚀 Testing code: Running pytest"
Expand Down
25 changes: 8 additions & 17 deletions cmd2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
#
# -*- coding: utf-8 -*-
# flake8: noqa F401
"""This simply imports certain things for backwards compatibility."""

import sys

import argparse
import importlib.metadata as importlib_metadata
import sys

try:
__version__ = importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError: # pragma: no cover
# package is not installed
pass

from typing import List

from .ansi import (
Cursor,
Bg,
Fg,
Cursor,
EightBitBg,
EightBitFg,
Fg,
RgbBg,
RgbFg,
TextStyle,
Expand All @@ -36,34 +31,30 @@

# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER.
# Do this before loading cmd2.Cmd class so its commands use the custom parser.
import argparse

cmd2_parser_module = getattr(argparse, 'cmd2_parser_module', None)
if cmd2_parser_module is not None:
import importlib

importlib.import_module(cmd2_parser_module)

from . import plugin
from .argparse_completer import set_default_ap_completer_type

from .cmd2 import Cmd
from .command_definition import CommandSet, with_default_category
from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS
from .decorators import with_argument_list, with_argparser, with_category, as_subcommand_to
from .decorators import as_subcommand_to, with_argparser, with_argument_list, with_category
from .exceptions import (
Cmd2ArgparseError,
CommandSetRegistrationError,
CompletionError,
PassThroughException,
SkipPostcommandHooks,
)
from . import plugin
from .parsing import Statement
from .py_bridge import CommandResult
from .utils import categorize, CompletionMode, CustomCompletionSettings, Settable

from .utils import CompletionMode, CustomCompletionSettings, Settable, categorize

__all__: List[str] = [
__all__: list[str] = [
'COMMAND_NAME',
'DEFAULT_SHORTCUTS',
# ANSI Exports
Expand Down
Loading
Loading