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

DEVOPS-1440 Add Precommit #195

Closed
wants to merge 21 commits into from
Closed

DEVOPS-1440 Add Precommit #195

wants to merge 21 commits into from

Conversation

bio-boris
Copy link
Collaborator

  • This adds precommit hooks
  • This PR also runs black and flake8 against the code and checks it in

pyproject.toml Outdated Show resolved Hide resolved
return web.FileResponse(
path.full_path, headers={"content-type": "application/octet-stream"}
)
return web.FileResponse(path.full_path, headers={"content-type": "application/octet-stream"})

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
staging_service/metadata.py Fixed Show fixed Hide fixed
staging_service/metadata.py Fixed Show fixed Hide fixed
@bio-boris bio-boris marked this pull request as ready for review April 24, 2024 22:07
Comment on lines 24 to 33
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args:
- --ignore=E203,W503
- --max-line-length=120
- --config=.flake8
files: '\.py$'
additional_dependencies: [ flake8 ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ruff replaces flake8 - no need to have both

.flake8 Outdated Show resolved Hide resolved
@@ -34,21 +34,23 @@ def bootstrap_config():
def assert_exception_correct(got: Exception, expected: Exception):
err = "".join(traceback.TracebackException.from_exception(got).format())
assert got.args == expected.args, err
assert type(got) == type(expected)
assert type(got) == type(expected) # noqa: E721
Copy link
Collaborator

Choose a reason for hiding this comment

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

I presume this rule wants you to use isinstance instead of type? Better to remove the # noqa and either fix it in this PR or in an upcoming one since it's a simple fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe I had discussions with @MrCreosote about how it needed to be this way rather than isinstance, but maybe I am mis-remembering. Can you chime in here @MrCreosote ?

Copy link
Member

Choose a reason for hiding this comment

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

Because you want to assert against the exact exception type, not the type's inheritance hierarchy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh -- in that case I'm sure that there are ways around this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do I need to do next?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For now, remove # noqa, it can be fixed in an upcoming PR (I am happy to fix it once you have finished your PRs).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we discussed in slack, we are keeping this one # noqa: E721 and changing the rest of them to be isinstance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the rest of the isinstance

E("Invalid order_and_display entry for datatype t at index 1 - "
+ "the entry is not a list"))
{"t": {"order_and_display": [["foo", "bar"], "baz"], "data": []}},
E("Invalid order_and_display entry for datatype t at index 1 - " + "the entry is not a list"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

unneeded concat

"data": [],
}
},
E("Invalid order_and_display entry for datatype t at index 2 - " + "expected 2 item list"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

unneeded concat

"data": [],
}
},
E("Invalid order_and_display entry for datatype t at index 0 - " + "expected 2 item list"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

and again

@@ -275,8 +387,7 @@ def test_xsv_parse_fail_missing_column_header_entries(temp_dir: Path):
def test_xsv_parse_fail_missing_data(temp_dir: Path):
err = "No non-header data in file"
lines = [
"Data type: foo; Columns: 3; Version: 1\n"
"head1, head2, head3\n",
"Data type: foo; Columns: 3; Version: 1\n" "head1, head2, head3\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

can these two strings be converted into a single string?

@@ -285,40 +396,35 @@ def test_xsv_parse_fail_missing_data(temp_dir: Path):
def test_xsv_parse_fail_unequal_rows(temp_dir: Path):
err = "Incorrect number of items in line 3, expected 3, got 2"
lines = [
"Data type: foo; Columns: 3; Version: 1\n"
"head1, head2, head3\n",
"Data type: foo; Columns: 3; Version: 1\n" "head1, head2, head3\n",
Copy link
Collaborator

@ialarmedalien ialarmedalien Apr 25, 2024

Choose a reason for hiding this comment

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

same here and below

@ialarmedalien
Copy link
Collaborator

This is the Ruff config that I've been using for recent projects -- although you may want to add it in one of the upcoming PRs if you're doing one focussed on dev tools. I just have all the available modules listed and comment out the ones that aren't appropriate. It's easier than looking up the docs every time!

@bio-boris bio-boris changed the title Add Precommit DEVOPS-1440 Add Precommit Apr 25, 2024
pyproject.toml Outdated
Comment on lines 42 to 43
select = ["E4", "E7", "E9", "F"]
ignore = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

this only checks a very small selection of errors. Let's start with the "core" error checks and we can add more as required.

select = [
    # core
    "F", # Pyflakes
    "E", # pycodestyle errors
    "W", # pycodestyle warnings
    "C90", # mccabe +
    "I", # isort
    "N", # pep8-naming
    # "D", # pydocstyle - disabled for now
    "UP", # pyupgrade
]

a few ignores to add:

# E203: whitespace before ‘,’, ‘;’, or ‘:’
# E501: line length
# W503: line break after binary operator
ignore = [
    "E203",
    "E501",
    "S101",
]

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

@bio-boris bio-boris closed this Apr 30, 2024
@bio-boris bio-boris mentioned this pull request Apr 30, 2024
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