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 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/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/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/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/pyproject.toml b/pyproject.toml index 5b5d05d..06b64c5 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" @@ -10,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 b8b3a2d..0000000 --- a/setup.cfg +++ /dev/null @@ -1,47 +0,0 @@ -[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 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 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() 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" 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 =