Skip to content

Commit 3a37fb7

Browse files
committed
Fix #2888 -- Apply ruff and pyupgrade to templates
1 parent 903ce3c commit 3a37fb7

File tree

3 files changed

+91
-64
lines changed

3 files changed

+91
-64
lines changed
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
AUTHOR = {{author}}
22
SITENAME = {{sitename}}
3-
SITEURL = ''
3+
SITEURL = ""
44

5-
PATH = 'content'
5+
PATH = "content"
66

77
TIMEZONE = {{timezone}}
88

@@ -16,16 +16,20 @@ AUTHOR_FEED_ATOM = None
1616
AUTHOR_FEED_RSS = None
1717

1818
# Blogroll
19-
LINKS = (('Pelican', 'https://getpelican.com/'),
20-
('Python.org', 'https://www.python.org/'),
21-
('Jinja2', 'https://palletsprojects.com/p/jinja/'),
22-
('You can modify those links in your config file', '#'),)
19+
LINKS = (
20+
("Pelican", "https://getpelican.com/"),
21+
("Python.org", "https://www.python.org/"),
22+
("Jinja2", "https://palletsprojects.com/p/jinja/"),
23+
("You can modify those links in your config file", "#"),
24+
)
2325

2426
# Social widget
25-
SOCIAL = (('You can add links in your config file', '#'),
26-
('Another social link', '#'),)
27+
SOCIAL = (
28+
("You can add links in your config file", "#"),
29+
("Another social link", "#"),
30+
)
2731

2832
DEFAULT_PAGINATION = {{default_pagination}}
2933

3034
# Uncomment following line if you want document-relative URLs when developing
31-
#RELATIVE_URLS = True
35+
# RELATIVE_URLS = True

pelican/tools/templates/publishconf.py.jinja2

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33

44
import os
55
import sys
6+
67
sys.path.append(os.curdir)
78
from pelicanconf import *
89

910
# If your site is available via HTTPS, make sure SITEURL begins with https://
10-
SITEURL = '{{siteurl}}'
11+
SITEURL = "{{siteurl}}"
1112
RELATIVE_URLS = False
1213

13-
FEED_ALL_ATOM = 'feeds/all.atom.xml'
14-
CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'
14+
FEED_ALL_ATOM = "feeds/all.atom.xml"
15+
CATEGORY_FEED_ATOM = "feeds/{slug}.atom.xml"
1516

1617
DELETE_OUTPUT_DIRECTORY = True
1718

1819
# Following items are often useful when publishing
1920

20-
#DISQUS_SITENAME = ""
21-
#GOOGLE_ANALYTICS = ""
21+
# DISQUS_SITENAME = ""
22+
# GOOGLE_ANALYTICS = ""
Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import os
42
import shlex
53
import shutil
@@ -14,61 +12,66 @@ from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
1412
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
1513

1614
OPEN_BROWSER_ON_SERVE = True
17-
SETTINGS_FILE_BASE = 'pelicanconf.py'
15+
SETTINGS_FILE_BASE = "pelicanconf.py"
1816
SETTINGS = {}
1917
SETTINGS.update(DEFAULT_CONFIG)
2018
LOCAL_SETTINGS = get_settings_from_file(SETTINGS_FILE_BASE)
2119
SETTINGS.update(LOCAL_SETTINGS)
2220

