fix(project): Use an annotated type for duration strings#5213
fix(project): Use an annotated type for duration strings#5213
Conversation
| # required project data for core24 snaps | ||
| CORE24_DATA = {"base": "core24", "grade": "devel"} | ||
| VALID_DURATIONS = ["10ns", "10us", "10ms", "10s", "10m", "10m4s3us"] | ||
| INVALID_DURATIONS = ["10", "10 s", "10 seconds", "1:00", "invalid"] |
There was a problem hiding this comment.
Surprisingly, just an integer isn't a valid duration. The current snapcraft will error out during the packing step:
$ snapcraft_edge pack
Generated snap metadata
Cannot pack snap: error: cannot parse snap.yaml: time: missing unit in duration "10"
Detailed information: Command '['snap', 'pack', '--check-skeleton', PosixPath('/root/prime')]' returned non-zero exit status 1.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
Full execution log: '/home/lengau/.local/state/snapcraft/log/snapcraft-20250121-181707.415584.log'
|
|
||
| # required project data for core24 snaps | ||
| CORE24_DATA = {"base": "core24", "grade": "devel"} | ||
| VALID_DURATIONS = ["10ns", "10us", "10ms", "10s", "10m", "10m4s3us"] |
There was a problem hiding this comment.
I added a separate data entry for a valid duration here, as "10m4s3us" is a valid duration string. Snapd uses time.ParseDuration to parse this, and the resulting service file contains a value something like TimeoutStartSec=604.000003.
mr-cal
left a comment
There was a problem hiding this comment.
Thank you!
Do you mind targeting hotfix/8.6? The hotfix/8.5 branch is closing in favor of 8.6 this week and I can get this into 8.6.0 or 8.6.1, depending on the timing. It may require a touch of rebasing as Sergio updated the project model.
Inspired by: #5210 This makes an annotated type for duration strings and uses a stricter regex.
d017a82 to
12d16bf
Compare
|
@mr-cal done! I'll take this out of draft once I ensure CI is still succeeding, and then since it was his fine work that gave me a conflict during rebase I'll ask @sergiusens to review. |
Inspired by: #5210
This makes an annotated type for duration strings and uses a stricter regex.
tox run -m lint?tox run -e test-py310? (supported versions:py39,py310,py311,py312)