fix: accept all Docker-style memory limits in convert_mem_limit_to_bytes#14
Open
mkzung wants to merge 1 commit into
Open
fix: accept all Docker-style memory limits in convert_mem_limit_to_bytes#14mkzung wants to merge 1 commit into
mkzung wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem.
convert_mem_limit_to_bytesonly handled lowercase single-letter units and usedstr.replace, so valid Docker memory limits raisedValueError:8G,512M,1gb, or a bare byte count all failed. The samemem_limitstring is passed straight to Docker for the container limit incompressor.py(docker-py'sparse_bytesaccepts all of those), so a user could set--mem-limit 8G, Docker would take it for the container, and the memory-hint conversion would crash on the same value.Fix. Parse it the way Docker does (case-insensitive, 1024-based): a number with an optional
b/k/m/gunit (also writtenkb/mb/gb) or a bare byte count; clearValueErroron invalid input (empty, negative, non-finite, or unrecognised unit).Tests / CI.
CLAUDE.mdalready documents apytest/tests/workflow, but the repo had notests/directory andpytestwas not in the dev group, so the documentedpytestcommand did not work out of the box. This adds the first test module for the parser (valid + invalid cases, and a check that it agrees with docker-py'sparse_byteson configurable values), appendspytestto the existing dev group, and a small GitHub Actions workflow that runs the documented command on PRs (uv sync --dev+uv run pytest).If a reviewer prefers, the CI workflow can be split into a follow-up PR.