Fix flake8 warnings for lektor_project_data.py
This commit is contained in:
parent
41e6091e0d
commit
850e52f598
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import cgi
|
||||
import pkg_resources
|
||||
|
||||
import readme_renderer.markdown
|
||||
import readme_renderer.rst
|
||||
|
@ -17,6 +16,7 @@ _RENDERERS = {
|
|||
'text/markdown': readme_renderer.markdown,
|
||||
}
|
||||
|
||||
|
||||
class ProjectDataPlugin(Plugin):
|
||||
name = 'Project Data'
|
||||
description = u'Retrieve project information from PyPI.'
|
||||
|
@ -24,27 +24,33 @@ class ProjectDataPlugin(Plugin):
|
|||
data = {}
|
||||
|
||||
def render(self, value, content_type=None):
|
||||
"""Taken from https://github.com/pypa/warehouse/blob/master/warehouse/filters.py
|
||||
to ensure compliance and not reinvent the wheel. We don't want to be creative here.
|
||||
"""Render project description.
|
||||
|
||||
This is taken from
|
||||
https://github.com/pypa/warehouse/blob/master/warehouse/filters.py
|
||||
to ensure compliance and not reinvent the wheel. We don't
|
||||
want to be creative here.
|
||||
|
||||
"""
|
||||
content_type, parameters = cgi.parse_header(content_type or '')
|
||||
|
||||
# Get the appropriate renderer
|
||||
renderer = _RENDERERS.get(content_type, readme_renderer.txt)
|
||||
|
||||
# Actually render the given value, this will not only render the value, but
|
||||
# also ensure that it's had any disallowed markup removed.
|
||||
# Actually render the given value, this will not only render
|
||||
# the value, but also ensure that it's had any disallowed
|
||||
# markup removed.
|
||||
rendered = renderer.render(value, **parameters)
|
||||
|
||||
# If the content was not rendered, we'll render as plaintext instead. The
|
||||
# reason it's necessary to do this instead of just accepting plaintext is
|
||||
# that readme_renderer will deal with sanitizing the content.
|
||||
# If the content was not rendered, we'll render as plaintext
|
||||
# instead. The reason it's necessary to do this instead of
|
||||
# just accepting plaintext is that readme_renderer will deal
|
||||
# with sanitizing the content.
|
||||
if rendered is None:
|
||||
rendered = readme_renderer.txt.render(value)
|
||||
|
||||
return rendered
|
||||
|
||||
|
||||
def package_data(self, name, entry_point=None):
|
||||
if not entry_point:
|
||||
entry_point = 'https://pypi.org/pypi'
|
||||
|
@ -64,7 +70,7 @@ class ProjectDataPlugin(Plugin):
|
|||
self.data['description'] = self.render(
|
||||
self.data['description'], self.data['description_content_type'])
|
||||
if not self.data.get('home_page'):
|
||||
self.data['home_page'] = 'https://pypi.org/project/{}/'.format(name)
|
||||
self.data['home_page'] = f'https://pypi.org/project/{name}/'
|
||||
|
||||
def github_data(self, owner=None, repo=None):
|
||||
url = 'https://api.github.com/repos/{}/{}'.format(owner, repo)
|
||||
|
|
Loading…
Reference in New Issue