diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index aef7ebaa..8267c3b3 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -33,24 +33,22 @@ jobs: uses: actions/cache@v4 with: path: ${{ env.PRE_COMMIT_HOME }} - key: "precommit-${{ runner.os }}-${{ steps.poetry_setup.outputs.python-version }}-\ - ${{ hashFiles('./.pre-commit-config.yaml') }}" + key: + "precommit-${{ runner.os }}-${{ steps.poetry_setup.outputs.python-version }}-\ + ${{ hashFiles('./.pre-commit-config.yaml') }}" # Restore keys allows us to perform a cache restore even if the full cache key wasn't matched. # That way we still end up saving new cache, but we can still make use of the cache from previous # version. restore-keys: "precommit-${{ runner.os }}-${{ steps.poetry_setup.outputs-python-version}}-" - name: Run pre-commit hooks - run: SKIP=black,isort,ruff,slotscheck,pyright pre-commit run --all-files - - - name: Run black formatter check - run: black --check --diff . - - - name: Run isort import formatter check - run: isort --check --diff . + run: SKIP=ruff-linter,ruff-formatter,slotscheck,pyright pre-commit run --all-files - name: Run ruff linter - run: ruff --no-fix --show-source . + run: ruff check --output-format=full --show-fixes --exit-non-zero-on-fix . + + - name: Run ruff formatter + run: ruff format --diff . - name: Run slotscheck run: slotscheck -m mcproto diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e5fd70c..6b35009a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,32 +13,24 @@ repos: - repo: local hooks: - - id: black - name: Black - description: Auto-format the code with black - entry: poetry run black - language: system - types: [python] - - - repo: local - hooks: - - id: isort - name: ISort - description: Sort imports with isort - entry: poetry run isort + - id: ruff-linter + name: Ruff Linter + description: Run ruff checks on the code + entry: poetry run ruff check --force-exclude language: system types: [python] + require_serial: true + args: [--fix, --exit-non-zero-on-fix] - repo: local hooks: - - id: ruff - name: Ruff - description: Run Ruff checks on the code - entry: poetry run ruff check --force-exclude + - id: ruff-formatter + name: Ruff Formatter + description: Ruf ruff auto-formatter + entry: poetry run ruff format language: system types: [python] require_serial: true - args: [--fix, --exit-non-zero-on-fix] - repo: local hooks: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25b5334d..a96bd540 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -100,25 +100,30 @@ automated tools to help us catch any style violation without manual review! Currently, these are the tools we use for code style enforcement: -- [`ruff`](https://beta.ruff.rs/docs/): General python linter -- [`isort`](https://pycqa.github.io/isort/): Formatter/Sorter of import statements -- [`black`](https://black.readthedocs.io/en/stable/): General python formatter +- [`ruff`](https://beta.ruff.rs/docs/): General python linter, formatter and import sorter +- [`slotscheck`](https://slotscheck.readthedocs.io/en/latest/): Enforces the presence of `__slots__` in classes -You can read more about them individually in the sections below. It is important that you familiarize yourself with all -of these tools, and their standalone usage, but it would of course be very annoying to have to run all of these tools -manually, so while there will be instructions on how to do that, you should pretty much always prefer direct IDE/editor -integration, which is mentioned [here](#editor-integration), and make use of [pre-commit](#pre-commit). +You can read more about them individually in the sections below. It is important that you familiarize yourself with +these tools, and their standalone usage, but it would of course be very annoying to have to run the commands to run +these tools manually, so while there will be instructions on how to do that, you should pretty much always prefer +direct IDE/editor integration, which is mentioned [here](#editor-integration), and make use of +[pre-commit](#pre-commit). -#### Ruff linter +#### Ruff linter & Formatter -Ruff is an alternative program to the more popular [`flake8`](https://flake8.pycqa.org/en/latest/) linter. Ruff is -faster (written in rust! 🦀) and includes most of the popular flake8 extensions directly. +Ruff is an all-in-one linter & formatter solution, which aims to replace the previously very popular +[`flake8`](https://flake8.pycqa.org/en/latest/) linter, [`isort`](https://pycqa.github.io/isort/) import sorter and +[`black`](https://black.readthedocs.io/en/stable/) formatter. Ruff is faster (written in rust! 🦀) and includes most of +the popular flake8 extensions directly. It is almost 1:1 compatible with black, which means the way it formats code is +pretty much the same, with only some very subtle differences. -You can check which ruff rules we're using in [`pyproject.toml`](./pyproject.toml) file, under the `[tools.ruff]`. +You can check the ruff configuration we're using in [`pyproject.toml`](./pyproject.toml) file, under the `[tool.ruff]` +category (and it's subcategories), you can find the enabled linter rules there, and some more specific configuration, +like line length, python version, individual ignored lint rules, and ignored files. -To run `ruff` on the code, you can use `ruff check .` command, while in the project's root directory (from an activated -poetry environment, alternatively `poetry run ruff .`). Ruff also supports some automatic fixes to many violations it -founds, to enable fixing, you can use `ruff check --fix`. +To run `ruff` **linter** on the code, you can use `ruff check .` command, while in the project's root directory (from +an activated poetry environment, alternatively `poetry run ruff .`). Ruff also supports some automatic fixes to many +violations it founds, to enable fixing, you can use `ruff check --fix`. This will also run the `isort` integration. If you find a rule violation in your code somewhere, and you don't understand what that rule's purpose is, `ruff` evens supports running `ruff rule [rule id]` (for example `ruff rule ANN401`). These explanations are in markdown, so I'd @@ -126,27 +131,20 @@ recommend using a markdown renderer such as [`glow`](https://github.com/charmbra install it with: `pacman -S glow`) and piping the output into it for a much nicer reading experience: `ruff rule ANN401 | glow`. -#### Isort +To run `ruff` **formatter** on the code, you can simply execute `ruff format .` command (also needs an activated poetry +environment). This will automatically format all files in the code-base. -Isort is a tool for sorting python imports. We use it for consistency in the code-base, and because it makes it very -easy to quickly know where to look, when a file has a lot of imports in it, since you'll know they're all sorted in a -very particular order. +#### Slotscheck -Specifically, isort splits our imports up into 3 groups: stdlib, external, internal. Inside of these groups, all -imports are also alphabetically sorted. +Slotscheck is a utility/linter that enforces the proper use of `__slots__` in our python classes. This is important for +memory-optimization reasons, and it also improves the general performance when accessing/working with attributes of +slotted classes. -You can run isort to automatically sort the imports for you with: `isort .` (or `poetry run isort .`) from the -project's root. +If you're unsure how slots work / what they are, there is a very nice explanation of them in the official python wiki: +[here](https://wiki.python.org/moin/UsingSlots). -#### Black - -Black is a popular auto-formatter for python, with a bunch of different rules to automatically format our code in a -way we want it to look. Black is a great way to allow us to focus on writing the logic of the code, without worrying -too much about the code style, as it simply formats the code for us. It is fully compatible with `ruff`, linter, so no -conflicts between these tools will arise. In fact, black can often fix a lot of violations ruff will report on it's -own. - -To run black, simply execute `black .` (or `poetry run black .`) from the project's root. +To run slotscheck, you can simply execute `slotscheck -m mcproto` from an activated poetry environment (or +`poetry run slotscheck -m mcproto`). ### Use of `__all__` @@ -301,15 +299,15 @@ pyright automatically, as a part of [pre-commit](#pre-commit). ## Pre-commit -Now that you've seen all of the linters and type-checkers we use in the project, you might be wondering whether you're -really expected to run all of those commands manually, after each change. And of course, no, you're not, that would be -really annoying, and you'd probably also often just forget to do that. +Now that you've seen the linters, formatters, type-checkers and other tools that we use in the project, you might be +wondering whether you're really expected to run all of those commands manually, after each change. And of course, no, +you're not, that would be really annoying, and you'd probably also often just forget to do that. So, instead of that, we use a tool called `pre-commit`, which creates a [git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), that will automatically run before each commit you -make. That means each time when you make a commit, all of the linters, formatters and other checkers will run over the -code you updated, and if any of these linters detects an issue, the commit will be aborted, and you will see which -linter failed, and it's output telling you why. +make. That means each time when you make a commit, all of these tools will run over the code you updated, and if any of +these linters detects an issue, the commit will be aborted, and you will see which linter failed, and it's output +telling you why. To install pre-commit as a git hook all you need to do is to run `pre-commit install` from an activated poetry environment, installing it into the git repository as a hook running before every commit. That said, you can also run @@ -317,17 +315,17 @@ pre-commit without having to install it (or without having to make a commit, eve execute: `pre-commit run --all-files`. Note that the installed hook will only run the linters on the files that were updated in the commit, while using the command directly will run it on the whole project. -You can find pre-commit's configuration the [`.pre-commit-config.yaml`](./.pre-commit-config.yaml) file, where we define -which tools should be ran and how. Currently, pre-commit runs ruff, black, isort and pyright, but also a checker for -some issues in TOML/YAML files. +You can find pre-commit's configuration the [`.pre-commit-config.yaml`](./.pre-commit-config.yaml) file, where we +define which tools should be ran and how. Currently, pre-commit runs ruff linter, ruff formatter, slotscheck and +pyright, but also a checker for some issues in TOML/YAML files. -Even though in most cases enforcing linting before each commit is what we want, there are some situations where -we need to commit some code which doesn't pass these checks. This can happen for example after a merge, or as a result -of making a single purpose small commit without yet worrying about linters. In these cases, you can use the -`--no-verify` flag when making a commit, telling git to skip all of the pre-commit hooks and commit normally. You can -also only skip a specific hook(s), by setting `SKIP` environmental variable (e.g. `SKIP=ruff`, or -`SKIP=ruff,isort`), the names of the individual hooks are their ids, you can find those in the configuration -file for pre-commit. +Even though in most cases enforcing linting before each commit is what we want, there are some situations where we need +to commit some code which doesn't pass these checks. This can happen for example after a merge, or as a result of +making a single purpose small commit without yet worrying about linters. In these cases, you can use the `--no-verify` +flag when making a commit, telling git to skip all of the pre-commit hooks and commit normally. You can also only skip +a specific hook(s), by setting `SKIP` environmental variable (e.g. `SKIP=pyright`, or +`SKIP=ruff-linter,ruff-formatter,slotscheck`), the names of the individual hooks are their ids, you can find those in +the configuration file for pre-commit. However this kind of verification skipping should be used sparingly. We value a clean history which consistently follows our linting guidelines, and making commits with linting issues only leads to more commits, fixing those issues later. If @@ -344,20 +342,22 @@ editors will support integration will all of these tools, so you shouldn't have If you're using neovim, I would recommend setting up LSP (Language Server Protocol), and installing Pyright, as it has language server support built into it. Same thing goes with `ruff`, which has an LSP implementation -[`ruff-lsp`](https://github.com/astral-sh/ruff-lsp). As for `isort` and `black`, you'll want to use something like -`null-ls` for those. +[`ruff-lsp`](https://github.com/astral-sh/ruff-lsp). As for slotscheck, there isn't currently any good way to integrate +it directly, so you will need to rely on pre-commit, or run it manually. However, slotscheck violations are fairly +rare. -On vscode, you can simply install extensions for all of the tools we're using: +On vscode, you can simply install the following extensions: - [pylance (pyright)](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) - [ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) -- [isort](https://marketplace.visualstudio.com/items?itemName=ms-python.isort) -- [black](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) Note that with Pylance, you will also need to enable the type checking mode, by setting `"python.analysis.typeCheckingMode": "basic"` in `settings.json`. You can use `.vscode/settings.json` for per-project settings, to only enable type-checking for this project, or enable it globally in your user settings). +(Similarly to neovim, there is no extension available for slotscheck, however violations are fairly rare, and it should +be enough to have it run with pre-commit.) + ## Making Great Commits A well-structured git log is key to a project's maintainability; it provides insight into when and why things were done diff --git a/mcproto/encryption.py b/mcproto/encryption.py index d0a638cb..509a22a4 100644 --- a/mcproto/encryption.py +++ b/mcproto/encryption.py @@ -40,7 +40,11 @@ def generate_rsa_key() -> RSAPrivateKey: # pragma: no cover This will be a 1024-bit RSA key pair. """ - return generate_private_key(public_exponent=65537, key_size=1024, backend=default_backend()) + return generate_private_key( + public_exponent=65537, + key_size=1024, # noqa: S505 # 1024-bit keys are not secure, but well, the mc protocol uses them + backend=default_backend(), + ) def encrypt_token_and_secret( diff --git a/poetry.lock b/poetry.lock index e80130f0..3a05cd06 100644 --- a/poetry.lock +++ b/poetry.lock @@ -78,52 +78,6 @@ soupsieve = ">1.2" html5lib = ["html5lib"] lxml = ["lxml"] -[[package]] -name = "black" -version = "24.4.2" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.8" -files = [ - {file = "black-24.4.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce"}, - {file = "black-24.4.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021"}, - {file = "black-24.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063"}, - {file = "black-24.4.2-cp310-cp310-win_amd64.whl", hash = "sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96"}, - {file = "black-24.4.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474"}, - {file = "black-24.4.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c"}, - {file = "black-24.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb"}, - {file = "black-24.4.2-cp311-cp311-win_amd64.whl", hash = "sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1"}, - {file = "black-24.4.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d"}, - {file = "black-24.4.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04"}, - {file = "black-24.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc"}, - {file = "black-24.4.2-cp312-cp312-win_amd64.whl", hash = "sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0"}, - {file = "black-24.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7"}, - {file = "black-24.4.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94"}, - {file = "black-24.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8"}, - {file = "black-24.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c"}, - {file = "black-24.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1"}, - {file = "black-24.4.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741"}, - {file = "black-24.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e"}, - {file = "black-24.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7"}, - {file = "black-24.4.2-py3-none-any.whl", hash = "sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c"}, - {file = "black-24.4.2.tar.gz", hash = "sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d"}, -] - -[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)", "aiohttp (>=3.7.4,!=3.9.0)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - [[package]] name = "certifi" version = "2023.7.22" @@ -713,23 +667,6 @@ files = [ {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] -[[package]] -name = "isort" -version = "5.12.0" -description = "A Python utility / library to sort Python imports." -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, - {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, -] - -[package.extras] -colors = ["colorama (>=0.4.3)"] -pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] -plugins = ["setuptools"] -requirements-deprecated-finder = ["pip-api", "pipreqs"] - [[package]] name = "jinja2" version = "3.1.3" @@ -833,17 +770,6 @@ files = [ {file = "mslex-0.3.0.tar.gz", hash = "sha256:4a1ac3f25025cad78ad2fe499dd16d42759f7a3801645399cce5c404415daa97"}, ] -[[package]] -name = "mypy-extensions" -version = "0.4.3" -description = "Experimental type system extensions for programs checked with the mypy typechecker." -optional = false -python-versions = "*" -files = [ - {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, - {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, -] - [[package]] name = "nodeenv" version = "1.7.0" @@ -869,17 +795,6 @@ files = [ {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, ] -[[package]] -name = "pathspec" -version = "0.10.3" -description = "Utility library for gitignore style pattern matching of file paths." -optional = false -python-versions = ">=3.7" -files = [ - {file = "pathspec-0.10.3-py3-none-any.whl", hash = "sha256:3c95343af8b756205e2aba76e843ba9520a24dd84f68c22b9f93251507509dd6"}, - {file = "pathspec-0.10.3.tar.gz", hash = "sha256:56200de4077d9d0791465aa9095a01d421861e405b5096955051deefd697d6f6"}, -] - [[package]] name = "platformdirs" version = "2.6.0" @@ -1175,28 +1090,28 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.1.5" +version = "0.3.7" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.1.5-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:32d47fc69261c21a4c48916f16ca272bf2f273eb635d91c65d5cd548bf1f3d96"}, - {file = "ruff-0.1.5-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:171276c1df6c07fa0597fb946139ced1c2978f4f0b8254f201281729981f3c17"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:17ef33cd0bb7316ca65649fc748acc1406dfa4da96a3d0cde6d52f2e866c7b39"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b2c205827b3f8c13b4a432e9585750b93fd907986fe1aec62b2a02cf4401eee6"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bb408e3a2ad8f6881d0f2e7ad70cddb3ed9f200eb3517a91a245bbe27101d379"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:f20dc5e5905ddb407060ca27267c7174f532375c08076d1a953cf7bb016f5a24"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:aafb9d2b671ed934998e881e2c0f5845a4295e84e719359c71c39a5363cccc91"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a4894dddb476597a0ba4473d72a23151b8b3b0b5f958f2cf4d3f1c572cdb7af7"}, - {file = "ruff-0.1.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a00a7ec893f665ed60008c70fe9eeb58d210e6b4d83ec6654a9904871f982a2a"}, - {file = "ruff-0.1.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:a8c11206b47f283cbda399a654fd0178d7a389e631f19f51da15cbe631480c5b"}, - {file = "ruff-0.1.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:fa29e67b3284b9a79b1a85ee66e293a94ac6b7bb068b307a8a373c3d343aa8ec"}, - {file = "ruff-0.1.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9b97fd6da44d6cceb188147b68db69a5741fbc736465b5cea3928fdac0bc1aeb"}, - {file = "ruff-0.1.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:721f4b9d3b4161df8dc9f09aa8562e39d14e55a4dbaa451a8e55bdc9590e20f4"}, - {file = "ruff-0.1.5-py3-none-win32.whl", hash = "sha256:f80c73bba6bc69e4fdc73b3991db0b546ce641bdcd5b07210b8ad6f64c79f1ab"}, - {file = "ruff-0.1.5-py3-none-win_amd64.whl", hash = "sha256:c21fe20ee7d76206d290a76271c1af7a5096bc4c73ab9383ed2ad35f852a0087"}, - {file = "ruff-0.1.5-py3-none-win_arm64.whl", hash = "sha256:82bfcb9927e88c1ed50f49ac6c9728dab3ea451212693fe40d08d314663e412f"}, - {file = "ruff-0.1.5.tar.gz", hash = "sha256:5cbec0ef2ae1748fb194f420fb03fb2c25c3258c86129af7172ff8f198f125ab"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, + {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, + {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, + {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, + {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, ] [[package]] @@ -1597,4 +1512,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4" -content-hash = "7e2cc63b5fbfe0dd84cbcc39233f5f8d9254f1610128ef157f1b75e24f7379dc" +content-hash = "740a96166851838ff7cfc596d7956c24d175a37e88cfe6130b03383d0fa7c757" diff --git a/pyproject.toml b/pyproject.toml index 79c3cf3d..5cf7b542 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,9 +47,7 @@ pytest-cov = ">=3,<6" pytest-httpx = { version = ">=0.23.1,<0.25.0", python = ">=3.9,<4" } [tool.poetry.group.lint.dependencies] -ruff = ">=0.0.278,<0.1.6" -black = ">=22.3,<25.0" -isort = "^5.10.1" +ruff = "^0.3.4" pyright = "^1.1.313" slotscheck = ">=0.16.1,<0.18.0" @@ -102,6 +100,7 @@ reportShadowedImports = "error" target-version = "py38" line-length = 119 +[tool.ruff.lint] select = [ "F", # Pyflakes "W", # Pycodestyle (warnigns) @@ -124,8 +123,10 @@ select = [ "SIM", # flake8-simplify "TID", # flake8-tidy-imports "INT", # flake8-gettext + "ISC", # flake8-implicit-str-concat "PTH", # flake8-use-pathlib "PGH", # pygrep-hooks + "PIE", # flake8-pie "PL", # pylint "RUF", # ruff-specific rules "UP", # pyupgrade @@ -157,14 +158,34 @@ ignore = [ "ANN101", # Missing type annotation for self in method "ANN102", # Missing type annotation for cls in classmethod "ANN204", # Missing return type annotation for special method + "ANN401", # Dynamically typed expressions (typing.Any) disallowed + + "SIM102", # use a single if statement instead of nested if statements + "SIM108", # Use ternary operator {contents} instead of if-else-block "PT011", # pytest.raises without match parameter is too broad # TODO: Unignore this "UP024", # Using errors that alias OSError "PLR2004", # Using unnamed numerical constants "PGH003", # Using specific rule codes in type ignores + "E731", # Don't asign a lambda expression, use a def + + # Redundant rules with ruff-format: + "E111", # Indentation of a non-multiple of 4 spaces + "E114", # Comment with indentation of a non-multiple of 4 spaces + "E117", # Cheks for over-indented code + "D206", # Checks for docstrings indented with tabs + "D300", # Checks for docstring that use ''' instead of """ + "Q000", # Checks of inline strings that use wrong quotes (' instead of ") + "Q001", # Multiline string that use wrong quotes (''' instead of """) + "Q002", # Checks for docstrings that use wrong quotes (''' instead of """) + "Q003", # Checks for avoidable escaped quotes ("\"" -> '"') + "COM812", # Missing trailing comma (in multi-line lists/tuples/...) + "COM819", # Prohibited trailing comma (in single-line lists/tuples/...) + "ISC001", # Single line implicit string concatenation ("hi" "hey" -> "hihey") + "ISC002", # Multi line implicit string concatenation ] -[tool.ruff.extend-per-file-ignores] +[tool.ruff.lint.extend-per-file-ignores] "tests/*" = [ "ANN", # flake8-annotations "S101", # Use of assert @@ -173,25 +194,29 @@ ignore = [ "D", # pydocstyle ] -[tool.ruff.flake8-tidy-imports] -ban-relative-imports = "all" +[tool.ruff.lint.isort] +order-by-type = false +case-sensitive = true +combine-as-imports = true -[tool.ruff.pylint] -max-args = 6 -max-branches = 12 -max-returns = 10 -max-statements = 50 +# Redundant rules with ruff-format +force-single-line = false # forces all imports to appear on their own line +force-wrap-aliases = false # Split imports with multiple members and at least one alias +lines-after-imports = -1 # The number of blank lines to place after imports +lines-between-types = 0 # Number of lines to place between "direct" and import from imports +split-on-trailing-comma = false # if last member of multiline import has a comma, don't fold it to single line -[tool.black] -line-length = 119 +[tool.ruff.lint.pylint] +max-args = 20 +max-branches = 20 +max-returns = 20 +max-statements = 250 + +[tool.ruff.lint.flake8-tidy-imports] +ban-relative-imports = "all" -[tool.isort] -profile = "black" -line_length = 119 -atomic = true -order_by_type = false -case_sensitive = true -combine_as_imports = true +[tool.ruff.format] +line-ending = "lf" [tool.pytest.ini_options] minversion = "6.0" @@ -257,10 +282,9 @@ exclude-modules = ''' [tool.taskipy.tasks] precommit = "pre-commit install" lint = "pre-commit run --all-files" -black = "black ." -isort = "isort ." pyright = "pyright ." -flake8 = "flake8 ." +ruff = "ruff check --fix ." +ruff-format = "ruff format ." slotscheck = "slotscheck -m mcproto" test = "pytest -v --failed-first" retest = "pytest -v --last-failed" diff --git a/tests/mcproto/test_connection.py b/tests/mcproto/test_connection.py index 7a8b4013..a778864a 100644 --- a/tests/mcproto/test_connection.py +++ b/tests/mcproto/test_connection.py @@ -51,7 +51,6 @@ def close(self) -> None: @override def shutdown(self, __how: int, /) -> None: """Mock version of shutdown, without any real implementation.""" - pass class MockStreamWriter(CustomMockMixin, MagicMock):