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

New file progress #933

Merged
merged 32 commits into from
Jul 31, 2019
Merged

New file progress #933

merged 32 commits into from
Jul 31, 2019

Conversation

asvetlov
Copy link
Contributor

  1. Rewrite CLI progress for file operations
  2. Enable the progress by default on TTY

@asvetlov
Copy link
Contributor Author

The code is mainly finished, I like how it looks now.
Working on test coverage.

neuromation/api/storage.py Outdated Show resolved Hide resolved
for child in await self.ls(src):
progress.enter(StorageProgressEnterDir(src, dst))
folder = await self.ls(src)
folder.sort(key=lambda item: (item.is_dir(), item.name))
Copy link
Contributor

Choose a reason for hiding this comment

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

The same sorting key is used in upload_dir() and download_dir(). Maybe expose it as a named function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quite not the same: item is FileStatus here but pathlib.Path in other places.

@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #933 into master will increase coverage by 0.06%.
The diff coverage is 98.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #933      +/-   ##
==========================================
+ Coverage   91.29%   91.36%   +0.06%     
==========================================
  Files          37       37              
  Lines        4103     4203     +100     
  Branches      608      634      +26     
==========================================
+ Hits         3746     3840      +94     
  Misses        248      248              
- Partials      109      115       +6
Impacted Files Coverage Δ
neuromation/cli/printer.py 100% <100%> (ø) ⬆️
neuromation/cli/formatters/images.py 85.71% <100%> (ø) ⬆️
neuromation/api/abc.py 100% <100%> (ø) ⬆️
neuromation/cli/storage.py 79.17% <100%> (+0.06%) ⬆️
neuromation/api/storage.py 97.87% <100%> (-0.31%) ⬇️
neuromation/cli/formatters/jobs.py 97.04% <66.66%> (-0.85%) ⬇️
neuromation/cli/formatters/storage.py 99.1% <99.31%> (+2.5%) ⬆️
neuromation/api/utils.py 90% <0%> (-6.67%) ⬇️
neuromation/api/url_utils.py 87.87% <0%> (-4.55%) ⬇️
neuromation/cli/main.py 66.33% <0%> (-3.47%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f1b052...a8062fa. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #933 into master will increase coverage by 0.46%.
The diff coverage is 99.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #933      +/-   ##
==========================================
+ Coverage   91.29%   91.76%   +0.46%     
==========================================
  Files          37       37              
  Lines        4103     4201      +98     
  Branches      608      633      +25     
==========================================
+ Hits         3746     3855     +109     
+ Misses        248      237      -11     
  Partials      109      109
Impacted Files Coverage Δ
neuromation/cli/printer.py 100% <100%> (ø) ⬆️
neuromation/cli/formatters/images.py 85.71% <100%> (ø) ⬆️
neuromation/api/abc.py 100% <100%> (ø) ⬆️
neuromation/cli/formatters/jobs.py 97.89% <100%> (ø) ⬆️
neuromation/cli/storage.py 79.17% <100%> (+0.06%) ⬆️
neuromation/api/storage.py 98.21% <100%> (+0.03%) ⬆️
neuromation/cli/formatters/storage.py 99.1% <99.31%> (+2.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f1b052...239590a. Read the comment docs.

neuromation/cli/formatters/images.py Outdated Show resolved Hide resolved
neuromation/cli/formatters/jobs.py Outdated Show resolved Hide resolved
return (
self.color_indicator[GnuIndicators.LEFT]
+ color
+ self.color_indicator[GnuIndicators.RIGHT]
+ underline
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use style(lable, fg=color, underline=self._underline or None)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It produces a little different ANSI sequence.
I've tried but rejected the idea for the sake of less unittest changes.

@@ -43,17 +42,16 @@ def __init__(self) -> None:
def total_lines(self) -> int:
return self._total_lines

def print(self, text: str, lineno: Optional[int] = None) -> str:
def print(self, text: str, lineno: int = -1) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems lineno was 1-based, but now it is 0-based. Is it correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is true.
I've found that 0-based index is more native for Python program.
Also, -1 is a good indicator for not set value here, it is better than None from typing perspective.
The change doesn't touch the public part of API.

width = self.full_width
while len(label) > width:
parts = list(url.parts)
if len(parts) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would not be better to check the negative condition and get rid of one indentation level?

if not parts:
    break
if parts[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.

Maybe, I'll try.
Wrote the method by looking on generated output and tuning code.
Perhaps it can be rewritten for less repetition

if len(parts) > 1:
if parts[0] == "/":
if len(parts) < 3:
slash = "/"
Copy link
Contributor

Choose a reason for hiding this comment

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

slash is not used after the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, pre = f"//{url.host or ''}{slash}"

slash = ""
# len(parts) > 1 always
first, second, *last = parts
if first == "...":
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the part after if first == "...": is common in both branches.

else:
# there is only top folder line, drop next file line
del self.lines[1]
for lineno, line in enumerate(self.lines):
Copy link
Contributor

Choose a reason for hiding this comment

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

If there was a problem with 1-based linenos, you could use enumerate(self.lines, 1).

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 know about enumerate(it, start) variant.

The reason for conversion to 0-based index is mainly the fact that list and other Python types are 0-based too. There is no motivation for 1-based ones, Python is not Pascal.

The code can be rewritten with 1-based indexes, sure. I just think that 0-based is more readable.

@asvetlov asvetlov merged commit c650903 into master Jul 31, 2019
@asvetlov asvetlov deleted the enable-progress branch July 31, 2019 11:05
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