2321
CONFIG = {
24-
'settings_base': SETTINGS_FILE_BASE,
25-
'settings_publish': 'publishconf.py',
22+
"settings_base": SETTINGS_FILE_BASE,
23+
"settings_publish": "publishconf.py",
2624
# Output path. Can be absolute or relative to tasks.py. Default: 'output'
27-
'deploy_path': SETTINGS['OUTPUT_PATH'],
25+
"deploy_path": SETTINGS["OUTPUT_PATH"],
2826
{% if ssh %}
2927
# Remote server configuration
30-
'ssh_user': '{{ssh_user}}',
31-
'ssh_host': '{{ssh_host}}',
32-
'ssh_port': '{{ssh_port}}',
33-
'ssh_path': '{{ssh_target_dir}}',
28+
"ssh_user": "{{ssh_user}}",
29+
"ssh_host": "{{ssh_host}}",
30+
"ssh_port": "{{ssh_port}}",
31+
"ssh_path": "{{ssh_target_dir}}",
3432
{% endif %}
3533
{% if cloudfiles %}
3634
# Rackspace Cloud Files configuration settings
37-
'cloudfiles_username': '{{cloudfiles_username}}',
38-
'cloudfiles_api_key': '{{cloudfiles_api_key}}',
39-
'cloudfiles_container': '{{cloudfiles_container}}',
35+
"cloudfiles_username": "{{cloudfiles_username}}",
36+
"cloudfiles_api_key": "{{cloudfiles_api_key}}",
37+
"cloudfiles_container": "{{cloudfiles_container}}",
4038
{% endif %}
4139
{% if github %}
4240
# Github Pages configuration
43-
'github_pages_branch': '{{github_pages_branch}}',
44-
'commit_message': "'Publish site on {}'".format(datetime.date.today().isoformat()),
41+
"github_pages_branch": "{{github_pages_branch}}",
42+
"commit_message": f"'Publish site on {datetime.date.today().isoformat()}'",
4543
{% endif %}
4644
# Host and port for `serve`
47-
'host': 'localhost',
48-
'port': 8000,
45+
"host": "localhost",
46+
"port": 8000,
4947
}
5048

49+
5150
@task
5251
def clean(c):
5352
"""Remove generated files"""
54-
if os.path.isdir(CONFIG['deploy_path']):
55-
shutil.rmtree(CONFIG['deploy_path'])
56-
os.makedirs(CONFIG['deploy_path'])
53+
if os.path.isdir(CONFIG["deploy_path"]):
54+
shutil.rmtree(CONFIG["deploy_path"])
55+
os.makedirs(CONFIG["deploy_path"])
56+
5757

5858
@task
5959
def build(c):
6060
"""Build local version of site"""
61-
pelican_run('-s {settings_base}'.format(**CONFIG))
61+
pelican_run("-s {settings_base}".format(**CONFIG))
62+
6263

6364
@task
6465
def rebuild(c):
6566
"""`build` with the delete switch"""
66-
pelican_run('-d -s {settings_base}'.format(**CONFIG))
67+
pelican_run("-d -s {settings_base}".format(**CONFIG))
68+
6769

6870
@task
6971
def regenerate(c):
7072
"""Automatically regenerate site upon file modification"""
71-
pelican_run('-r -s {settings_base}'.format(**CONFIG))
73+
pelican_run("-r -s {settings_base}".format(**CONFIG))
74+
7275

7376
@task
7477
def serve(c):
@@ -78,54 +81,59 @@ def serve(c):
7881
allow_reuse_address = True
7982

8083
server = AddressReuseTCPServer(
81-
CONFIG['deploy_path'],
82-
(CONFIG['host'], CONFIG['port']),
83-
ComplexHTTPRequestHandler)
84+
CONFIG["deploy_path"],
85+
(CONFIG["host"], CONFIG["port"]),
86+
ComplexHTTPRequestHandler,
87+
)
8488

8589
if OPEN_BROWSER_ON_SERVE:
8690
# Open site in default browser
8791
import webbrowser
92+
8893
webbrowser.open("http://{host}:{port}".format(**CONFIG))
8994

90-
sys.stderr.write('Serving at {host}:{port} ...\n'.format(**CONFIG))
95+
sys.stderr.write("Serving at {host}:{port} ...\n".format(**CONFIG))
9196
server.serve_forever()
9297

98+
9399
@task
94100
def reserve(c):
95101
"""`build`, then `serve`"""
96102
build(c)
97103
serve(c)
98104

105+
99106
@task
100107
def preview(c):
101108
"""Build production version of site"""
102-
pelican_run('-s {settings_publish}'.format(**CONFIG))
109+
pelican_run("-s {settings_publish}".format(**CONFIG))
110+
103111

104112
@task
105113
def livereload(c):
106114
"""Automatically reload browser tab upon file modification."""
107115
from livereload import Server
108116

