Skip to content

Commit

Permalink
Replace black, isort, and flake8 with ruff and remove former three
Browse files Browse the repository at this point in the history
  • Loading branch information
tleonhardt committed Oct 22, 2024
1 parent 45190d4 commit 0d5d115
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 208 deletions.
240 changes: 139 additions & 101 deletions .github/CONTRIBUTING.md

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: Format

on: [push, pull_request]
on: [ push, pull_request ]

permissions:
contents: read
Expand All @@ -11,8 +11,8 @@ jobs:
lint:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]
os: [ ubuntu-latest ]
python-version: [ "3.12" ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -26,8 +26,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install python prerequisites
run: pip install -U --user pip setuptools setuptools-scm black isort
- name: Black
run: python -m black --check --diff .
- name: isort
run: python -m isort --check-only .
run: pip install -U --user ruff
- name: Ruff format
run: ruff format --check
12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: Lint

on: [push, pull_request]
on: [ push, pull_request ]

permissions:
contents: read
Expand All @@ -11,8 +11,8 @@ jobs:
lint:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]
os: [ ubuntu-latest ]
python-version: [ "3.12" ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -26,6 +26,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install python prerequisites
run: pip install -U --user pip setuptools setuptools-scm nox
- name: Lint
run: python -m nox --non-interactive --session validate-${{ matrix.python-version }} -k flake8
run: pip install -U --user ruff
- name: Ruff lint
run: ruff --check
11 changes: 4 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ setuptools = ">=34.4"
wcwidth = ">=0.1.7"

[dev-packages]
black = "*"
cmd2 = {editable = true,path = "."}
cmd2_ext_test = {editable = true,path = "plugins/ext_test"}
cmd2 = { editable = true, path = "." }
cmd2_ext_test = { editable = true, path = "plugins/ext_test" }
codecov = "*"
doc8 = "*"
flake8 = "*"
gnureadline = {version = "*",sys_platform = "== 'darwin'"}
gnureadline = { version = "*", sys_platform = "== 'darwin'" }
invoke = "*"
ipython = "*"
isort = "*"
mypy = "*"
pyreadline3 = {version = ">=3.4",sys_platform = "== 'win32'"}
pyreadline3 = { version = ">=3.4", sys_platform = "== 'win32'" }
pytest = "*"
pytest-cov = "*"
pytest-mock = "*"
Expand Down
37 changes: 3 additions & 34 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,10 @@ addopts =
--cov-report=term
--cov-report=html

[flake8]
count = True
ignore = E203,W503,E704
max-complexity = 26
max-line-length = 127
show-source = True
statistics = True
exclude =
.git
__pycache__
.tox
.nox
.eggs
*.eggs,
.venv,
.idea,
.pytest_cache,
.vscode,
build,
dist,
htmlcov

[isort]
line_length = 1
skip = cmd2/__init__.py,.git,__pycache,.tox,.nox,.venv,.eggs,.idea,.vscode,build,dist.htmlcov
profile = black
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true

[doc8]
ignore-path=docs/_build,.git,.idea,.pytest_cache,.tox,.nox,.venv,.vscode,build,cmd2,examples,tests,cmd2.egg-info,dist,htmlcov,__pycache__,*.egg,plugins
max-line-length=120
verbose=0
ignore-path = docs/_build,.git,.idea,.pytest_cache,.tox,.nox,.venv,.vscode,build,cmd2,examples,tests,cmd2.egg-info,dist,htmlcov,__pycache__,*.egg,plugins
max-line-length = 120
verbose = 0

[mypy]
disallow_incomplete_defs = True
Expand Down
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Programming Language :: Python :: Implementation :: CPython
Topic :: Software Development :: Libraries :: Python Modules
""".splitlines(),
),
)
) # noqa: E128

SETUP_REQUIRES = ['setuptools >= 34.4', 'setuptools_scm >= 3.0']
SETUP_REQUIRES = ['setuptools', 'setuptools_scm']

INSTALL_REQUIRES = [
'pyperclip >= 1.6',
'wcwidth >= 0.1.7',
'pyperclip',
'wcwidth',
]

EXTRAS_REQUIRE = {
Expand All @@ -56,17 +57,14 @@
"gnureadline; sys_platform=='darwin'", # include gnureadline on macOS to ensure it is available in nox env
'codecov',
'coverage',
'pytest>=4.6',
'pytest',
'pytest-cov',
'pytest-mock',
],
# development only dependencies: install with 'pip install -e .[dev]'
'dev': [
'codecov',
'doc8',
'flake8',
'black',
'isort',
'invoke',
'mypy',
'nox',
Expand All @@ -76,11 +74,12 @@
'sphinx',
'sphinx-rtd-theme',
'sphinx-autobuild',
'twine>=1.11',
'ruff',
'twine',
],
'validate': [
'flake8',
'mypy',
'ruff',
'types-setuptools',
],
}
Expand Down
27 changes: 8 additions & 19 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,34 +347,23 @@ def pypi_test(context):
namespace.add_task(pypi_test)


# Flake8 - linter and tool for style guide enforcement and linting
# ruff fast linter
@invoke.task(post=[plugin_tasks.flake8])
def flake8(context):
"""Run flake8 linter and tool for style guide enforcement"""
def lint(context):
"""Run ruff fast linter"""
with context.cd(TASK_ROOT_STR):
context.run("flake8")
context.run("ruff check")


namespace.add_task(flake8)
namespace.add_task(lint)


# Black and isort auto-formatting
# ruff fast formatter
@invoke.task()
def format(context):
"""Run black and isort auto-formatting for code style enforcement"""
"""Run ruff format --checkt"""
with context.cd(TASK_ROOT_STR):
context.run("black . && isort .")
context.run("ruff format --check")


namespace.add_task(format)


# ruff extremely fast Python linter and formatter written in Rust
@invoke.task()
def ruff(context):
"""Run ruff linter and formatter"""
with context.cd(TASK_ROOT_STR):
context.run("ruff check && ruff format --check")


namespace.add_task(ruff)
32 changes: 8 additions & 24 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,7 @@ def _expected_no_editor_error():
"""
EXCEPTION of type '{}' occurred with message: Please use 'set editor' to specify your text editing program of choice.
To enable full traceback, run the following command: 'set debug true'
""".format(
expected_exception
)
""".format(expected_exception)
)

