Skip to content

Commit

Permalink
chore: Ruff improvements (#59)
Browse files Browse the repository at this point in the history
* chore: updating ruff and vscode settings

* chore: fixing ruff erros
  • Loading branch information
negar-abbasi authored Nov 27, 2023
1 parent cf0e65d commit 7d586d7
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 526 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
# --ignore-vuln "GHSA-hcpj-qp55-gfph" # GitPython vulnerability, dev only dependency
poetry run pip-audit
- 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
31 changes: 17 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
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: "2.9.2"
files: "^(src|tests)/"
- 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,
"source.fixAll": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.exclude": {
Expand All @@ -21,30 +22,31 @@
"platformSettings.autoLoad": true,
"python.defaultInterpreterPath": "${workspaceFolder}/.venv",
"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
489 changes: 20 additions & 469 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ deprecated = "^1.2.14"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
black = {extras = ["d"], version = "^23.9.1"}
ruff = "^0.0.261"
ruff = "^0.1.6"
pip-audit = "^2.5.6"
pytest-mock = "^3.11.1"
mypy = "^1.5.1"
Expand Down Expand Up @@ -93,12 +92,25 @@ select = [
ignore = [
"ANN101", # no type for self
"ANN102", # no type for cls
"SIM108", # allow if-else in place of ternary
"RET505", # allow else after return
"SIM108", # allow if-else in place of ternary
"E111", # indentation is not a multiple of four
"E117", # over-indented
"ISC001", # single line implicit string concatenation
"ISC002", # multi line implicit string concatenation
"Q000", # bad quotes inline string
"Q001", # bad quotes multiline string
"Q002", # bad quotes docstring
"Q003", # avoidable escaped quotes
"W191", # indentation contains tabs
]
# Exclude a variety of commonly ignored directories.
extend-exclude = [
"docs"
"docs",
".git",
".mypy_cache",
".ruff_cache",

]
# Assume Python 3.10.
target-version = "py310"
Expand All @@ -107,9 +119,6 @@ target-version = "py310"
allow-star-arg-any = true
suppress-none-returning = true

[tool.black]
line-length = 120

[tool.poe.tasks]
docs = "sphinx-build docs/source docs/html"

Expand Down
6 changes: 3 additions & 3 deletions src/algokit_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@
ABIMethod,
ABITransactionResponse,
Account,
CommonCallParameters, # noqa: ignore[F401]
CommonCallParametersDict, # noqa: ignore[F401]
CommonCallParameters, # noqa: F401
CommonCallParametersDict, # noqa: F401
CreateCallParameters,
CreateCallParametersDict,
CreateTransactionParameters,
OnCompleteCallParameters,
OnCompleteCallParametersDict,
RawTransactionParameters, # noqa: ignore[F401]
RawTransactionParameters, # noqa: F401
TransactionParameters,
TransactionParametersDict,
TransactionResponse,
Expand Down
12 changes: 6 additions & 6 deletions src/algokit_utils/application_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ApplicationClient:
"""A class that wraps an ARC-0032 app spec and provides high productivity methods to deploy and call the app"""

@overload
def __init__(
def __init__( # noqa: PLR0913
self,
algod_client: "AlgodClient",
app_spec: au_spec.ApplicationSpecification | Path,
Expand All @@ -111,7 +111,7 @@ def __init__(
...

@overload
def __init__(
def __init__( # noqa: PLR0913
self,
algod_client: "AlgodClient",
app_spec: au_spec.ApplicationSpecification | Path,
Expand All @@ -127,7 +127,7 @@ def __init__(
):
...

def __init__(
def __init__( # noqa: PLR0913
self,
algod_client: "AlgodClient",
app_spec: au_spec.ApplicationSpecification | Path,
Expand Down Expand Up @@ -251,7 +251,7 @@ def prepare(
)
return new_client

def _prepare(
def _prepare( # noqa: PLR0913
self,
target: "ApplicationClient",
*,
Expand All @@ -266,7 +266,7 @@ def _prepare(
)
target.template_values = self.template_values | (template_values or {})

def deploy(
def deploy( # noqa: PLR0913
self,
version: str | None = None,
*,
Expand Down Expand Up @@ -978,7 +978,7 @@ def import_source_map(self, source_map_json: str) -> None:
source_map = json.loads(source_map_json)
self._approval_source_map = SourceMap(source_map)

def add_method_call(
def add_method_call( # noqa: PLR0913
self,
atc: AtomicTransactionComposer,
abi_method: ABIMethod | bool | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/algokit_utils/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class AppChanges:
schema_change_description: str | None


def check_for_app_changes(
def check_for_app_changes( # noqa: PLR0913
algod_client: "AlgodClient",
*,
new_approval: bytes,
Expand Down
2 changes: 1 addition & 1 deletion src/algokit_utils/logic_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def parse_logic_error(


class LogicError(Exception):
def __init__(
def __init__( # noqa: PLR0913
self,
*,
logic_error_str: str,
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def check_output_stability(logs: str, *, test_name: str | None = None) -> None:
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
# first fail if there are any changes to already committed files, you must manually add them in that case
assert git_diff.returncode == 0, git_diff.stdout
Expand Down
2 changes: 1 addition & 1 deletion tests/test_app_client_signer_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def sign_transactions(
@pytest.mark.parametrize("override_signer", [CustomSigner(), AccountTransactionSigner(fake_key), None])
@pytest.mark.parametrize("default_sender", ["default_sender", None])
@pytest.mark.parametrize("default_signer", [CustomSigner(), AccountTransactionSigner(fake_key), None])
def test_resolve_signer_sender(
def test_resolve_signer_sender( # noqa: PLR0913
*,
algod_client: "AlgodClient",
app_spec: ApplicationSpecification,
Expand Down
13 changes: 4 additions & 9 deletions tests/test_deploy_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
self.creator = creator
self.app_name = get_unique_name()

def deploy(
def deploy( # noqa: PLR0913
self,
app_spec: ApplicationSpecification,
*,
Expand Down Expand Up @@ -98,8 +98,7 @@ def _normalize_logs(self, logs: str) -> str:
logs = logs.replace(dispenser.address, "{dispenser_account}")
for index, app_id in enumerate(self.app_ids):
logs = logs.replace(f"app id {app_id}", f"app id {{app{index}}}")
logs = re.sub(r"app id \d+", r"{appN_failed}", logs)
return logs
return re.sub(r"app id \d+", r"{appN_failed}", logs)

def _wait_for_indexer_round(self, round_target: int, max_attempts: int = 100) -> None:
for _attempts in range(max_attempts):
Expand Down Expand Up @@ -230,15 +229,11 @@ def test_deploy_app_with_existing_permanent_app_on_update_equals_replace_app_fai
app_v1 = deploy_fixture.deploy(v1, version="1.0", allow_update=False, allow_delete=False)
assert app_v1.app_id

apps_before = deploy_fixture.indexer_client.lookup_account_application_by_creator(
deploy_fixture.creator.address
) # type: ignore[no-untyped-call]
apps_before = deploy_fixture.indexer_client.lookup_account_application_by_creator(deploy_fixture.creator.address) # type: ignore[no-untyped-call]

with pytest.raises(LogicError) as error:
deploy_fixture.deploy(v2, version="3.0", allow_update=False, allow_delete=False, on_update=OnUpdate.ReplaceApp)
apps_after = deploy_fixture.indexer_client.lookup_account_application_by_creator(
deploy_fixture.creator.address
) # type: ignore[no-untyped-call]
apps_after = deploy_fixture.indexer_client.lookup_account_application_by_creator(deploy_fixture.creator.address) # type: ignore[no-untyped-call]

# ensure no other apps were created
assert len(apps_before["applications"]) == len(apps_after["applications"])
Expand Down

1 comment on commit 7d586d7

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit_utils
   _ensure_funded.py69199%99
   _transfer.py62395%13, 76–77
   account.py851385%14–17, 61–65, 96, 109, 136, 139, 183
   application_client.py5519683%53–54, 111, 128, 179, 184, 213, 325, 330–331, 333, 335, 402, 411, 420, 470, 478, 487, 531, 539, 548, 592, 600, 609, 661, 669, 678, 720, 728, 737, 797, 812, 830–833, 909, 949, 961, 974, 1016, 1076–1082, 1086–1091, 1093, 1129, 1136, 1247, 1279, 1333–1335, 1337, 1347–1404, 1415–1420, 1440–1443
   application_specification.py971189%92, 94, 193–202, 206
   asset.py79594%9, 27–30
   config.py17759%13–18, 21–22
   deploy.py4552395%30–33, 168, 172–173, 190, 246, 402, 413–421, 438–441, 451, 459, 652–653, 677
   dispenser_api.py821285%112–113, 117–120, 155–157, 176–178
   logic_error.py38295%6, 30
   models.py126794%45, 50–52, 61–62, 125
   network_clients.py66395%89–90, 121
TOTAL173918389% 

Tests Skipped Failures Errors Time
191 0 💤 0 ❌ 0 🔥 59.583s ⏱️

Please sign in to comment.