Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'less-deps'
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Mar 30, 2019
2 parents 8b7cc21 + c55db89 commit ef37c77
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
21 changes: 17 additions & 4 deletions dephell/converters/setuppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
# external
from dephell_specifier import RangeSpecifier
from packaging.requirements import Requirement
from yapf.yapflib.style import CreateGoogleStyle
from yapf.yapflib.yapf_api import FormatCode

# app
from ..controllers import DependencyMaker, Readme
from ..models import Author, EntryPoint, RootDependency
from ..utils import chdir
from .base import BaseConverter

try:
from yapf.yapflib.style import CreateGoogleStyle
from yapf.yapflib.yapf_api import FormatCode
except ImportError:
FormatCode = None
try:
from autopep8 import fix_code
except ImportError:
fix_code = None


TEMPLATE = """
# -*- coding: utf-8 -*-
Expand Down Expand Up @@ -175,7 +183,7 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
data = {package: sorted(paths) for package, paths in data.items()}
content.append(('package_data', data))

reqs_list = [self._format_req(req=req) for req in reqs]
reqs_list = [self._format_req(req=req) for req in reqs if not req.main_envs]
content.append(('install_requires', reqs_list))

extras = defaultdict(list)
Expand All @@ -195,7 +203,12 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
content = ',\n '.join('{}={!r}'.format(name, value) for name, value in content)
content = TEMPLATE.format(kwargs=content, readme=readme)

content, _changed = FormatCode(content, style_config=CreateGoogleStyle())
# beautify
if FormatCode is not None:
content, _changed = FormatCode(content, style_config=CreateGoogleStyle())
if fix_code is not None:
content = fix_code(content)

return content

# private methods
Expand Down
30 changes: 23 additions & 7 deletions dephell/repositories/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# external
import attr
import aiofiles
import requests
from aiohttp import ClientSession
from dephell_markers import Markers
Expand All @@ -23,6 +22,12 @@
from .base import Interface


try:
import aiofiles
except ImportError:
aiofiles = None


def _process_url(url: str) -> str:
parsed = urlparse(url)
if parsed.path in ('', '/', '/simple', '/simple/'):
Expand Down Expand Up @@ -233,11 +238,22 @@ async def _download_and_parse(self, *, url: str, converter) -> Tuple[str, ...]:
response.status, response.reason, url,
))
path = Path(tmp) / url.rsplit('/', maxsplit=1)[-1]
async with aiofiles.open(str(path), mode='wb') as stream:
while True:
chunk = await response.content.read(1024)
if not chunk:
break
await stream.write(chunk)

# download file
if aiofiles is not None:
async with aiofiles.open(str(path), mode='wb') as stream:
while True:
chunk = await response.content.read(1024)
if not chunk:
break
await stream.write(chunk)
else:
with path.open(mode='wb') as stream:
while True:
chunk = await response.content.read(1024)
if not chunk:
break
stream.write(chunk)

root = converter.load(path)
return tuple(str(dep) for dep in root.dependencies)
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ dephell = "dephell.cli:entrypoint"

[tool.poetry.dependencies]
python = ">=3.5"
aiofiles = "*"
aiohttp = "*"
appdirs = "*"
attrs = "*"
Expand All @@ -85,7 +84,13 @@ pip = "*"
requests = "*"
tomlkit = "*"
tqdm = "*"
yapf = "*"

# optional
aiofiles = {optional = true}
autopep8 = {optional = true}
colorama = {optional = true}
graphviz = {optional = true}
yapf = {optional = true}

# dephell ecosystem
dephell_archive = "*" # https://github.com/dephell/dephell_archive
Expand All @@ -104,5 +109,6 @@ sphinx-rtd-theme = "*"
pygments-github-lexers = "*"

[tool.poetry.extras]
full = ["aiofiles", "autopep8", "colorama", "graphviz", "yapf"]
tests = ["pytest"]
docs = ["sphinx", "recommonmark", "sphinx-rtd-theme", "pygments-github-lexers"]

0 comments on commit ef37c77

Please sign in to comment.