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

fix ls --json being corrupted by Using https://... msg #218

Closed
wants to merge 3 commits into from

Conversation

mjurbanski-reef
Copy link

No description provided.

@@ -337,6 +337,7 @@ def should_equal(expected, actual):
class CommandLine:

EXPECTED_STDERR_PATTERNS = [
re.compile(r'^Using https?://[\w.]+.com$'), # account auth

Choose a reason for hiding this comment

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

+\.com

@@ -84,7 +84,9 @@ def _run_command_ignore_output(self, argv):
print('ACTUAL STDERR: ', repr(actual_stderr))
print(actual_stderr)

self.assertEqual('', actual_stderr, 'stderr')
assert re.match(
r'^(|Using https?://[\w.]+.com\n)$', actual_stderr

Choose a reason for hiding this comment

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

I'd prefer (xxx)? over (|xxx) :)
Also, +\.com.
Also, do you need \n if you use $ in the end?

Copy link
Author

@mjurbanski-reef mjurbanski-reef Nov 9, 2023

Choose a reason for hiding this comment

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

(|xxx) catches empty line as well as xxx
as for \n - it indeed is not needed

Comment on lines 291 to 292
['authorize_account', self.account_id, self.master_key], '',
"Using http://production.example.com\n", 0

Choose a reason for hiding this comment

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

I'd make it consistent with other tests, i.e. add

expected_stderr = """
    ...
"""

 '', expected_sterr, 0

Comment on lines 349 to 351
['authorize-account', self.account_id, self.master_key], '',
'Using http://custom2.example.com\n', 0
)

Choose a reason for hiding this comment

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

Same here, make it consistent plz

Comment on lines +2226 to +2227
self._print_files(args)
return 0

Choose a reason for hiding this comment

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

Why not calling super().run(args)? It won't set args.quiet now, and thus you won't be able to mute self.PROGRESS_REPORT_CLASS later as far as I see.


@classmethod
def _print_helper(cls, descriptor, descriptor_encoding, descriptor_name, *args):
def _print_helper(
cls, descriptor, descriptor_encoding, descriptor_name, *args, raw: bool = False

Choose a reason for hiding this comment

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

Why raw instead of print_endline or so?

self._print(
json.dumps(data, indent=4, sort_keys=True, cls=B2CliJsonEncoder), enforce_output=True
)
def _print_json(self, data, *, raw: bool = False):

Choose a reason for hiding this comment

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

This makes no sense to name it _print_json and not to do json dump. I'd say, _print_json should not accept raw data at all. Instead of _print_json(..., raw=True), use _print('[\n', print_endline=False). Actually, since _print(...) adds \n in the end by default, you don't need the print_endline at all, just call _print('['), and it will add \n automatically.

Copy link
Author

Choose a reason for hiding this comment

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

the reason was that I didn't want to expose enforce_output to anything else that method printing actual data - that would invite someone to break intended --quiet behavior.

I guess I will document it in docstring instead.

Comment on lines -1893 to +1898
super().run(args)
def _print_files(self, args):

Choose a reason for hiding this comment

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

Yeah, that's how it should've been from the beginning.

Comment on lines 1998 to 2004
super().run(args)
self._print_files(args)
if args.json:
# TODO: Make this work for an infinite generation.
# Use `_print_file_version` to print a single `file_version` and manage the external JSON list
# e.g. manually. However, to do it right, some sort of state needs to be kept e.g. info whether
# at least one element was written to the stream, so we can add a `,` on the start of another.
# That would sadly lead to an ugly formatting, so `_print` needs to be expanded with an ability
# to not print end-line character(s).
self._print_json([file_version for file_version, _ in self._get_ls_generator(args)])
return 0

return super().run(args)
if self._first_row: # no files were printed
self._print_json('[', raw=True)
self._print_json(']\n', raw=True)
return 0

Choose a reason for hiding this comment

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

I don't get it. How is it supposed to work?
Why not something stupid like

if args.json:
    self._print('[')
    for i, (file_version, _) in enumerate(self._get_ls_generator(args)):
         if i:
            self._print(', ', print_endline=False)
         self._print_json(file_version)
    self._print(']')
else:
     self._print_files(args)

@mjurbanski-reef
Copy link
Author

squash merged in the upstream

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

Successfully merging this pull request may close these issues.

2 participants