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

Ruff code auto-format #1105

Merged
merged 8 commits into from
Mar 15, 2024

Conversation

SofiaSazonova
Copy link
Contributor

Feature or Bugfix

  • Refactoring

Detail

Ruff tool configured for the project.
All files are formatted
In pipelines instead of "make lint" now "make ruff" is used

Relates

#1076

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@SofiaSazonova SofiaSazonova requested a review from petrkalos March 13, 2024 17:34
@SofiaSazonova
Copy link
Contributor Author

Flake8 fails, but it's fine by now. It's only a first iteration of introducing Ruff.
Ruff rules are slightly different

Copy link
Contributor

@petrkalos petrkalos left a comment

Choose a reason for hiding this comment

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

Since this is python and even format changes can easily break functionality can you describe what short of testing did you perform to validate the PR?

@@ -33,9 +33,9 @@ install-cdkproxy:
install-tests:
pip install -r tests/requirements.txt

lint:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't makefile target tool specific, let's keep it as lint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be we can keep both? I don't want the name to be confusing, since it's just an alias

Copy link
Contributor

Choose a reason for hiding this comment

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

Previously we were running flake8 and we called the target lint and not flake8 which I think is correct because it's abstracting whatever underlying linter we use and also that way we wouldn't have to change the pipelines code.

python -m flake8 --exclude cdk.out,blueprints --ignore E402,E501,F841,W503,F405,F403,F401,E712,E203 backend/
ruff:
pip install ruff
ruff check --fix
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we run ruff format here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

btw forgot to say that we should be taking into account both check and format exit codes and fail the target if either of them fail.

line-length = 120
target-version = ["py37", "py38", "py39", "py310"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep target-version as 39 which is the lambda runtime version we use?

pyproject.toml Outdated

[tool.ruff.lint]
exclude = [ "backend/migrations","tests/**", "**/input_types.py", "**/mutations.py", "**/queries.py", "**/types.py", "**/api/__init__.py"]
Copy link
Contributor

Choose a reason for hiding this comment

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

why exclude migrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alembic has one weakness, you sometimes have to keep unused imports and other strange stuff. Also, migrations are usually something very specifically tailored, so I thought it's better to exclude this.
But of course I can just add 'noqa'-statements, where it's needed

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are standard strange stuff for Alembic perhaps it's better to use per-file-ignores than noqa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I enabled all formatting back. And added block-comment for current unused imports. In future, if something like this comes up again, we can decide on-the-go, if any other re-configuration is needed

@SofiaSazonova
Copy link
Contributor Author

And the problem with flake8 testing of this PR is
E704 multiple statements on one line (def)
It's a known disagreement, e.g. discussed here
May be we should reconfigure the Github testing then.

@SofiaSazonova
Copy link
Contributor Author

Since this is python and even format changes can easily break functionality can you describe what short of testing did you perform to validate the PR?

  1. Run 'make test' to ensure, that integration test are fine
  2. Run 'cdk list' to ensure, that deployment is build without errors (there were some troubles with imports, that i caught that way)
  3. Perform migrations (drop and upgrade) for local database
  4. Check that CICD pipeline completed

@petrkalos
Copy link
Contributor

And the problem with flake8 testing of this PR is E704 multiple statements on one line (def) It's a known disagreement, e.g. discussed here May be we should reconfigure the Github testing then.

Oh I thought we were going to drop flake8 on a next PR.
I don't think it makes sense to keep 2 formatters/linters.

@petrkalos
Copy link
Contributor

Since this is python and even format changes can easily break functionality can you describe what short of testing did you perform to validate the PR?

  1. Run 'make test' to ensure, that integration test are fine
  2. Run 'cdk list' to ensure, that deployment is build without errors (there were some troubles with imports, that i caught that way)
  3. Perform migrations (drop and upgrade) for local database
  4. Check that CICD pipeline completed

I think another thing you could run is to make some requests through the cdkproxy, an action that will create a new stack (i.e create a new dataset or environment etc)

Copy link
Contributor

@dlpzx dlpzx left a comment

Choose a reason for hiding this comment

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

Looks good to me

@SofiaSazonova SofiaSazonova merged commit a35a4c7 into data-dot-all:main Mar 15, 2024
8 checks passed
@SofiaSazonova SofiaSazonova deleted the 1076-ruff-code-format branch October 3, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants