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

Commit

Permalink
Merge branch 'drop-html2text'
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Mar 30, 2019
2 parents 7f687a3 + f497626 commit 8b7cc21
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
37 changes: 33 additions & 4 deletions dephell/controllers/conflict.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import re
from logging import getLogger

# external
from graphviz.backend import ExecutableNotFound
from html2text import html2text
from jinja2 import Environment, PackageLoader


logger = getLogger('dephell')
env = Environment(
loader=PackageLoader('dephell', 'templates'),
)


REPLACEMENTS = (
('</div>', '\n\n'),
('</ul>', '\n\n'),
('</ol>', '\n\n'),

('</li>', '\n'),
('</p>', '\n'),

('<ul>', '\n'),
('<ol>', '\n'),
('<li>', ' * '),
)
REX_BEGINING = re.compile(r'(\n[ \t]+)')


# https://github.com/dephell/dephell/issues/11
def html2text(text: str) -> str:
text = REX_BEGINING.sub('', text)
for tag, char in REPLACEMENTS:
text = text.replace(tag, char)
for tag, _ in REPLACEMENTS:
text = text.replace(tag.replace('/', ''), '')
while '\n\n\n' in text:
text = text.replace('\n\n\n', '\n\n')
return text.strip() + '\n'


def analize_conflict(resolver, suffix: str = '') -> str:
try:
resolver.graph.draw(suffix=suffix)
except ExecutableNotFound:
print('GraphViz is not installed yet.')
except ImportError as e:
logger.warning(e.args[0])

conflict = resolver.graph.conflict
if conflict is None:
Expand Down
11 changes: 7 additions & 4 deletions dephell/controllers/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from logging import getLogger
from typing import Optional

# external
from graphviz import Digraph

# app
from ..models.root import RootDependency

Expand Down Expand Up @@ -180,6 +177,9 @@ def get_parents(self, *deps, avoid: Optional[list] = None) -> dict:
return parents

def draw(self, path: str = '.dephell_report', suffix: str = '') -> None:
from graphviz import Digraph
from graphviz.backend import ExecutableNotFound

dot = Digraph(
name=self._roots[0].name + suffix,
directory=path,
Expand Down Expand Up @@ -208,7 +208,10 @@ def draw(self, path: str = '.dephell_report', suffix: str = '') -> None:
dot.edge(parent, dep.name, label=constraint)

# save files
dot.render()
try:
dot.render()
except ExecutableNotFound as e:
raise ImportError('GraphViz is not installed yet.') from e

# properties

Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ appdirs = "*"
attrs = "*"
cerberus = "*"
editorconfig = "*" # https://github.com/editorconfig/editorconfig-core-py
graphviz = "*"
html2text = "*"
jinja2 = "*"
m2r = "*"
packaging = "*"
Expand Down

0 comments on commit 8b7cc21

Please sign in to comment.