Skip to content

fix: array decoding in sysctl-runner#775

Closed
alexruzenhack wants to merge 16 commits intomasterfrom
fix/sysctl-runner
Closed

fix: array decoding in sysctl-runner#775
alexruzenhack wants to merge 16 commits intomasterfrom
fix/sysctl-runner

Conversation

@alexruzenhack
Copy link
Contributor

Motivation

Fix SysctlRunner array decode.

Acceptance Criteria

  • Test decode and array with more than 1 element with success. See test_command_option_sysctl_init_file in tests/cli/test_sysctl_init.py.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@alexruzenhack alexruzenhack self-assigned this Sep 20, 2023
@alexruzenhack alexruzenhack changed the title fix: sysctl-runner fix: arra decoding in sysctl-runner Sep 20, 2023
@alexruzenhack alexruzenhack changed the title fix: arra decoding in sysctl-runner fix: array decoding in sysctl-runner Sep 20, 2023
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (fd3c1ff) 84.66% compared to head (a3de3c3) 84.69%.
Report is 3 commits behind head on master.

❗ Current head a3de3c3 differs from pull request most recent head 7b43158. Consider uploading reports for the commit 7b43158 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #775      +/-   ##
==========================================
+ Coverage   84.66%   84.69%   +0.03%     
==========================================
  Files         264      260       -4     
  Lines       22034    21955      -79     
  Branches     3369     2966     -403     
==========================================
- Hits        18654    18594      -60     
+ Misses       2725     2712      -13     
+ Partials      655      649       -6     
Files Coverage Δ
hathor/builder/sysctl_builder.py 41.66% <ø> (ø)
hathor/sysctl/runner.py 86.36% <50.00%> (-3.64%) ⬇️
hathor/sysctl/init_file_loader.py 33.33% <33.33%> (ø)

... and 30 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# - It ends with a closing square bracket ].
# - The elements are separated by commas and can be followed by optional whitespace.
# - There can be zero or more elements in the array (an empty array is allowed).
array_pattern = r'^\s*\[\s*(?:[^\[\],]+(?:\s*,\s*[^\[\],]+)*)?\s*\]\s*$'
Copy link
Member

Choose a reason for hiding this comment

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

The regex pattern is hard to understand for me. I understand the "positive" cases, but what are the "negative" cases: what are we trying to prevent from being parsed as a list/array by using this regex?

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've update it and tried to make the regex clearer.

Copy link
Member

Choose a reason for hiding this comment

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

I've seen it, the updated one is even longer. I used some tools to break it down and understand how it works. However I don't like the solution too much, because we're making a regex pattern that really has to understand JSON syntax, and I don't think it's really possible with regex. I have a different proposal to tackle this without having to use a regex I'll explain further on our chat with @msbrogli so we can discuss it better.

return ()

if re.match(array_pattern, value_str):
return list(json.loads(value_str))
Copy link
Member

Choose a reason for hiding this comment

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

Won't this produce a list inside a list? I don't understand how this is working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. The list(...) is consolidating to list type, apparently. Take a look:
image

Copy link
Member

Choose a reason for hiding this comment

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

I guess this solution would not work if the method returns a tuple[int, list[str]], for instance. But I haven't really tested against this case yet.

@alexruzenhack alexruzenhack force-pushed the feat/add-optional-argument branch 2 times, most recently from 7404f94 to f6edfcf Compare September 25, 2023 17:17
Base automatically changed from feat/add-optional-argument to master September 25, 2023 18:05
@alexruzenhack
Copy link
Contributor Author

Replaced by #820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants