-
Notifications
You must be signed in to change notification settings - Fork 18
[MISC] Add linters #667
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
[MISC] Add linters #667
Conversation
| # TODO Should we be using md5 here? | ||
| return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be a security problem, but it might be better to use a different algorithm or just use the random chars of the expected length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/md5/sha256/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be worth to put algorithm changes into the separate followup PR (to avoid hiding it into Linting changes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use shake_128 in such cases to keep the value short without being bothered by security linters:
>>> stri= b"test"
>>> hashlib.md5(stri).hexdigest()
'098f6bcd4621d373cade4e832627b4f6'
>>> hashlib.shake_128(stri).hexdigest(16)
'd3b0aa9cd8b7255622cebc631e867d40'
>>> hashlib.sha256(stri).hexdigest()
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
But either way, best to be done separately.
| [tool.ruff] | ||
| # preview and explicit preview are enabled for CPY001 | ||
| preview = true | ||
| target-version = "py38" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Focal compatibility for the libs.
|
|
||
| [tool.poetry.group.format.dependencies] | ||
| ruff = "^0.4.5" | ||
| ruff = "^0.12.7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump to latest ruff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renovate config to bump it further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in PR #425
| # preview and explicit preview are enabled for CPY001 | ||
| preview = true | ||
| target-version = "py38" | ||
| target-version = "py310" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use jammy python for non-libs.
| # TODO use set_ports instead | ||
| subprocess.check_call(["open-port", f"{port}/tcp"]) # noqa: S603 S607 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops set_ports should be able to do the same thing without having to call external utilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. my guess this bit predates set_ports
| if skip_release_lock: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm. Ok that makes sense
| # Awaitied insed the loop | ||
| lambda: unit.workload_status == "active", # noqa: B023 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem dangerous, but should the test await serially here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, there's room for improvements. Jubilant migration will be the time
| except RetryError as e: | ||
| raise Exception("Failed to start server.") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's better to enable reraise in Retrying and remove the custom exception, since it makes it easier to figure out what went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on charm code yes. On test either way. Fell free
paulomach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GH is not showing big diffs. Will resume the review tomorrow.
| from ops.charm import ActionEvent | ||
| from ops.framework import Object | ||
| from ops.jujuversion import JujuVersion | ||
| from ops.model import BlockedStatus, MaintenanceStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
| f"Application Name: {self.model.app.name}\n" | ||
| f"Unit Name: {self.charm.unit.name}\n" | ||
| f"Juju Version: {str(juju_version)}\n" | ||
| f"Juju Version: {juju_version!s}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
| select = ["A", "E", "W", "F", "C", "N", "D", "I", "B", "CPY001", "RUF", "S", "SIM", "UP", "TC"] | ||
| ignore = [ | ||
| "D107", # Ignore D107 Missing docstring in __init__ | ||
| "E501", # Ignore E501 Line too long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we ignoring long lines on PG also? I would prefer not to ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulomach you set LGTM, should this be addressed before merging or followup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deep lore is that it comes from the charmcraft templates. I guess it was set for compatibility with black, which was the default formatter before ruff started doing that as well.
Shouldn't practically matter, since the subsequent formatting check will complain about it, but most probably should be removed as legacy fluff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to disable here and in the main pyproject, but causes additional violations with long strings. I guess that the formatter can't handle cutting the strings down.
Merging as is for the time being.
| # TODO use set_ports instead | ||
| subprocess.check_call(["open-port", f"{port}/tcp"]) # noqa: S603 S607 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. my guess this bit predates set_ports
|
|
||
| if pid := self.charm.unit_peer_data.get("observer-pid"): | ||
| if check_pid(int(pid)): | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's embarrassing
| except RetryError as e: | ||
| raise Exception("Failed to start server.") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on charm code yes. On test either way. Fell free
paulomach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worked. Drago, my hero
| # TODO Should we be using md5 here? | ||
| return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/md5/sha256/
| if skip_release_lock: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm. Ok that makes sense
| # Awaitied insed the loop | ||
| lambda: unit.workload_status == "active", # noqa: B023 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, there's room for improvements. Jubilant migration will be the time
taurus-forever
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well.... tiny PR to enable Lints they said. WELL DONE!
| # TODO Should we be using md5 here? | ||
| return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be worth to put algorithm changes into the separate followup PR (to avoid hiding it into Linting changes).
| select = ["A", "E", "W", "F", "C", "N", "D", "I", "B", "CPY001", "RUF", "S", "SIM", "UP", "TC"] | ||
| ignore = [ | ||
| "D107", # Ignore D107 Missing docstring in __init__ | ||
| "E501", # Ignore E501 Line too long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulomach you set LGTM, should this be addressed before merging or followup?
| @@ -1,4 +1,4 @@ | |||
| # This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. | |||
| # This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's my locally installed Poetry version and it sets the version of poetry used to generate the lock.
|
|
||
| [tool.poetry.group.format.dependencies] | ||
| ruff = "^0.4.5" | ||
| ruff = "^0.12.7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renovate config to bump it further?
Adding new linters:
Checklist