Skip to content
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

Adds --verify #195

Merged
merged 15 commits into from
Nov 3, 2024
Merged

Adds --verify #195

merged 15 commits into from
Nov 3, 2024

Conversation

jspaezp
Copy link
Contributor

@jspaezp jspaezp commented Feb 18, 2024

Discussed here #153

The idea is to have a cli flag that works as --dry-run BUT returns a status 1 if any change would have been made on the files.

This PR is still a work in progress, right now its compatible with the behavior of the rest of the flags but I think we need to add a test case that verifies its behavior directly (2 files, one that gets changed, one that doesnt and make sure they exit with the correct error) an additional test I can think of is that no file should return status 1 if it has already been stripped (so .... step 1, verify it returns status 1, make sure no changes are made; step 2 run bstripout, step 3 verify that it returns status 0 on the modified file).

if args.mode == 'zeppelin':
nb = json.load(input_stream, object_pairs_hook=collections.OrderedDict)
nb_str_orig = json.dumps(nb, indent=2)
Copy link
Owner

Choose a reason for hiding this comment

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

What's the reason for writing to a JSON formatted string here and below? Could you also just compare the dicts directly? Not necessarily objecting, just trying to understand why you've implemented it this way :)

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 was afraid of instances where the dict is different but the serialization is the same; for instance if for some reason the strip zepellin converts a list to a tuple. Both are equivalent in json but not as python dicts. (It might also prevent some edge cases where copying vs deep cloning might be an issue)

Example

import json

d1 = {"a": 1, "b": [1,]}
d2 = {"a": 1, "b": (1,)}

print(json.dumps(d1) == json.dumps(d2))
# True
print(d2 == d1)
# False
print(json.dumps(d2))
# {"a": 1, "b": [1]}

(I am not 100% sure if my concerns are totally grounded, but felt better).

Copy link
Owner

Choose a reason for hiding this comment

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

You are indeed correct that both strip_output and strip_zeppelin_output mutate the existing dict, so we'd probably need to create a deep copy for comparison purposes. I'd prefer that over the JSON serialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
jspaezp and others added 3 commits March 18, 2024 02:28
Co-authored-by: Florian Rathgeber <[email protected]>
Co-authored-by: Florian Rathgeber <[email protected]>
Co-authored-by: Florian Rathgeber <[email protected]>
if args.mode == 'zeppelin':
nb = json.load(input_stream, object_pairs_hook=collections.OrderedDict)
nb_str_orig = json.dumps(nb, indent=2)
Copy link
Owner

Choose a reason for hiding this comment

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

You are indeed correct that both strip_output and strip_zeppelin_output mutate the existing dict, so we'd probably need to create a deep copy for comparison purposes. I'd prefer that over the JSON serialization.

tests/test_end_to_end.py Outdated Show resolved Hide resolved
@sh0rtcircuit
Copy link

@jspaezp Are there any updates on this? It would be super-helpful if this PR could be completed =)

@jspaezp
Copy link
Contributor Author

jspaezp commented Oct 17, 2024

@sh0rtcircuit Thanks for the nudge!
I added the suggestions in a51d43f

Also took care of updating to the main branch.
@kynan LMK If there is anything else you would like done!

nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
nbstripout/_nbstripout.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
@jspaezp jspaezp requested a review from kynan October 19, 2024 23:21
Copy link
Owner

@kynan kynan left a comment

Choose a reason for hiding this comment

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

Nearly there :)

tests/test_end_to_end.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
tests/test_end_to_end.py Outdated Show resolved Hide resolved
@jspaezp jspaezp requested a review from kynan October 21, 2024 05:17
Copy link
Owner

@kynan kynan left a comment

Choose a reason for hiding this comment

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

2 minor nits, then we should we good once you've addressed the failing tests :)

Comment on lines 73 to 76
if input_ != expected:
assert pc.returncode == 1
else:
assert pc.returncode == 0
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if input_ != expected:
assert pc.returncode == 1
else:
assert pc.returncode == 0
assert pc.returncode == 1 if input_ != expected else 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This the tests really hard to figure out and I partially reverted the change bc it is equivalent to ...

>>> (pc.returncode == 1) if input_ != expected else (0)

instead of

>>> pc.returncode == (1 if input_ != expected else 0)

Comment on lines 126 to 129
if verify:
assert pc.returncode == 1
else:
assert pc.returncode == 0
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if verify:
assert pc.returncode == 1
else:
assert pc.returncode == 0
assert pc.returncode == 1 if verify else 0

jspaezp and others added 2 commits October 27, 2024 13:09
Co-authored-by: Florian Rathgeber <[email protected]>
Co-authored-by: Florian Rathgeber <[email protected]>
@jspaezp jspaezp requested a review from kynan October 27, 2024 20:09
@kynan
Copy link
Owner

kynan commented Oct 28, 2024

@jspaezp Unfortunately tests are still failing :(

@kynan
Copy link
Owner

kynan commented Nov 2, 2024

Thanks, that's looking good now and tests are passing. The only thing missing now is documentation. Are you happy to document this in the README? Sorry this has been dragging on for so long :(

@jspaezp
Copy link
Contributor Author

jspaezp commented Nov 2, 2024

Updated the readme on f5b02d2

@kynan kynan added this to the 0.8.0 milestone Nov 3, 2024
Copy link
Owner

@kynan kynan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! This is ready to merge now 👍🏽

@kynan kynan merged commit b8fd98c into kynan:main Nov 3, 2024
15 checks passed
@jspaezp jspaezp deleted the feature/verify_flag2 branch November 3, 2024 17:14
@sh0rtcircuit
Copy link

Guys you are amazing thanks a lot !! 👏😃

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

Successfully merging this pull request may close these issues.

3 participants