From da781ab9a794911d88c9225b1e343c40d784c3c1 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Fri, 28 Jun 2024 10:51:02 +0200 Subject: [PATCH 1/4] Migrate to PEP621 --- Makefile | 4 ---- pyproject.toml | 46 +++++++++++++++++++++++++++++++++++++++++++++- setup.cfg | 42 ------------------------------------------ setup.py | 7 ------- 4 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 setup.py diff --git a/Makefile b/Makefile index b563b2f..ec2df2d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -release: - @python setup.py sdist bdist_wheel upload -.PHONY: release - testrepl: @python bin/testrepl.py repl .PHONY: testrepl diff --git a/pyproject.toml b/pyproject.toml index 5b5d05d..c0829af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,51 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools"] build-backend = "setuptools.build_meta" +[project] +name = "click-repl" +description = "REPL plugin for Click" +readme = "README.md" +authors = [ + { name = "Markus Unterwaditzer", email = "markus@unterwaditzer.net" }, +] +license = { text = "MIT" } +requires-python = ">=3.7" +dynamic = ["version"] +dependencies = [ + "click>=7.0", + "prompt_toolkit>=3.0.36", + "typing-extensions>=4.7.0", +] +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "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", +] + +[project.optional-dependencies] +testing = [ + "pytest>=7.2.1", + "pytest-cov>=4.0.0", + "tox>=4.4.3", +] + +[project.urls] +Homepage = "https://github.com/click-contrib/click-repl" +Repository = "https://github.com/click-contrib/click-repl" + +[tool.setuptools] +packages = ["click_repl"] +zip-safe = false + +[tool.setuptools.dynamic] +version = { attr = "click_repl.__version__" } + [tool.pytest.ini_options] addopts = [ "--cov=click_repl" diff --git a/setup.cfg b/setup.cfg index b8b3a2d..b4cd819 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,45 +1,3 @@ -[metadata] -name = click-repl -version = attr: click_repl.__version__ -description = REPL plugin for Click -description-file = README.md -long_description_content_type = text/markdown -long_description = file: README.md - -url = https://github.com/click-contrib/click-repl - -author = Markus Unterwaditzer -author_email = markus@unterwaditzer.net -license = MIT - -classifiers = - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - -[options] -packages= - click_repl - -install_requires = - click>=7.0 - prompt_toolkit>=3.0.36 - typing-extensions>=4.7.0 - -python_requires = >=3.6 -zip_safe = no - -[options.extras_require] -testing = - pytest>=7.2.1 - pytest-cov>=4.0.0 - tox>=4.4.3 - [flake8] ignore = E203, E266, W503, E402, E731, C901 max-line-length = 90 diff --git a/setup.py b/setup.py deleted file mode 100644 index 06d3ae6..0000000 --- a/setup.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -from setuptools import setup - - -if __name__ == '__main__': - setup() From 6df287a8ac0eb5c300481f289b0e4a439a5f02d3 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Fri, 28 Jun 2024 10:59:26 +0200 Subject: [PATCH 2/4] Add release workflow --- .github/workflows/release.yml | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8da9619 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: 🚀 Release +run-name: 🚀 Release ${{ github.ref_name }} + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: hynek/build-and-inspect-python-package@v2 + upload_pypi: + name: Upload to PyPI repository + needs: [ build ] + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/click-repl/ + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: Packages + path: dist + - uses: pypa/gh-action-pypi-publish@release/v1 + release: + needs: [ upload_pypi ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: softprops/action-gh-release@v2 + with: + name: ${{ github.ref_name }} + generate_release_notes: true From 46bbabac12f750e58b51da94ee1a86725c4dba09 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Fri, 28 Jun 2024 11:11:06 +0200 Subject: [PATCH 3/4] Migrate flake8 to ruff (minimal) --- .github/workflows/tests.yml | 10 +++++++ .pre-commit-config.yaml | 19 +++++++++++++ pyproject.toml | 55 +++++++++++++++++++++++++++++++++++++ setup.cfg | 5 ---- tox.ini | 5 ---- 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 setup.cfg diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3b08cfe..4e1d995 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,8 +5,18 @@ on: - pull_request jobs: + pre-commit: + name: pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 test: runs-on: ${{ matrix.os }} + needs: [ pre-commit ] strategy: matrix: os: [ubuntu-latest, windows-latest] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..96212c6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.3 + hooks: + - id: ruff + args: ["--fix", "--show-fixes"] + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index c0829af..06b64c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,3 +54,58 @@ addopts = [ testpaths = [ "tests", ] + +[tool.ruff] +line-length = 90 + +[tool.ruff.lint] +select = [ + "F", # pyflakes + "W", # pycodestyle-warnings + "E", # pycodestyle-errors +# "I", # isort +# "N", # pep8-naming +# "D", # pydocstyle +# "UP", # pyupgrade +# "YTT", # flake8-2020 +# "ANN", # flake8-annotations +# "S", # flake8-banditF +# "FBT", # flake8-boolean-trap +# "B", # flake8-bugbear +# "A", # flake8-builtins +# "COM", # flake8-comma +# "C4", # flake8-comprehensions +# "EM", # flake8-errmsg +# "FA", # flake8-future-annotations + "ISC", # flake8-implicit-str-concat + "ICN", # flake8-import-conventions +# "G", # flake8-logging-format + "PIE", # flake8-pie +# "T20", # flake8-print +# "PYI", # flake8-pyi +# "PT", # flake8-pytest-style +# "Q", # flake8-quotes +# "RSE", # flake8-raise +# "RET", # flake8-return +# "SLF", # flake8-self +# "SIM", # flake8-simplify +# "TID", # flake8-tidy-imports +# "TCH", # flake8-type-checking +# "ARG", # flake8-unused-arguments +# "PTH", # flake8-use-pathlib +# "TD", # flake8-todos +# "ERA", # eradicate +# "PGH", # pygrep-hooks +# "PL", # pylint +# "TRY", # tryceratops +# "FLY", # flynt +# "PERF", # perflint +# "FURB", # refurb +# "RUF", # Ruff-specific +] +ignore = [ + "E203", "E266", "E402", "E731", "C901", +] + +[tool.ruff.lint.mccabe] +max-complexity = 18 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b4cd819..0000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -ignore = E203, E266, W503, E402, E731, C901 -max-line-length = 90 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 diff --git a/tox.ini b/tox.ini index 92b95cc..d64bff9 100644 --- a/tox.ini +++ b/tox.ini @@ -28,11 +28,6 @@ deps = commands = pytest --basetemp={envtmpdir} -[testenv:flake8] -basepython = python3.7 -deps = flake8 -commands = flake8 click_repl tests - [testenv:click7] basepython = python3.10 deps = From e2444926e2fa177fb488ca3307d65a833e123bc8 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Fri, 28 Jun 2024 11:18:57 +0200 Subject: [PATCH 4/4] Run pre-commit --- Changelog.rst | 2 +- README.md | 2 +- click_repl/_completer.py | 1 - .../test_click_version_ge_8/test_option_completion_v8.py | 8 ++------ .../test_click_version_le_7/test_option_completion_v7.py | 4 +--- .../test_common_tests/test_hidden_cmd_and_args.py | 4 +--- tests/test_dev/test_get_internal_cmds.py | 4 +--- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Changelog.rst b/Changelog.rst index 02cd37e..315ba2d 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -32,4 +32,4 @@ - Backwards compatibility between click 7 & 8 - support for click 8 changes -- Update tests to expect hyphens \ No newline at end of file +- Update tests to expect hyphens diff --git a/README.md b/README.md index d846e77..5d81cdb 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ def myrepl(): 'history': FileHistory('/etc/myrepl/myrepl-history'), } repl(click.get_current_context(), prompt_kwargs=prompt_kwargs) - + cli() ``` And then your custom `myrepl` command will be available on your CLI, which diff --git a/click_repl/_completer.py b/click_repl/_completer.py index 1f64fa0..a7e8e0e 100644 --- a/click_repl/_completer.py +++ b/click_repl/_completer.py @@ -155,7 +155,6 @@ def _get_completion_for_Boolean_type(self, param, incomplete): ] def _get_completion_from_params(self, autocomplete_ctx, args, param, incomplete): - choices = [] param_type = param.type diff --git a/tests/test_completion/test_click_version_ge_8/test_option_completion_v8.py b/tests/test_completion/test_click_version_ge_8/test_option_completion_v8.py index 41169b8..cbef642 100644 --- a/tests/test_completion/test_click_version_ge_8/test_option_completion_v8.py +++ b/tests/test_completion/test_click_version_ge_8/test_option_completion_v8.py @@ -56,12 +56,8 @@ def shell_complete_func(ctx, param, incomplete): def autocompletion_cmd2(handler): pass - completions = list( - c.get_completions(Document("autocompletion-cmd2 --handler ")) - ) + completions = list(c.get_completions(Document("autocompletion-cmd2 --handler "))) assert {x.text for x in completions} == {"foo", "bar"} - completions = list( - c.get_completions(Document("autocompletion-cmd2 --handler ")) - ) + completions = list(c.get_completions(Document("autocompletion-cmd2 --handler "))) assert {x.text for x in completions} == {"foo", "bar"} diff --git a/tests/test_completion/test_click_version_le_7/test_option_completion_v7.py b/tests/test_completion/test_click_version_le_7/test_option_completion_v7.py index 13ff670..e825463 100644 --- a/tests/test_completion/test_click_version_le_7/test_option_completion_v7.py +++ b/tests/test_completion/test_click_version_le_7/test_option_completion_v7.py @@ -25,7 +25,5 @@ def shell_complete_func(ctx, args, incomplete): def autocompletion_opt_cmd2(handler): pass - completions = list( - c.get_completions(Document("autocompletion-opt-cmd2 --handler ")) - ) + completions = list(c.get_completions(Document("autocompletion-opt-cmd2 --handler "))) assert {x.text for x in completions} == {"foo", "bar"} diff --git a/tests/test_completion/test_common_tests/test_hidden_cmd_and_args.py b/tests/test_completion/test_common_tests/test_hidden_cmd_and_args.py index b0ed79c..3bad6bb 100644 --- a/tests/test_completion/test_common_tests/test_hidden_cmd_and_args.py +++ b/tests/test_completion/test_common_tests/test_hidden_cmd_and_args.py @@ -44,9 +44,7 @@ def args_choices_hidden_cmd(handler): completions = list(c.get_completions(Document("args-choices-hidden-cmd foo "))) assert {x.text for x in completions} == set() - completions = list( - c.get_completions(Document("args-choices-hidden-cmd --handler ")) - ) + completions = list(c.get_completions(Document("args-choices-hidden-cmd --handler "))) assert {x.text for x in completions} == set() diff --git a/tests/test_dev/test_get_internal_cmds.py b/tests/test_dev/test_get_internal_cmds.py index 6f07e8e..4d05b41 100644 --- a/tests/test_dev/test_get_internal_cmds.py +++ b/tests/test_dev/test_get_internal_cmds.py @@ -30,6 +30,4 @@ def test_get_registered_target_exit_cmd(test_input, expected): @pytest.mark.parametrize("test_input", ["hi", "hello", "76q358767"]) def test_get_registered_target(test_input): - assert ( - click_repl.utils._get_registered_target(test_input, "Not Found") == "Not Found" - ) + assert click_repl.utils._get_registered_target(test_input, "Not Found") == "Not Found"