109117
def cached_build():
110-
cmd = '-s {settings_base} -e CACHE_CONTENT=true LOAD_CONTENT_CACHE=true'
118+
cmd = "-s {settings_base} -e CACHE_CONTENT=true LOAD_CONTENT_CACHE=true"
111119
pelican_run(cmd.format(**CONFIG))
112120

113121
cached_build()
114122
server = Server()
115-
theme_path = SETTINGS['THEME']
123+
theme_path = SETTINGS["THEME"]
116124
watched_globs = [
117-
CONFIG['settings_base'],
118-
'{}/templates/**/*.html'.format(theme_path),
125+
CONFIG["settings_base"],
126+
f"{theme_path}/templates/**/*.html",
119127
]
120128

121-
content_file_extensions = ['.md', '.rst']
129+
content_file_extensions = [".md", ".rst"]
122130
for extension in content_file_extensions:
123-
content_glob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
131+
content_glob = "{}/**/*{}".format(SETTINGS["PATH"], extension)
124132
watched_globs.append(content_glob)
125133

126-
static_file_extensions = ['.css', '.js']
134+
static_file_extensions = [".css", ".js"]
127135
for extension in static_file_extensions:
128-
static_file_glob = '{0}/static/**/*{1}'.format(theme_path, extension)
136+
static_file_glob = f"{theme_path}/static/**/*{extension}"
129137
watched_globs.append(static_file_glob)
130138

131139
for glob in watched_globs:
@@ -134,43 +142,57 @@ def livereload(c):
134142
if OPEN_BROWSER_ON_SERVE:
135143
# Open site in default browser
136144
import webbrowser
145+
137146
webbrowser.open("http://{host}:{port}".format(**CONFIG))
138147

139-
server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path'])
148+
server.serve(host=CONFIG["host"], port=CONFIG["port"], root=CONFIG["deploy_path"])
149+
140150

141151
{% if cloudfiles %}
142152
@task
143153
def cf_upload(c):
144154
"""Publish to Rackspace Cloud Files"""
145155
rebuild(c)
146-
with cd(CONFIG['deploy_path']):
147-
c.run('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
148-
'-U {cloudfiles_username} '
149-
'-K {cloudfiles_api_key} '
150-
'upload -c {cloudfiles_container} .'.format(**CONFIG))
156+
with cd(CONFIG["deploy_path"]):
157+
c.run(
158+
"swift -v -A https://auth.api.rackspacecloud.com/v1.0 "
159+
"-U {cloudfiles_username} "
160+
"-K {cloudfiles_api_key} "
161+
"upload -c {cloudfiles_container} .".format(**CONFIG)
162+
)
163+
164+
151165
{% endif %}
152166

167+
153168
@task
154169
def publish(c):
155170
"""Publish to production via rsync"""
156-
pelican_run('-s {settings_publish}'.format(**CONFIG))
171+
pelican_run("-s {settings_publish}".format(**CONFIG))
157172
c.run(
158173
'rsync --delete --exclude ".DS_Store" -pthrvz -c '
159174
'-e "ssh -p {ssh_port}" '
160-
'{} {ssh_user}@{ssh_host}:{ssh_path}'.format(
161-
CONFIG['deploy_path'].rstrip('/') + '/',
162-
**CONFIG))
175+
"{} {ssh_user}@{ssh_host}:{ssh_path}".format(
176+
CONFIG["deploy_path"].rstrip("/") + "/", **CONFIG
177+
)
178+
)
179+
163180

164181
{% if github %}
165182
@task
166183
def gh_pages(c):
167184
"""Publish to GitHub Pages"""
168185
preview(c)
169-
c.run('ghp-import -b {github_pages_branch} '
170-
'-m {commit_message} '
171-
'{deploy_path} -p'.format(**CONFIG))
186+
c.run(
187+
"ghp-import -b {github_pages_branch} "
188+
"-m {commit_message} "
189+
"{deploy_path} -p".format(**CONFIG)
190+
)
191+
192+
172193
{% endif %}
173194

195+
174196
def pelican_run(cmd):
175-
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
197+
cmd += " " + program.core.remainder # allows to pass-through args to pelican
176198
pelican_main(shlex.split(cmd))

0 commit comments

Comments
 (0)