Skip to content

Commit

Permalink
Migrate to a modern Python project where all configuration is in pypr…
Browse files Browse the repository at this point in the history
…oject.toml

This includes the following:
- Remove setup.cfg
- Remove setup.py
- Update pyproject.toml with project and tool settings
- Add build module to Pipfile for building using pyproject.toml
- Add ruff fast linter/formatter to Pipfile
- Some very initial minor fixes based on ruff
- Update invoke tasks in tasks.py to not use setup.py
  • Loading branch information
tleonhardt committed Oct 18, 2024
1 parent 3062aaa commit a330f77
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 176 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Pipfile.lock

# pyenv version file
.python-version

# uv
uv.lock
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ wcwidth = ">=0.1.7"

[dev-packages]
black = "*"
build = "*"
cmd2 = {editable = true,path = "."}
cmd2_ext_test = {editable = true,path = "plugins/ext_test"}
codecov = "*"
doc8 = "*"
flake8 = "*"
Flake8-pyproject = "*"
gnureadline = {version = "*",sys_platform = "== 'darwin'"}
invoke = "*"
ipython = "*"
Expand All @@ -24,6 +26,7 @@ pyreadline3 = {version = ">=3.4",sys_platform = "== 'win32'"}
pytest = "*"
pytest-cov = "*"
pytest-mock = "*"
ruff = "*"
sphinx = "*"
sphinx-autobuild = "*"
sphinx-rtd-theme = "*"
Expand Down
1 change: 1 addition & 0 deletions cmd2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@
'CompletionMode',
'CustomCompletionSettings',
'Settable',
'PassThroughException',
]
2 changes: 1 addition & 1 deletion cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
return False

# Flags have to start with a prefix character
if not token[0] in parser.prefix_chars:
if token[0] not in parser.prefix_chars:
return False

# If it looks like a negative number, it is not a flag unless there are negative-number-like flags
Expand Down
2 changes: 1 addition & 1 deletion cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5537,7 +5537,7 @@ def cmdloop(self, intro: Optional[str] = None) -> int: # type: ignore[override]
"""
# cmdloop() expects to be run in the main thread to support extensive use of KeyboardInterrupts throughout the
# other built-in functions. You are free to override cmdloop, but much of cmd2's features will be limited.
if not threading.current_thread() is threading.main_thread():
if threading.current_thread() is not threading.main_thread():
raise RuntimeError("cmdloop must be run in the main thread")

# Register signal handlers
Expand Down
213 changes: 212 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,87 @@
[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]
requires = [
"setuptools>=64",
"setuptools-scm>=8",
]
build-backend = "setuptools.build_meta"

[project]
name = "cmd2"
description = "Quickly build feature-rich and user-friendly interactive command line applications in Python"
readme = "README.md"
license.file = "LICENSE"
authors = [ { name = "cmd2 Contributors" } ]
requires-python = ">=3.8"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries",
]
keywords = [
"cmd",
"command",
"console",
"prompt",
]
dynamic = [
"version",
]
dependencies = [
"pyperclip",
"wcwidth",
'gnureadline ; platform_system == "Darwin"',
'pyreadline3 ; platform_system == "Windows"',
]
[project.optional-dependencies]
dev = [
"codecov",
"doc8",
"flake8",
"Flake8-pyproject",
"black",
"isort",
"invoke",
"mypy",
"nox",
"pytest",
"pytest-cov",
"pytest-mock",
"sphinx",
"sphinx-rtd-theme",
"sphinx-autobuild",
"twine",
]
test = [
"codecov",
"coverage",
"pytest",
"pytest-cov",
"pytest-mock",
]
validate = [
"flake8",
"Flake8-pyproject",
"mypy",
"types-setuptools",
]
[project.urls]
documentation = "https://cmd2.readthedocs.io/"
repository = "https://github.com/python-cmd2/cmd2"

[tool.black]
skip-string-normalization = true
Expand All @@ -25,3 +107,132 @@ exclude = '''
| htmlcov
)/
'''

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

[tool.flake8]
count = true
ignore = ['E203', 'E704', 'W503']
max-complexity = 26
max-line-length = 127
per-file-ignores = [
'__init__.py:F401',
]
show-source = true
statistics = true
exclude = [
"__pycache__",
".eggs",
"*.eggs",
".git",
".idea",
".nox",
".pytest_cache",
".tox",
".venv",
".vscode",
"build",
"dist",
"htmlcov",
]

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

[tool.mypy]
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_defs = true
exclude = [
"examples",
"plugins",
]
strict = true
show_column_numbers = true
show_error_codes = true
show_error_context = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_ignores = false
warn_unreachable = true

[tool.pytest.ini_options]
minversion = "8"
addopts = "--cov=cmd2 --cov-append --cov-report=term --cov-report=html"
testpaths = [
"tests",
]

[tool.ruff]
src = ["cmd2"]
fix = true
line-length = 127
lint.preview = true
exclude=[
".git",
"__pycache__",
"dist",
"docs/_build",
"build",
]

[tool.ruff.format]
docstring-code-format = true
#quote-style = "double"

[tool.ruff.lint.isort]
force-single-line = true
from-first = false
lines-between-types = 1
order-by-type = true

[tool.setuptools.package-data]
"cmd2" = ["py.typed"]

[tool.setuptools.packages.find]
where = ["cmd2"]
namespaces = false

[tool.setuptools_scm]

57 changes: 0 additions & 57 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit a330f77

Please sign in to comment.