From e3df1ee2c2c9cb84cabdc1fefae9bb0c2f3a248d Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 03:30:57 -0600 Subject: [PATCH 1/8] build(deps): Remove black from dev dependencies --- poetry.lock | 84 +------------------------------------------------- pyproject.toml | 2 -- 2 files changed, 1 insertion(+), 85 deletions(-) diff --git a/poetry.lock b/poetry.lock index ae54dbeedf..96af523e48 100644 --- a/poetry.lock +++ b/poetry.lock @@ -58,48 +58,6 @@ soupsieve = ">1.2" html5lib = ["html5lib"] lxml = ["lxml"] -[[package]] -name = "black" -version = "23.11.0" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.8" -files = [ - {file = "black-23.11.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dbea0bb8575c6b6303cc65017b46351dc5953eea5c0a59d7b7e3a2d2f433a911"}, - {file = "black-23.11.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:412f56bab20ac85927f3a959230331de5614aecda1ede14b373083f62ec24e6f"}, - {file = "black-23.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d136ef5b418c81660ad847efe0e55c58c8208b77a57a28a503a5f345ccf01394"}, - {file = "black-23.11.0-cp310-cp310-win_amd64.whl", hash = "sha256:6c1cac07e64433f646a9a838cdc00c9768b3c362805afc3fce341af0e6a9ae9f"}, - {file = "black-23.11.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cf57719e581cfd48c4efe28543fea3d139c6b6f1238b3f0102a9c73992cbb479"}, - {file = "black-23.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:698c1e0d5c43354ec5d6f4d914d0d553a9ada56c85415700b81dc90125aac244"}, - {file = "black-23.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:760415ccc20f9e8747084169110ef75d545f3b0932ee21368f63ac0fee86b221"}, - {file = "black-23.11.0-cp311-cp311-win_amd64.whl", hash = "sha256:58e5f4d08a205b11800332920e285bd25e1a75c54953e05502052738fe16b3b5"}, - {file = "black-23.11.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:45aa1d4675964946e53ab81aeec7a37613c1cb71647b5394779e6efb79d6d187"}, - {file = "black-23.11.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4c44b7211a3a0570cc097e81135faa5f261264f4dfaa22bd5ee2875a4e773bd6"}, - {file = "black-23.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2a9acad1451632021ee0d146c8765782a0c3846e0e0ea46659d7c4f89d9b212b"}, - {file = "black-23.11.0-cp38-cp38-win_amd64.whl", hash = "sha256:fc7f6a44d52747e65a02558e1d807c82df1d66ffa80a601862040a43ec2e3142"}, - {file = "black-23.11.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7f622b6822f02bfaf2a5cd31fdb7cd86fcf33dab6ced5185c35f5db98260b055"}, - {file = "black-23.11.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:250d7e60f323fcfc8ea6c800d5eba12f7967400eb6c2d21ae85ad31c204fb1f4"}, - {file = "black-23.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5133f5507007ba08d8b7b263c7aa0f931af5ba88a29beacc4b2dc23fcefe9c06"}, - {file = "black-23.11.0-cp39-cp39-win_amd64.whl", hash = "sha256:421f3e44aa67138ab1b9bfbc22ee3780b22fa5b291e4db8ab7eee95200726b07"}, - {file = "black-23.11.0-py3-none-any.whl", hash = "sha256:54caaa703227c6e0c87b76326d0862184729a69b73d3b7305b6288e1d830067e"}, - {file = "black-23.11.0.tar.gz", hash = "sha256:4c68855825ff432d197229846f971bc4d6666ce90492e5b02013bcaca4d9ab05"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -packaging = ">=22.0" -pathspec = ">=0.9.0" -platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - [[package]] name = "certifi" version = "2023.11.17" @@ -210,20 +168,6 @@ files = [ {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, ] -[[package]] -name = "click" -version = "8.1.7" -description = "Composable command line interface toolkit" -optional = false -python-versions = ">=3.7" -files = [ - {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, - {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} - [[package]] name = "codecov" version = "2.1.13" @@ -687,17 +631,6 @@ files = [ {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, ] -[[package]] -name = "pathspec" -version = "0.11.2" -description = "Utility library for gitignore style pattern matching of file paths." -optional = false -python-versions = ">=3.7" -files = [ - {file = "pathspec-0.11.2-py3-none-any.whl", hash = "sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20"}, - {file = "pathspec-0.11.2.tar.gz", hash = "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3"}, -] - [[package]] name = "pillow" version = "10.1.0" @@ -765,21 +698,6 @@ files = [ docs = ["furo", "olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-inline-tabs", "sphinx-removed-in", "sphinxext-opengraph"] tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"] -[[package]] -name = "platformdirs" -version = "4.0.0" -description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -optional = false -python-versions = ">=3.7" -files = [ - {file = "platformdirs-4.0.0-py3-none-any.whl", hash = "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b"}, - {file = "platformdirs-4.0.0.tar.gz", hash = "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731"}, -] - -[package.extras] -docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] -test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] - [[package]] name = "pluggy" version = "1.3.0" @@ -1476,4 +1394,4 @@ test = [] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "2ae1516875549856f4d82b1ea21fd593ae235f84804f732a18cde7f4f47ea131" +content-hash = "6b8412498d54ea3aa7f9975d7b1686316705a0d38e4a1c570c4513bdcee867d2" diff --git a/pyproject.toml b/pyproject.toml index 57c27d5755..184ae9bdf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,6 @@ codecov = "*" coverage = "*" ### Lint ### -black = "*" ruff = "*" mypy = "*" types-colorama = "*" @@ -106,7 +105,6 @@ docs = [ test = ["pytest", "pytest-rerunfailures", "pytest-mock", "pytest-watcher"] coverage = ["codecov", "coverage", "pytest-cov"] lint = [ - "black", "ruff", "mypy", "types-colorama", From 7ae2242893417e3801dc6aee00b30ff6f0b6f041 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 03:43:04 -0600 Subject: [PATCH 2/8] ci(tests): Add ruff format checking --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c4e88172e9..5caa4ddc63 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,12 +56,12 @@ jobs: run: | poetry install -E "test coverage lint" - - name: Lint with black . --check - run: poetry run black . --check - - name: Lint with ruff . run: poetry run ruff . + - name: Format with ruff + run: poetry run ruff format . --check + - name: Lint with mypy run: poetry run mypy . From eb5221a66df2eb3d510e3d7c0b810d0e3a265acc Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 04:04:34 -0600 Subject: [PATCH 3/8] chore(Makefile): black -> ruff format --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 254e69569a..e16735a759 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,8 @@ start_docs: design_docs: $(MAKE) -C docs design -black: - poetry run black `${PY_FILES}` +ruff_format: + poetry run ruff format . ruff: poetry run ruff . From 3a405d5bb5746d52c372355367674cc383f74c32 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 04:09:40 -0600 Subject: [PATCH 4/8] chore: Run `ruff format .` --- src/tmuxp/shell.py | 2 +- tests/workspace/test_builder.py | 12 ++++++------ tests/workspace/test_config.py | 4 +--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/tmuxp/shell.py b/src/tmuxp/shell.py index bb06fb4b64..d5f6aaca95 100644 --- a/src/tmuxp/shell.py +++ b/src/tmuxp/shell.py @@ -272,7 +272,7 @@ def launch( shell: t.Optional["CLIShellLiteral"] = "best", use_pythonrc: bool = False, use_vi_mode: bool = False, - **kwargs: "Unpack[LaunchOptionalImports]" + **kwargs: "Unpack[LaunchOptionalImports]", ) -> None: # Also allowing passing shell='code' to force using code.interact imported_objects = get_launch_args(**kwargs) diff --git a/tests/workspace/test_builder.py b/tests/workspace/test_builder.py index db31e419ee..87d519cf21 100644 --- a/tests/workspace/test_builder.py +++ b/tests/workspace/test_builder.py @@ -321,14 +321,14 @@ def f() -> bool: return retry_until(f, raises=False) for i, pane in enumerate(session.attached_window.panes): - assert assert_last_line( - pane, str(i) - ), "Initial command did not execute properly/" + str(i) + assert assert_last_line(pane, str(i)), ( + "Initial command did not execute properly/" + str(i) + ) pane.cmd("send-keys", "Up") # Will repeat echo pane.enter() # in each iteration - assert assert_last_line( - pane, str(i) - ), "Repeated command did not execute properly/" + str(i) + assert assert_last_line(pane, str(i)), ( + "Repeated command did not execute properly/" + str(i) + ) session.cmd("send-keys", " echo moo") session.cmd("send-keys", "Enter") diff --git a/tests/workspace/test_config.py b/tests/workspace/test_config.py index e087fbeabf..5bef626f96 100644 --- a/tests/workspace/test_config.py +++ b/tests/workspace/test_config.py @@ -317,9 +317,7 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None: panes: - shell_command: - htop - """.format( - TEST_VAR="${%s}" % env_key - ) + """.format(TEST_VAR="${%s}" % env_key) sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) From d31eeddfdb7887f0d9271f9d04623a9fa24799a1 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 04:25:19 -0600 Subject: [PATCH 5/8] docs(CHANGES): Note move to `ruff format` --- CHANGES | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES b/CHANGES index e01648867c..78efba9017 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,15 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force See also: https://github.com/python-poetry/poetry/blob/1.7.0/CHANGELOG.md +### Development + +- Move formatting from `black` to [`ruff format`] (#890) + + This retains the same formatting style of `black` while eliminating a + dev dependency by using our existing rust-based `ruff` linter. + + [`ruff format`]: https://docs.astral.sh/ruff/formatter/ + ## tmuxp 1.31.0 (2023-09-23) ### Breaking changes From 8647448f2f7a025ef04b5863f6db6c7c11d6ed1b Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 05:04:17 -0600 Subject: [PATCH 6/8] docs(developing): Use `ruff format` --- docs/developing.md | 56 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/docs/developing.md b/docs/developing.md index 78fdae7b95..61178654b8 100644 --- a/docs/developing.md +++ b/docs/developing.md @@ -329,22 +329,22 @@ this will load the `.tmuxp.yaml` in the root of the project. ## Formatting -### black +### ruff -[black] is used for formatting. +The project uses [ruff] to handles formatting, sorting imports and linting. ````{tab} Command poetry: ```console -$ poetry run black . +$ poetry run ruff ``` If you setup manually: ```console -$ black . +$ ruff . ``` ```` @@ -352,63 +352,61 @@ $ black . ````{tab} make ```console -$ make black +$ make ruff ``` ```` -In the future, `ruff` (below) may replace black as formatter. +````{tab} Watch -### ruff +```console +$ make watch_ruff +``` -The project uses [ruff] to handles formatting, sorting imports and linting. +requires [`entr(1)`]. -````{tab} Command +```` + +````{tab} Fix files poetry: ```console -$ poetry run ruff +$ poetry run ruff . --fix ``` If you setup manually: ```console -$ ruff . +$ ruff . --fix ``` ```` -````{tab} make +#### ruff format -```console -$ make ruff -``` +[ruff format] is used for formatting. -```` +````{tab} Command -````{tab} Watch +poetry: ```console -$ make watch_ruff +$ poetry run ruff format . ``` -requires [`entr(1)`]. - -```` - -````{tab} Fix files - -poetry: +If you setup manually: ```console -$ poetry run ruff . --fix +$ ruff format . ``` -If you setup manually: +```` + +````{tab} make ```console -$ ruff . --fix +$ make ruff_format ``` ```` @@ -467,7 +465,7 @@ the [gh build site]. [entr]: http://entrproject.org/ [`entr(1)`]: http://entrproject.org/ [ruff]: https://ruff.rs -[black]: https://github.com/psf/black +[ruff format]: https://docs.astral.sh/ruff/formatter/ [mypy]: http://mypy-lang.org/ [github actions]: https://github.com/features/actions [gh build site]: https://github.com/tmux-python/tmuxp/actions?query=workflow%3Atests From 3c77c7e511c379a417e30f5eac33aea7383b7e97 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 05:57:18 -0600 Subject: [PATCH 7/8] docs(CHANGES): Note move to `ruff format` --- .vim/coc-settings.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .vim/coc-settings.json diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json new file mode 100644 index 0000000000..d542a72629 --- /dev/null +++ b/.vim/coc-settings.json @@ -0,0 +1,19 @@ +{ + "[markdown][python]": { + "coc.preferences.formatOnSave": true + }, + "python.analysis.autoSearchPaths": true, + "python.analysis.typeCheckingMode": "basic", + "python.analysis.useLibraryCodeForTypes": true, + "python.formatting.provider": "ruff", + "python.linting.ruffEnabled": true, + "python.linting.mypyEnabled": true, + "python.linting.flake8Enabled": false, + "python.linting.pyflakesEnabled": false, + "python.linting.pycodestyleEnabled": false, + "python.linting.banditEnabled": false, + "python.linting.pylamaEnabled": false, + "python.linting.pylintEnabled": false, + "pyright.organizeimports.provider": "ruff", + "pyright.testing.provider": "pytest", +} From 84a8c32e93f50e5f4b0a581d135435756715f2c9 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 18 Nov 2023 05:57:22 -0600 Subject: [PATCH 8/8] .vim/coc-settings.json: Add file for ruff --- .vim/.vim/coc-settings.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .vim/.vim/coc-settings.json diff --git a/.vim/.vim/coc-settings.json b/.vim/.vim/coc-settings.json new file mode 100644 index 0000000000..d542a72629 --- /dev/null +++ b/.vim/.vim/coc-settings.json @@ -0,0 +1,19 @@ +{ + "[markdown][python]": { + "coc.preferences.formatOnSave": true + }, + "python.analysis.autoSearchPaths": true, + "python.analysis.typeCheckingMode": "basic", + "python.analysis.useLibraryCodeForTypes": true, + "python.formatting.provider": "ruff", + "python.linting.ruffEnabled": true, + "python.linting.mypyEnabled": true, + "python.linting.flake8Enabled": false, + "python.linting.pyflakesEnabled": false, + "python.linting.pycodestyleEnabled": false, + "python.linting.banditEnabled": false, + "python.linting.pylamaEnabled": false, + "python.linting.pylintEnabled": false, + "pyright.organizeimports.provider": "ruff", + "pyright.testing.provider": "pytest", +}