forked from github/pelican
chore: Simplify boolean if expression ✨ (#2944)
This commit is contained in:
parent
e14f20bb99
commit
b812f2ad1c
3 changed files with 25 additions and 24 deletions
|
|
@ -183,7 +183,7 @@ def install(path, v=False, u=False):
|
|||
exists = os.path.exists(theme_path)
|
||||
if exists and not u:
|
||||
err(path + ' : already exists')
|
||||
elif exists and u:
|
||||
elif exists:
|
||||
remove(theme_name, v)
|
||||
install(path, v)
|
||||
else:
|
||||
|
|
@ -245,15 +245,14 @@ def clean(v=False):
|
|||
c = 0
|
||||
for path in os.listdir(_THEMES_PATH):
|
||||
path = os.path.join(_THEMES_PATH, path)
|
||||
if os.path.islink(path):
|
||||
if is_broken_link(path):
|
||||
if v:
|
||||
print('Removing {}'.format(path))
|
||||
try:
|
||||
os.remove(path)
|
||||
except OSError:
|
||||
print('Error: cannot remove {}'.format(path))
|
||||
else:
|
||||
c += 1
|
||||
if os.path.islink(path) and is_broken_link(path):
|
||||
if v:
|
||||
print('Removing {}'.format(path))
|
||||
try:
|
||||
os.remove(path)
|
||||
except OSError:
|
||||
print('Error: cannot remove {}'.format(path))
|
||||
else:
|
||||
c += 1
|
||||
|
||||
print("\nRemoved {} broken links".format(c))
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ class Writer:
|
|||
feed_title = context['SITENAME'] + ' - ' + feed_title
|
||||
else:
|
||||
feed_title = context['SITENAME']
|
||||
feed = feed_class(
|
||||
return feed_class(
|
||||
title=Markup(feed_title).striptags(),
|
||||
link=(self.site_url + '/'),
|
||||
feed_url=self.feed_url,
|
||||
description=context.get('SITESUBTITLE', ''),
|
||||
subtitle=context.get('SITESUBTITLE', None))
|
||||
return feed
|
||||
|
||||
def _add_item_to_the_feed(self, feed, item):
|
||||
title = Markup(item.title).striptags()
|
||||
|
|
@ -71,7 +70,7 @@ class Writer:
|
|||
if description == content:
|
||||
description = None
|
||||
|
||||
categories = list()
|
||||
categories = []
|
||||
if hasattr(item, 'category'):
|
||||
categories.append(item.category)
|
||||
if hasattr(item, 'tags'):
|
||||
|
|
@ -83,13 +82,17 @@ class Writer:
|
|||
unique_id=get_tag_uri(link, item.date),
|
||||
description=description,
|
||||
content=content,
|
||||
categories=categories if categories else None,
|
||||
categories=categories or None,
|
||||
author_name=getattr(item, 'author', ''),
|
||||
pubdate=set_date_tzinfo(
|
||||
item.date, self.settings.get('TIMEZONE', None)),
|
||||
item.date, self.settings.get('TIMEZONE', None)
|
||||
),
|
||||
updateddate=set_date_tzinfo(
|
||||
item.modified, self.settings.get('TIMEZONE', None)
|
||||
) if hasattr(item, 'modified') else None)
|
||||
)
|
||||
if hasattr(item, 'modified')
|
||||
else None,
|
||||
)
|
||||
|
||||
def _open_w(self, filename, encoding, override=False):
|
||||
"""Open a file to write some content to it.
|
||||
|
|
@ -101,9 +104,8 @@ class Writer:
|
|||
if override:
|
||||
raise RuntimeError('File %s is set to be overridden twice'
|
||||
% filename)
|
||||
else:
|
||||
logger.info('Skipping %s', filename)
|
||||
filename = os.devnull
|
||||
logger.info('Skipping %s', filename)
|
||||
filename = os.devnull
|
||||
elif filename in self._written_files:
|
||||
if override:
|
||||
logger.info('Overwriting %s', filename)
|
||||
|
|
@ -139,7 +141,7 @@ class Writer:
|
|||
'SITEURL', path_to_url(get_relative_path(path)))
|
||||
|
||||
self.feed_domain = context.get('FEED_DOMAIN')
|
||||
self.feed_url = self.urljoiner(self.feed_domain, url if url else path)
|
||||
self.feed_url = self.urljoiner(self.feed_domain, url or path)
|
||||
|
||||
feed = self._create_new_feed(feed_type, feed_title, context)
|
||||
|
||||
|
|
|
|||
6
tasks.py
6
tasks.py
|
|
@ -8,7 +8,7 @@ PKG_NAME = "pelican"
|
|||
PKG_PATH = Path(PKG_NAME)
|
||||
DOCS_PORT = os.environ.get("DOCS_PORT", 8000)
|
||||
BIN_DIR = "bin" if os.name != "nt" else "Scripts"
|
||||
PTY = True if os.name != "nt" else False
|
||||
PTY = os.name != "nt"
|
||||
ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
|
||||
VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/virtualenvs"))
|
||||
VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME / PKG_NAME)
|
||||
|
|
@ -16,8 +16,8 @@ VENV = str(VENV_PATH.expanduser())
|
|||
VENV_BIN = Path(VENV) / Path(BIN_DIR)
|
||||
|
||||
TOOLS = ["poetry", "pre-commit", "psutil"]
|
||||
POETRY = which("poetry") if which("poetry") else (VENV_BIN / "poetry")
|
||||
PRECOMMIT = which("pre-commit") if which("pre-commit") else (VENV_BIN / "pre-commit")
|
||||
POETRY = which("poetry") or VENV_BIN / "poetry"
|
||||
PRECOMMIT = which("pre-commit") or VENV_BIN / "pre-commit"
|
||||
|
||||
|
||||
@task
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue