Skip to content

Conversation

@dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Aug 7, 2025

Adding new linters:

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

@dragomirp dragomirp added the not bug or enhancement PR is not 'bug' or 'enhancement'. For release notes label Aug 7, 2025
Comment on lines +968 to +969
# TODO Should we be using md5 here?
return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

s/md5/sha256/

Copy link
Contributor

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).

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 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"
Copy link
Contributor Author

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"
Copy link
Contributor Author

@dragomirp dragomirp Aug 7, 2025

Choose a reason for hiding this comment

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

Bump to latest ruff.

Copy link
Contributor

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?

Copy link
Contributor Author

@dragomirp dragomirp Aug 8, 2025

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"
Copy link
Contributor Author

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.

Comment on lines +381 to +382
# TODO use set_ports instead
subprocess.check_call(["open-port", f"{port}/tcp"]) # noqa: S603 S607
Copy link
Contributor Author

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.

Copy link
Contributor

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

Comment on lines -2419 to -2420
if skip_release_lock:
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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

Comment on lines +273 to +274
# Awaitied insed the loop
lambda: unit.workload_status == "active", # noqa: B023
Copy link
Contributor Author

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?

Copy link
Contributor

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

Comment on lines +469 to +470
except RetryError as e:
raise Exception("Failed to start server.") from e
Copy link
Contributor Author

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.

Copy link
Contributor

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

@dragomirp dragomirp marked this pull request as ready for review August 7, 2025 18:37
@dragomirp dragomirp requested review from a team, carlcsaposs-canonical, paulomach, shayancanonical, sinclert-canonical and taurus-forever and removed request for a team August 7, 2025 18:37
Copy link
Contributor

@paulomach paulomach left a 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
Copy link
Contributor

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"
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Comment on lines +381 to +382
# TODO use set_ports instead
subprocess.check_call(["open-port", f"{port}/tcp"]) # noqa: S603 S607
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

that's embarrassing

Comment on lines +469 to +470
except RetryError as e:
raise Exception("Failed to start server.") from e
Copy link
Contributor

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

Copy link
Contributor

@paulomach paulomach left a 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

Comment on lines +968 to +969
# TODO Should we be using md5 here?
return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324
Copy link
Contributor

Choose a reason for hiding this comment

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

s/md5/sha256/

Comment on lines -2419 to -2420
if skip_release_lock:
return
Copy link
Contributor

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

Comment on lines +273 to +274
# Awaitied insed the loop
lambda: unit.workload_status == "active", # noqa: B023
Copy link
Contributor

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

Copy link
Contributor

@taurus-forever taurus-forever left a 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!

Comment on lines +968 to +969
# TODO Should we be using md5 here?
return hashlib.md5(random_characters.encode("utf-8")).hexdigest() # noqa: S324
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

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"
Copy link
Contributor

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?

@dragomirp dragomirp merged commit 57441ed into main Aug 8, 2025
450 of 455 checks passed
@dragomirp dragomirp deleted the add-linters branch August 8, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Libraries: Out of sync not bug or enhancement PR is not 'bug' or 'enhancement'. For release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants