Skip to content

Commit

Permalink
Add black, isort and flake8 for dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoriniere committed Jul 5, 2022
1 parent 6796043 commit a20422b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
!requirements-dev.txt
!requirements-docs.txt
!setup.py
!setup.cfg
__pycache__/
*.py[cod]
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
tests:
nosetests --with-coverage --cover-package=chopper

styles:
isort chopper
black .
flake8 --config setup.cfg

styles.check:
black . --check
isort --ws jurismarches --check-only
flake8 --config setup.cfg
12 changes: 6 additions & 6 deletions chopper/css/extractor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import re
import cssselect
from urllib.parse import urljoin
from tinycss.css21 import RuleSet, ImportRule, MediaRule, PageRule

import cssselect
from tinycss.css21 import ImportRule, MediaRule, PageRule, RuleSet
from tinycss.parsing import split_on_comma, strip_whitespace

from ..mixins import TreeBuilderMixin
from .parser import CSSParser
from .rules import FontFaceRule
from .translator import XpathTranslator

from ..mixins import TreeBuilderMixin


class CSSExtractor(TreeBuilderMixin):
"""
Expand Down Expand Up @@ -103,7 +103,7 @@ def _clean_css(self):
if cleaned_rule is not None:
css_rules.append(cleaned_rule)

except:
except Exception:
# On error, assume the rule matched the tree
css_rules.append(rule)

Expand Down Expand Up @@ -165,7 +165,7 @@ def _token_list_matches_tree(self, token_list):
return bool(
self.tree.xpath(
self.xpath_translator.selector_to_xpath(parsed_selector)))
except:
except Exception:
# On error, assume the selector matches the tree
return True

Expand Down
5 changes: 3 additions & 2 deletions chopper/html/extractor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import re
from lxml import html
from itertools import chain
from lxml.etree import strip_attributes
from urllib.parse import urljoin

from lxml import html
from lxml.etree import strip_attributes

from ..mixins import TreeBuilderMixin


Expand Down
3 changes: 1 addition & 2 deletions chopper/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from .extractor import Extractor


TEST_HTML = """
<html>
<head>
Expand Down Expand Up @@ -53,7 +52,7 @@ def __init__(self, *args, **kwargs):
self.assertIsNone = lambda v: self.assertEqual(v, None)

def format_output(self, output):
return ''.join(l.strip() for l in output.splitlines())
return ''.join(line.strip() for line in output.splitlines())

def test_no_rules(self):
"""
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
# Dev requirements
Sphinx==1.2.2
nose==1.3.3
black
isort
flake8
22 changes: 22 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
max-complexity = 11
max-line-length = 99
# ignore = E203,W503,W504
exclude =
.git,
docs,
**/site-packages/**
.venv
filename =
# complete
**.py
per-file-ignores =
chopper/tests.py:E501

[isort]
combine_as_imports = true
multi_line_output = 3
include_trailing_comma = true
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
line_length=99
profile=black
42 changes: 21 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
from chopper import __version__


with open('README.rst', 'r') as f:
with open("README.rst", "r") as f:
long_description = f.read()

setup(
name='chopper',
name="chopper",
version=__version__,
description="Lib to extract html elements by preserving ancestors and cleaning CSS",
long_description=long_description,
author='Jurismarches',
author_email='contact@jurismarches.com',
url='https://github.com/jurismarches/chopper',
author="Jurismarches",
author_email="contact@jurismarches.com",
url="https://github.com/jurismarches/chopper",
packages=[
'chopper',
'chopper.css',
'chopper.html',
"chopper",
"chopper.css",
"chopper.html",
],
install_requires=[
'cssselect==1.1.0',
'tinycss==0.4',
'lxml==4.9.1',
"cssselect==1.1.0",
"tinycss==0.4",
"lxml==4.9.1",
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6'
'Programming Language :: Python :: 3.7'
'Programming Language :: Python :: 3.8'
'Programming Language :: Python :: 3.9'
'Programming Language :: Python :: 3.10'
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6"
"Programming Language :: Python :: 3.7"
"Programming Language :: Python :: 3.8"
"Programming Language :: Python :: 3.9"
"Programming Language :: Python :: 3.10",
],
test_suite='chopper.tests'
test_suite="chopper.tests",
)

0 comments on commit a20422b

Please sign in to comment.