-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Created new module: unpacking #6866
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.
Thanks! Some initial comments.
@@ -21,23 +21,19 @@ | |||
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response | |||
from pip._vendor.requests.structures import CaseInsensitiveDict | |||
from pip._vendor.requests.utils import get_netrc_auth | |||
# NOTE: XMLRPC Client is not annotated in typeshed as on 2017-07-17, which is |
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 comment shouldn't be removed.
from pip._vendor.six.moves import xmlrpc_client # type: ignore | ||
from pip._vendor.six.moves.urllib import parse as urllib_parse | ||
from pip._vendor.six.moves.urllib import request as urllib_request | ||
|
||
import pip | ||
from pip._internal.exceptions import HashMismatch, InstallationError | ||
from pip._internal.models.index import PyPI | ||
# Import ssl from compat so the initial import occurs in only one place. |
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 comment also shouldn't be removed (don't remove comments unrelated to the PR).
from collections import deque | ||
|
||
from pip._vendor import pkg_resources | ||
# NOTE: retrying is not annotated in typeshed as on 2017-07-17, which is |
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.
Ditto
src/pip/_internal/utils/unpacking.py
Outdated
current_umask, | ||
ensure_dir, | ||
file_contents, | ||
has_leading_dir, |
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.
is_svn_page()
, has_leading_dir()
and split_leading_dir()
should also be moved to the new module, as the only place they're used is in the unpack functions.
src/pip/_internal/utils/unpacking.py
Outdated
logger.debug('lzma module is not available') | ||
|
||
|
||
def unpack_file_url( |
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 would be best if the functions in the module are ordered so that functions only depend on function that occur above them in the module, so ordered low-level to high-level. That way the module can be read top-to-bottom, and it becomes easier to locate things.
Also, the tests of the functions moved to this module should be moved to e.g. test_unpacking.py
, following the pattern of other test modules.
src/pip/_internal/utils/unpacking.py
Outdated
is_dir_url, | ||
url_to_path, | ||
_check_download_dir, | ||
_copy_file |
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.
Also, this module shouldn't have dependencies on download.py
(avoid introducing new nested imports, by the way). Rather, the functions in download.py
that unpack_file_url()
depends on should also be moved into this module. We don't want to have dependencies from utils
to higher-level modules outside of it like download.py
.
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.
A few small comments, but in general I'm concerned about the placement of unpack_file_url
. It embeds a lot of really specific business logic whereas the others are closer to what I'd call utilities. Maybe it would be worth considering keeping it outside utils
.
src/pip/_internal/utils/misc.py
Outdated
Any, AnyStr, Container, Iterable, List, Mapping, Match, Optional, Text, | ||
Tuple, Union, cast, | ||
Any, Container, Iterable, List, Mapping, Optional, Text, | ||
Tuple, cast, AnyStr, Union, Match |
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.
I would alphabetize these.
from typing import Optional | ||
from pip._internal.models.link import Link | ||
from pip._internal.utils.hashes import Hashes | ||
|
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.
I would put two lines between the end of imports and body.
@@ -0,0 +1,286 @@ | |||
# mypy: strict-optional=False |
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.
Elsewhere we pair this with # The following comment should be removed at some point in the future.
, we should do the same here.
What location are you suggesting for |
Actually, now that I look at it, |
I agree, it shouldn't be in |
What about something like |
Sounds fine to me. In |
Yes, sibling to |
Okay, great! @ivenk Did you get that? You can continue with your |
@cjerdonek i got it, thanks ! I will fix everything mentioned here and create a new file for unpack_file_url() and required functions. |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
@ivenk This needs a rebase. Also, in your latest PR, it looks like all of the |
@cjerdonek thanks for the hint i think that happened during some refactoring from the ide. |
Okay, thanks for letting us know. Maybe we'll switch back to proceeding on some things that we were holding off on for this, or else take this (or parts of this) up to help ease the burden. |
Fixes #6861
Only code refactoring was done.
Moved download::unpack_file_url() and misc::unzip_file(), misc::untar_file(), misc::unpack_file() to a new module. The new module is named unpacking and is located in pip/_internal/utils/
I ran all the tests and locally everything works.