Remove cssutils dependency

- Remove everything related to cssutils
This commit is contained in:
duthades 2020-11-11 10:12:21 +05:30
parent 24f0de1aa6
commit 6acd40a383
12 changed files with 12 additions and 94 deletions

View File

@ -36,10 +36,6 @@ ignore_missing_imports = True
# https://bitbucket.org/birkenfeld/pygments-main/issues/1485/type-hints
ignore_missing_imports = True
[mypy-cssutils]
# Pretty much inactive currently
ignore_missing_imports = True
[mypy-pypeg2]
# Pretty much inactive currently
ignore_missing_imports = True

View File

@ -134,8 +134,6 @@ The following software and libraries are required to run qutebrowser:
The following libraries are optional:
* http://cthedot.de/cssutils/[cssutils] (for an improved `:download --mhtml`
with QtWebKit).
* On Windows, https://pypi.python.org/pypi/colorama/[colorama] for colored log
output.
* http://asciidoc.org/[asciidoc] to generate the documentation for the `:help`

View File

@ -6,7 +6,6 @@ cffi==1.14.3
chardet==3.0.4
colorama==0.4.4
cryptography==3.2.1
cssutils==1.0.2
github3.py==1.3.0
hunter==3.3.1
idna==2.10

View File

@ -1,5 +1,4 @@
hunter
cssutils
pympler
github3.py
bump2version

View File

@ -3,5 +3,4 @@ Pygments
pyPEG2
PyYAML
colorama
cssutils
attrs

View File

@ -27,7 +27,6 @@ git+https://github.com/pallets/werkzeug.git
## qutebrowser dependencies
git+https://github.com/tartley/colorama.git
hg+https://bitbucket.org/cthedot/cssutils
git+https://github.com/pallets/jinja.git
git+https://github.com/pallets/markupsafe.git
hg+http://bitbucket.org/birkenfeld/pygments-main

View File

@ -62,7 +62,7 @@ _CSS_URL_PATTERNS = [re.compile(x) for x in [
]]
def _get_css_imports_regex(data):
def _get_css_imports(data):
"""Return all assets that are referenced in the given CSS document.
The returned URLs are relative to the stylesheet's URL.
@ -79,55 +79,6 @@ def _get_css_imports_regex(data):
return urls
def _get_css_imports_cssutils(data, inline=False):
"""Return all assets that are referenced in the given CSS document.
The returned URLs are relative to the stylesheet's URL.
Args:
data: The content of the stylesheet to scan as string.
inline: True if the argument is an inline HTML style attribute.
"""
try:
import cssutils
except ImportError:
return None
# We don't care about invalid CSS data, this will only litter the log
# output with CSS errors
parser = cssutils.CSSParser(loglevel=100,
fetcher=lambda url: (None, ""), validate=False)
if not inline:
sheet = parser.parseString(data)
return list(cssutils.getUrls(sheet))
else:
urls = []
declaration = parser.parseStyle(data)
# prop = background, color, margin, ...
for prop in declaration:
# value = red, 10px, url(foobar), ...
for value in prop.propertyValue:
if isinstance(value, cssutils.css.URIValue):
if value.uri:
urls.append(value.uri)
return urls
def _get_css_imports(data, inline=False):
"""Return all assets that are referenced in the given CSS document.
The returned URLs are relative to the stylesheet's URL.
Args:
data: The content of the stylesheet to scan as string.
inline: True if the argument is an inline HTML style attribute.
"""
imports = _get_css_imports_cssutils(data, inline)
if imports is None:
imports = _get_css_imports_regex(data)
return imports
def _check_rel(element):
"""Return true if the element's rel attribute fits our criteria.
@ -328,7 +279,7 @@ class _Downloader:
for element in web_frame.findAllElements('[style]'):
element = webkitelem.WebKitElement(element, tab=self.tab)
style = element['style']
for element_url in _get_css_imports(style, inline=True):
for element_url in _get_css_imports(style):
self._fetch_url(web_url.resolved(QUrl(element_url)))
# Shortcut if no assets need to be downloaded, otherwise the file would

View File

@ -263,7 +263,6 @@ def _module_versions() -> Sequence[str]:
('jinja2', ['__version__']),
('pygments', ['__version__']),
('yaml', ['__version__']),
('cssutils', ['__version__']),
('attr', ['__version__']),
('PyQt5.QtWebEngineWidgets', []),
('PyQt5.QtWebEngine', ['PYQT_WEBENGINE_VERSION_STR']),