return expected_text
Expand Down Expand Up @@ -1360,9 +1358,7 @@ def test_select_options(select_app, monkeypatch):
1. sweet
2. salty
{} with salty sauce, yum!
""".format(
food
)
""".format(food)
)

# Make sure our mock was called with the expected arguments
Expand All @@ -1388,9 +1384,7 @@ def test_select_invalid_option_too_big(select_app, monkeypatch):
2. salty
'3' isn't a valid choice. Pick a number between 1 and 2:
{} with sweet sauce, yum!
""".format(
food
)
""".format(food)
)

# Make sure our mock was called exactly twice with the expected arguments
Expand Down Expand Up @@ -1419,9 +1413,7 @@ def test_select_invalid_option_too_small(select_app, monkeypatch):
2. salty
'0' isn't a valid choice. Pick a number between 1 and 2:
{} with sweet sauce, yum!
""".format(
food
)
""".format(food)
)

# Make sure our mock was called exactly twice with the expected arguments
Expand All @@ -1445,9 +1437,7 @@ def test_select_list_of_strings(select_app, monkeypatch):
1. math
2. science
Good luck learning {}!
""".format(
'science'
)
""".format('science')
)

# Make sure our mock was called with the expected arguments
Expand All @@ -1468,9 +1458,7 @@ def test_select_list_of_tuples(select_app, monkeypatch):
1. Netflix
2. WebSurfing
Have fun procrasinating with {}!
""".format(
'YouTube'
)
""".format('YouTube')
)

# Make sure our mock was called with the expected arguments
Expand All @@ -1491,9 +1479,7 @@ def test_select_uneven_list_of_tuples(select_app, monkeypatch):
1. Electric Guitar
2. Drums
Charm us with the {}...
""".format(
'Drums'
)
""".format('Drums')
)

# Make sure our mock was called with the expected arguments
Expand Down Expand Up @@ -1523,9 +1509,7 @@ def test_select_return_type(select_app, monkeypatch, selection, type_str):
2. String
3. Method
The return type is {}
""".format(
type_str
)
""".format(type_str)
)

# Make sure our mock was called with the expected arguments
Expand Down

0 comments on commit 0d5d115

Please sign in to comment.