-
Notifications
You must be signed in to change notification settings - Fork 76
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
[] [SVCS-694] Fix wb_path imports #334
base: develop
Are you sure you want to change the base?
[] [SVCS-694] Fix wb_path imports #334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this PR. Three minor changes as commented. 🎆
waterbutler/core/provider.py
Outdated
from waterbutler import settings as wb_settings | ||
from waterbutler.core.metrics import MetricsRecord | ||
from waterbutler.core import exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine exceptions
and streams
waterbutler/core/provider.py
Outdated
from waterbutler.core.utils import RequestHandlerContext | ||
from waterbutler.core.utils import ZipStreamGenerator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine ZipStreamGenerator
and RequestHandlerContext
.
waterbutler/core/provider.py
Outdated
from waterbutler import settings as wb_settings | ||
from waterbutler.core.metrics import MetricsRecord | ||
from waterbutler.core import exceptions | ||
from waterbutler.core import metadata as wb_metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from waterbutler.core.metadata import (...,
...,
..., )
Remove some of the qualified imports as they are not needed to be qualified. Make some of the import more explicit as to which symbols are being imported.
9fd0534
to
d50d4b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix import styles and usages
- Fix the first line for DocStr
- Fix type annotations
- In the end, use
invoke mypy
to fix further typing errors
from waterbutler.core import exceptions | ||
from waterbutler.core import path as wb_path | ||
from waterbutler import settings as wb_settings | ||
from waterbutler.core.metadata import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the following style (several occurrences):
from waterbutler.core.metadata import (BaseMetadata,
BaseFileMetadata,
BaseFolderMetadata, )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the WB's style (several occurrences).
waterbutler/core/provider.py
Outdated
rename: str=None, | ||
conflict: str='replace', | ||
handle_naming: bool=True | ||
) -> typing.Tuple[wb_metadata.BaseMetadata, bool]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the typing: wb_metadata.BaseMetadata
-> BaseMetadata
. (Several occurrences)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, using
from typing import ...
will reduce line space and make the type annotation look less ugly.
waterbutler/core/provider.py
Outdated
conflict: str='replace', | ||
handle_naming: bool=True | ||
) -> typing.Tuple[wb_metadata.BaseMetadata, bool]: | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First sentence of DocStr starts on the same line of """
. (Several occurrences)
waterbutler/core/provider.py
Outdated
"""Moves a file or folder from the current provider to the specified one | ||
async def move( | ||
self, | ||
dest_provider: 'BaseProvider', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import the BaseProvider
and use it as it is instead of a string (similar to BaseMetadata, etc.)
waterbutler/core/provider.py
Outdated
return parent_path.child(meta_data.name, _id=meta_data.path.strip('/'), | ||
folder=meta_data.is_folder) | ||
|
||
async def revisions(self, path: wb_path.WaterButlerPath, **kwargs): | ||
"""Return a list of :class:`.BaseFileRevisionMetadata` objects representing the revisions | ||
async def revisions(self, path: WaterButlerPath, **kwargs): -> List[BaseFileRevisionMetadata] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
goes after return type.
for item in items[i:i + wb_settings.OP_CONCURRENCY]: # type: ignore | ||
futures.append(asyncio.ensure_future( | ||
for item in items[i:i + OP_CONCURRENCY]: # type: ignore | ||
future = asyncio.ensure_future( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a functional change that I will test locally. Need to verify that the current future
is not used in the for
loop.
waterbutler/core/provider.py
Outdated
ResponseStreamRenderer, | ||
ZipStreamRenderer | ||
) | ||
from waterbutler.core.utils import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put them in one line if the length is less than 100. I assume this is the case here.
… into ft/wb-path-import-fix
Reviewing this now but meanwhile please remove this merge commit be645cc and use rebase, thanks. @birdbrained |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Major Issue - Import Style
I understand that there are different preferences for line breaking and indentation for import
(and many other styles as well). I am not going to argue which one is better but please use the following one for consistence:
from waterbutler.core.metadata import (BaseMetadata,
BaseFileMetadata,
BaseFolderMetadata, )
The first time I saw this, I felt similarly that it looked very different from what I had been used to. However, I started using this style anyway. The main reason I switched to cater for what WB/MFR already has is consistence.
We already have a style to follow, which was decided about half a year ago and we have been applying them gradually instead of a full refactor. Changing them again to a new style (maybe better, maybe not) doesn't make sense.
CC @felliott
@@ -1,24 +1,41 @@ | |||
import abc | |||
import time | |||
import typing | |||
from typing import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it fits within one line, don't break it.
from typing import List, Set, Tuple, Callable, Union
from waterbutler.core import exceptions | ||
from waterbutler.core import path as wb_path | ||
from waterbutler import settings as wb_settings | ||
from waterbutler.core.metadata import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the WB's style (several occurrences).
@@ -647,7 +647,7 @@ def _build_upload_metadata(self, folder_id: str, name: str) -> dict: | |||
) as resp: | |||
try: | |||
data = await resp.json() | |||
except: # some 404s return a string instead of json | |||
except Exception: # some 404s return a string instead of json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good first step by using Exception
. How about one step further? Take a look at the aiohttp
library and you will find the specific exceptions to use here.
Ticket
https://openscience.atlassian.net/browse/SVCS-694
Purpose
Improve code consistency
Changes
wb_path is being imported qualified from wabterbutler.core.path. Most other files import the WaterButlerPath class directly. This change updates core/provider to align with other files.
Side effects
QA Notes
Deployment Notes