From 1080ae9cdd1a7b474eed763c6353088072cdd94c Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sun, 3 Nov 2024 11:48:08 -0500 Subject: [PATCH 1/3] Add [project] configuration to pyproject.toml The only thing that is preventing us from deleting setup.py at this point is the fact that there are multiple packages in the source tree due to the ones under the plugins directory. Also: - Ruggedized a couple unit tests --- plugins/ext_test/tasks.py | 4 +- plugins/template/tasks.py | 4 +- pyproject.toml | 80 +++++++++++++++++++++++++++++++++++++++ tasks.py | 4 +- tests/test_completion.py | 4 +- tests/test_utils.py | 8 +--- 6 files changed, 89 insertions(+), 15 deletions(-) diff --git a/plugins/ext_test/tasks.py b/plugins/ext_test/tasks.py index f51b14bf8..54b0e3791 100644 --- a/plugins/ext_test/tasks.py +++ b/plugins/ext_test/tasks.py @@ -157,7 +157,7 @@ def clean_all(context): def sdist(context): """Create a source distribution""" with context.cd(TASK_ROOT_STR): - context.run('python setup.py sdist') + context.run('python -m build --sdist') namespace.add_task(sdist) @@ -167,7 +167,7 @@ def sdist(context): def wheel(context): """Build a wheel distribution""" with context.cd(TASK_ROOT_STR): - context.run('python setup.py bdist_wheel') + context.run('python -m build --wheel') namespace.add_task(wheel) diff --git a/plugins/template/tasks.py b/plugins/template/tasks.py index 6abec40d8..ca1058c88 100644 --- a/plugins/template/tasks.py +++ b/plugins/template/tasks.py @@ -170,7 +170,7 @@ def clean_all(context): @invoke.task(pre=[clean_all]) def sdist(context): """Create a source distribution""" - context.run('python setup.py sdist') + context.run('python -m build --sdist') namespace.add_task(sdist) @@ -179,7 +179,7 @@ def sdist(context): @invoke.task(pre=[clean_all]) def wheel(context): """Build a wheel distribution""" - context.run('python setup.py bdist_wheel') + context.run('python -m build --wheel') namespace.add_task(wheel) diff --git a/pyproject.toml b/pyproject.toml index bfd8d44b7..86e938350 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,84 @@ requires = ["build", "setuptools>=64", "setuptools-scm>=8"] build-backend = "setuptools.build_meta" +[project] +name = "cmd2" +dynamic = ["version"] +description = "cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python" +authors = [{ name = "cmd2 Contributors" }] +readme = "README.md" +requires-python = ">=3.8" +keywords = [ + "CLI", + "cmd", + "command", + "interactive", + "prompt", + "Python", +] +license = { file = "LICENSE" } +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Operating System :: OS Independent", + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: MIT License", + "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 :: 3.13", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dependencies = [ + "gnureadline; os_name=='darwin'", + "pyperclip", + "pyreadline3; os_name=='nt'", + "wcwidth", +] + +[project.optional-dependencies] +build = [ + "build", + "setuptools", + "setuptools-scm", +] +dev = [ + "codecov", + "doc8", + "invoke", + "mypy", + "nox", + "pytest", + "pytest-cov", + "sphinx", + "sphinx-rtd-theme", + "sphinx-autobuild", + "ruff", + "twine", +] +docs = [ + "setuptools", + "setuptools_scm", + "sphinx", + "sphinx-rtd-theme", + "sphinx-autobuild", +] +test = [ + "codecov", + "coverage", + "pytest", + "pytest-cov", +] +validate = [ + "mypy", + "ruff", + "types-setuptools", +] + [tool.doc8] ignore-path = [ "__pycache__", @@ -232,3 +310,5 @@ docstring-code-format = false # This only has an effect when the `docstring-code-format` setting is # enabled. docstring-code-line-length = "dynamic" + +[tool.setuptools_scm] diff --git a/tasks.py b/tasks.py index 2fa88cf51..9a3bc620a 100644 --- a/tasks.py +++ b/tasks.py @@ -309,7 +309,7 @@ def validatetag(context): def sdist(context): """Create a source distribution""" with context.cd(TASK_ROOT_STR): - context.run('python setup.py sdist') + context.run('python -m build --sdist') namespace.add_task(sdist) @@ -319,7 +319,7 @@ def sdist(context): def wheel(context): """Build a wheel distribution""" with context.cd(TASK_ROOT_STR): - context.run('python setup.py bdist_wheel') + context.run('python -m build --wheel') namespace.add_task(wheel) diff --git a/tests/test_completion.py b/tests/test_completion.py index 18b7c0f27..cd2a2af08 100755 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -484,14 +484,14 @@ def test_path_completion_no_text(cmd2_app): def test_path_completion_no_path(cmd2_app): # Run path complete with search text that isn't preceded by a path. This should use CWD as the path. - text = 's' + text = 'p' line = 'shell ls {}'.format(text) endidx = len(line) begidx = endidx - len(text) completions_no_text = cmd2_app.path_complete(text, line, begidx, endidx) # Run path complete with path set to the CWD - text = os.getcwd() + os.path.sep + 's' + text = os.getcwd() + os.path.sep + text line = 'shell ls {}'.format(text) endidx = len(line) begidx = endidx - len(text) diff --git a/tests/test_utils.py b/tests/test_utils.py index 2779a38b8..b726e7f7a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -289,15 +289,9 @@ def pr_none(): def test_proc_reader_send_sigint(pr_none): assert pr_none._proc.poll() is None pr_none.send_sigint() - - wait_start = time.monotonic() pr_none.wait() - wait_finish = time.monotonic() - - # Make sure the process exited before sleep of 5 seconds finished - # 3 seconds accounts for some delay but is long enough for the process to exit - assert wait_finish - wait_start < 3 + # Mac sure a SIGINT killed the process ret_code = pr_none._proc.poll() if sys.platform.startswith('win'): assert ret_code is not None From eb9343455b10ff22b3cb17b6ffcc73619fbcb2b2 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sun, 3 Nov 2024 11:53:34 -0500 Subject: [PATCH 2/3] Make sure pytest-mock is installed for testing --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 86e938350..d7cddbb85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ dev = [ "nox", "pytest", "pytest-cov", + "pytest-mock", "sphinx", "sphinx-rtd-theme", "sphinx-autobuild", @@ -73,6 +74,7 @@ test = [ "coverage", "pytest", "pytest-cov", + "pytest-mock", ] validate = [ "mypy", From 15d2f04b2c2292cd57d0d690bae3a8dd7dee67d2 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sun, 3 Nov 2024 11:58:55 -0500 Subject: [PATCH 3/3] Fix gnureadline install on macOS --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d7cddbb85..2102b412f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,9 +35,9 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ - "gnureadline; os_name=='darwin'", + "gnureadline; platform_system == 'Darwin'", "pyperclip", - "pyreadline3; os_name=='nt'", + "pyreadline3; platform_system == 'Windows'", "wcwidth", ]