1
0
Fork 0
forked from github/pelican

chore: Simplify boolean if expression (#2944)

This commit is contained in:
Yasser Tahiri 2023-10-28 21:06:24 +01:00 committed by GitHub
commit b812f2ad1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 24 deletions

View file

@ -183,7 +183,7 @@ def install(path, v=False, u=False):
exists = os.path.exists(theme_path) exists = os.path.exists(theme_path)
if exists and not u: if exists and not u:
err(path + ' : already exists') err(path + ' : already exists')
elif exists and u: elif exists:
remove(theme_name, v) remove(theme_name, v)
install(path, v) install(path, v)
else: else:
@ -245,15 +245,14 @@ def clean(v=False):
c = 0 c = 0
for path in os.listdir(_THEMES_PATH): for path in os.listdir(_THEMES_PATH):
path = os.path.join(_THEMES_PATH, path) path = os.path.join(_THEMES_PATH, path)
if os.path.islink(path): if os.path.islink(path) and is_broken_link(path):
if is_broken_link(path): if v:
if v: print('Removing {}'.format(path))
print('Removing {}'.format(path)) try:
try: os.remove(path)
os.remove(path) except OSError:
except OSError: print('Error: cannot remove {}'.format(path))
print('Error: cannot remove {}'.format(path)) else:
else: c += 1
c += 1
print("\nRemoved {} broken links".format(c)) print("\nRemoved {} broken links".format(c))

View file

@ -37,13 +37,12 @@ class Writer:
feed_title = context['SITENAME'] + ' - ' + feed_title feed_title = context['SITENAME'] + ' - ' + feed_title
else: else:
feed_title = context['SITENAME'] feed_title = context['SITENAME']
feed = feed_class( return feed_class(
title=Markup(feed_title).striptags(), title=Markup(feed_title).striptags(),
link=(self.site_url + '/'), link=(self.site_url + '/'),
feed_url=self.feed_url, feed_url=self.feed_url,
description=context.get('SITESUBTITLE', ''), description=context.get('SITESUBTITLE', ''),
subtitle=context.get('SITESUBTITLE', None)) subtitle=context.get('SITESUBTITLE', None))
return feed
def _add_item_to_the_feed(self, feed, item): def _add_item_to_the_feed(self, feed, item):
title = Markup(item.title).striptags() title = Markup(item.title).striptags()
@ -71,7 +70,7 @@ class Writer:
if description == content: if description == content:
description = None description = None
categories = list() categories = []
if hasattr(item, 'category'): if hasattr(item, 'category'):
categories.append(item.category) categories.append(item.category)
if hasattr(item, 'tags'): if hasattr(item, 'tags'):
@ -83,13 +82,17 @@ class Writer:
unique_id=get_tag_uri(link, item.date), unique_id=get_tag_uri(link, item.date),
description=description, description=description,
content=content, content=content,
categories=categories if categories else None, categories=categories or None,
author_name=getattr(item, 'author', ''), author_name=getattr(item, 'author', ''),
pubdate=set_date_tzinfo( pubdate=set_date_tzinfo(
item.date, self.settings.get('TIMEZONE', None)), item.date, self.settings.get('TIMEZONE', None)
),
updateddate=set_date_tzinfo( updateddate=set_date_tzinfo(
item.modified, self.settings.get('TIMEZONE', None) 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): def _open_w(self, filename, encoding, override=False):
"""Open a file to write some content to it. """Open a file to write some content to it.
@ -101,9 +104,8 @@ class Writer:
if override: if override:
raise RuntimeError('File %s is set to be overridden twice' raise RuntimeError('File %s is set to be overridden twice'
% filename) % filename)
else: logger.info('Skipping %s', filename)
logger.info('Skipping %s', filename) filename = os.devnull
filename = os.devnull
elif filename in self._written_files: elif filename in self._written_files:
if override: if override:
logger.info('Overwriting %s', filename) logger.info('Overwriting %s', filename)
@ -139,7 +141,7 @@ class Writer:
'SITEURL', path_to_url(get_relative_path(path))) 'SITEURL', path_to_url(get_relative_path(path)))
self.feed_domain = context.get('FEED_DOMAIN') 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) feed = self._create_new_feed(feed_type, feed_title, context)

View file

@ -8,7 +8,7 @@ PKG_NAME = "pelican"
PKG_PATH = Path(PKG_NAME) PKG_PATH = Path(PKG_NAME)
DOCS_PORT = os.environ.get("DOCS_PORT", 8000) DOCS_PORT = os.environ.get("DOCS_PORT", 8000)
BIN_DIR = "bin" if os.name != "nt" else "Scripts" 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) ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/virtualenvs")) VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/virtualenvs"))
VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME / PKG_NAME) 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) VENV_BIN = Path(VENV) / Path(BIN_DIR)
TOOLS = ["poetry", "pre-commit", "psutil"] TOOLS = ["poetry", "pre-commit", "psutil"]
POETRY = which("poetry") if which("poetry") else (VENV_BIN / "poetry") POETRY = which("poetry") or VENV_BIN / "poetry"
PRECOMMIT = which("pre-commit") if which("pre-commit") else (VENV_BIN / "pre-commit") PRECOMMIT = which("pre-commit") or VENV_BIN / "pre-commit"
@task @task