View File

@ -2,7 +2,6 @@
attrs==20.3.0
colorama==0.4.4
cssutils==1.0.2
Jinja2==2.11.2
MarkupSafe==1.1.1
Pygments==2.7.2

View File

@ -164,7 +164,6 @@ CHANGELOG_URLS = {
'yamllint': 'https://github.com/adrienverge/yamllint/blob/master/CHANGELOG.rst',
'pathspec': 'https://github.com/cpburnz/python-path-specification/blob/master/CHANGES.rst',
'filelock': 'https://github.com/benediktschmitt/py-filelock/commits/master',
'cssutils': 'https://pythonhosted.org/cssutils/CHANGELOG.html',
'github3.py': 'https://github3py.readthedocs.io/en/master/release-notes/index.html',
'manhole': 'https://github3py.readthedocs.io/en/master/release-notes/index.html',
'pycparser': 'https://github.com/eliben/pycparser/blob/master/CHANGES',

View File

@ -28,12 +28,6 @@ import pytest
mhtml = pytest.importorskip('qutebrowser.browser.webkit.mhtml')
try:
import cssutils
except ImportError:
cssutils = None
@pytest.fixture(autouse=True)
def patch_uuid(monkeypatch):
monkeypatch.setattr(uuid, "uuid4", lambda: "UUID")
@ -255,34 +249,25 @@ def test_empty_content_type(checker):
""")
@pytest.mark.parametrize('has_cssutils', [
pytest.param(True, marks=pytest.mark.skipif(
cssutils is None, reason="requires cssutils"), id='with_cssutils'),
pytest.param(False, id='no_cssutils'),
])
@pytest.mark.parametrize('inline, style, expected_urls', [
pytest.param(False, "@import 'default.css'", ['default.css'],
@pytest.mark.parametrize('style, expected_urls', [
pytest.param("@import 'default.css'", ['default.css'],
id='import with apostrophe'),
pytest.param(False, '@import "default.css"', ['default.css'],
pytest.param('@import "default.css"', ['default.css'],
id='import with quote'),
pytest.param(False, "@import \t 'tabbed.css'", ['tabbed.css'],
pytest.param("@import \t 'tabbed.css'", ['tabbed.css'],
id='import with tab'),
pytest.param(False, "@import url('default.css')", ['default.css'],
pytest.param("@import url('default.css')", ['default.css'],
id='import with url()'),
pytest.param(False, """body {
pytest.param("""body {
background: url("/bg-img.png")
}""", ['/bg-img.png'], id='background with body'),
pytest.param(True, 'background: url(folder/file.png) no-repeat',
pytest.param('background: url(folder/file.png) no-repeat',
['folder/file.png'], id='background'),
pytest.param(True, 'content: url()', [], id='content'),
pytest.param('content: url()', [], id='content'),
])
def test_css_url_scanner(monkeypatch, has_cssutils, inline, style,
expected_urls):
if not has_cssutils:
monkeypatch.setattr(mhtml, '_get_css_imports_cssutils',
lambda data, inline=False: None)
def test_css_url_scanner(monkeypatch, style, expected_urls):
expected_urls.sort()
urls = mhtml._get_css_imports(style, inline=inline)
urls = mhtml._get_css_imports(style)
urls.sort()
assert urls == expected_urls

View File

@ -561,7 +561,6 @@ class ImportFake:
('jinja2', True),
('pygments', True),
('yaml', True),
('cssutils', True),
('attr', True),
('PyQt5.QtWebEngineWidgets', True),
('PyQt5.QtWebEngine', True),
@ -637,7 +636,6 @@ class TestModuleVersions:
@pytest.mark.parametrize('module, idx, expected', [
('colorama', 1, 'colorama: no'),
('cssutils', 6, 'cssutils: no'),
])
def test_missing_module(self, module, idx, expected, import_fake):
"""Test with a module missing.
@ -681,7 +679,6 @@ class TestModuleVersions:
('jinja2', True),
('pygments', True),
('yaml', True),
('cssutils', True),
('attr', True),
])
def test_existing_attributes(self, name, has_version):
@ -694,8 +691,6 @@ class TestModuleVersions:
name: The name of the module to check.
has_version: Whether a __version__ attribute is expected.
"""
if name == 'cssutils':
pytest.importorskip(name)
module = importlib.import_module(name)
assert hasattr(module, '__version__') == has_version