Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ruff improvements #359

Merged
merged 13 commits into from
Nov 23, 2023
Merged
4 changes: 2 additions & 2 deletions .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
# --ignore-vuln "GHSA-hcpj-qp55-gfph" # GitPython vulnerability, dev only dependency
poetry run pip-audit --ignore-vuln "GHSA-wfm5-v35h-vwf4" --ignore-vuln "GHSA-cwvm-v4w8-q58c" --ignore-vuln "PYSEC-2022-43059"

- name: Check formatting with Black
- name: Check formatting with Ruff
run: |
# stop the build if there are files that don't meet formatting requirements
poetry run black --check .
poetry run ruff format --check .

- name: Check linting with Ruff
run: |
Expand Down
30 changes: 16 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
repos:
- repo: local
hooks:
- id: black
name: black
description: "Black: The uncompromising Python code formatter"
entry: poetry run black
- id: ruff-format
name: ruff-format
description: "Run 'ruff format' for extremely fast Python formatting"
entry: poetry run ruff format
language: system
minimum_pre_commit_version: 2.9.2
types: [python]
args: []
require_serial: true
types_or: [ python, pyi ]
additional_dependencies: []
minimum_pre_commit_version: "0"
- id: ruff
name: ruff
description: "Run 'ruff' for extremely fast Python linting"
entry: poetry run ruff
language: system
'types': [python]
"types": [python]
args: [--fix]
require_serial: false
additional_dependencies: []
minimum_pre_commit_version: '0'
files: '^(src|tests)/'
minimum_pre_commit_version: "0"
files: "^(src|tests)/"
- id: mypy
name: mypy
description: '`mypy` will check Python types for correctness'
description: "`mypy` will check Python types for correctness"
entry: poetry run mypy
language: system
types_or: [ python, pyi ]
types_or: [python, pyi]
require_serial: true
additional_dependencies: [ ]
minimum_pre_commit_version: '2.9.2'
files: '^(src|tests)/'
additional_dependencies: []
minimum_pre_commit_version: "2.9.2"
files: "^(src|tests)/"
28 changes: 15 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
// Don't want to use isort because it conflicts with Ruff - see run on save below
"source.organizeImports": false
"source.organizeImports": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably remove the comment now.

"source.fixAll": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.exclude": {
Expand Down Expand Up @@ -32,30 +33,31 @@
}
},
"python.analysis.extraPaths": ["${workspaceFolder}/src"],
"python.formatting.provider": "black",
"[python]": {
// https://dev.to/eegli/quick-guide-to-python-formatting-in-vs-code-2040
"editor.defaultFormatter": null
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.analysis.typeCheckingMode": "basic",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"ruff.enable": true,
"ruff.lint.run": "onSave",
"ruff.lint.args": ["--config=pyproject.toml"],
"ruff.importStrategy": "fromEnvironment",
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": false,
"ruff.fixAll": true, //lint and fix all files in workspace
"ruff.organizeImports": true, //organize imports on save
"ruff.codeAction.disableRuleComment": {
"enable": true
},
"ruff.codeAction.fixViolation": {
"enable": true
},

"mypy.configFile": "pyproject.toml",
// set to empty array to use config from project
"mypy.targets": [],
"mypy.runUsingActiveInterpreter": true,
"python.linting.banditEnabled": false,
"python.linting.prospectorEnabled": false,
"python.linting.pydocstyleEnabled": false,
"python.linting.pycodestyleEnabled": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"emeraldwalk.runonsave": {
"commands": [
// Run Ruff linter on save of Python file
{
"match": "\\.py$",
"cmd": "${workspaceFolder}/.venv/bin/ruff ${file} --fix"
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AlgoKit development is done within the [AlgoKit Guiding Principles](./docs/algok
2. Install pre-requisites:

- Manually:
- Install `Python` - [Link](https://www.python.org/downloads/): The minimum required version is `3.10`. It is also recommended to use `3.10` for development so dependencies on higher versions are not introduced, and to avoid debugging issues with `3.11`(see https://github.com/fabioz/PyDev.Debugger/issues/234 and https://github.com/microsoft/debugpy/issues/939)
- Install `Python` - [Link](https://www.python.org/downloads/): The minimum required version is `3.10`. It is also recommended to use `3.10` for development so dependencies on higher versions are not introduced, and to avoid debugging issues with `3.10`(see <https://github.com/fabioz/PyDev.Debugger/issues/234> and <https://github.com/microsoft/debugpy/issues/939>)
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
- Install `Poetry` - [Link](https://python-poetry.org/docs/#installation): The minimum required version is `1.2`.
- If you're not using PyCharm, then run `poetry install` in the root directory (this should set up `.venv` and install all Python dependencies - PyCharm will do this for you on startup)
- Via automated script:
Expand Down Expand Up @@ -66,11 +66,13 @@ AlgoKit development is done within the [AlgoKit Guiding Principles](./docs/algok
- In each of the above cases, an `args.in` file will be created in the source root.
Each line will be executed in order, with the arguments passed to the cli.
For example, you could have:

```
version
--help
version --help
```

Not a terribly useful sequence of commands, but hopefully this helps illustrate the usage.

### Subsequently
Expand Down
2 changes: 1 addition & 1 deletion debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
os.chdir(vcs_root / "src")
for command in commands_sequence or [""]:
click.echo(click.style(f"> algokit -v {command}", bold=True), err=True)
run_result = subprocess.run([sys.executable, "-m", "algokit", "-v", *command.split()])
run_result = subprocess.run([sys.executable, "-m", "algokit", "-v", *command.split()], check=True)
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
if run_result.returncode != 0:
click.echo(
click.style(
Expand Down
Loading