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

[] [SVCS-694] Fix wb_path imports #334

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

NyanHelsing
Copy link
Contributor

@NyanHelsing NyanHelsing commented Apr 10, 2018

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

@coveralls
Copy link

coveralls commented Apr 10, 2018

Coverage Status

Coverage decreased (-0.01%) to 89.851% when pulling be645cc on birdbrained:ft/wb-path-import-fix into 98b057c on CenterForOpenScience:develop.

Copy link
Contributor

@cslzchen cslzchen left a 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. 🎆

from waterbutler import settings as wb_settings
from waterbutler.core.metrics import MetricsRecord
from waterbutler.core import exceptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine exceptions and streams

from waterbutler.core.utils import RequestHandlerContext
from waterbutler.core.utils import ZipStreamGenerator
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine ZipStreamGenerator and RequestHandlerContext.

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
Copy link
Contributor

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.
@NyanHelsing NyanHelsing changed the title [] [] Fix wb_path imports [] [SVCS-694] Fix wb_path imports Apr 18, 2018
Copy link
Contributor

@cslzchen cslzchen left a 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 (
Copy link
Contributor

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, )

Copy link
Contributor

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).

rename: str=None,
conflict: str='replace',
handle_naming: bool=True
) -> typing.Tuple[wb_metadata.BaseMetadata, bool]:
Copy link
Contributor

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)

Copy link
Contributor

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.

conflict: str='replace',
handle_naming: bool=True
) -> typing.Tuple[wb_metadata.BaseMetadata, bool]:
"""
Copy link
Contributor

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)

"""Moves a file or folder from the current provider to the specified one
async def move(
self,
dest_provider: 'BaseProvider',
Copy link
Contributor

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.)

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]
Copy link
Contributor

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(
Copy link
Contributor

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.

ResponseStreamRenderer,
ZipStreamRenderer
)
from waterbutler.core.utils import (
Copy link
Contributor

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.

@cslzchen
Copy link
Contributor

cslzchen commented May 7, 2018

Reviewing this now but meanwhile please remove this merge commit be645cc and use rebase, thanks. @birdbrained

Copy link
Contributor

@cslzchen cslzchen left a 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 (
Copy link
Contributor

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 (
Copy link
Contributor

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
Copy link
Contributor

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.

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