Skip to content

Commit f9e8632

Browse files
Thierry Chappuisfreezed
authored andcommitted
Removed f-strings to make invoke calls compatible with python 3.5
1 parent 5ed3687 commit f9e8632

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

tasks.py

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,62 @@
33
import os
44
import shutil
55
import sys
6-
import datetime
76
from pathlib import Path
87

98
from invoke import task
10-
from invoke.util import cd
119
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
1210

13-
BASEDIR = (Path(__file__) / '..').resolve()
14-
INPUTDIR = BASEDIR / 'content'
15-
OUTPUTDIR = BASEDIR / 'output'
16-
CONFFILE = BASEDIR / 'pelicanconf.py'
17-
PUBLISHCONF = BASEDIR / 'publishconf.py'
18-
19-
PORT = 8000
20-
21-
PELICANOPTS = '--fatal=warnings'
22-
11+
CONFIG = {}
12+
CONFIG['basedir'] = (Path(__file__) / '..').resolve()
13+
CONFIG['inputdir'] = CONFIG['basedir'] / 'content'
14+
CONFIG['outputdir'] = CONFIG['basedir'] / 'output'
15+
CONFIG['conffile'] = CONFIG['basedir'] / 'pelicanconf.py'
16+
CONFIG['publishconf'] = CONFIG['basedir'] / 'publishconf.py'
17+
CONFIG['opts'] = '--fatal=warnings'
18+
CONFIG['github'] = os.getenv('GITHUB_TOKEN')
19+
CONFIG['port'] = 8000
2320

2421
@task
2522
def clean(c):
2623
"""Remove generated files"""
27-
if OUTPUTDIR.is_dir():
28-
shutil.rmtree(OUTPUTDIR)
29-
OUTPUTDIR.mkdir(parents=True, exist_ok=True)
24+
if CONFIG['outputdir'].is_dir():
25+
shutil.rmtree(CONFIG['outputdir'])
26+
CONFIG['outputdir'].mkdir(parents=True, exist_ok=True)
3027

3128
@task
3229
def build(c):
3330
"""Builds the local Pelican blog"""
3431
c.run('echo "Building your Pelican website"')
35-
c.run(f'pelican {INPUTDIR} -o {OUTPUTDIR} -s {CONFFILE} {PELICANOPTS}')
32+
c.run('pelican {inputdir} -o {outputdir} -s {conffile} {opts}'
33+
.format(**CONFIG)
34+
)
35+
36+
@task
37+
def html(c):
38+
"""Builds the local Pelican blog"""
39+
build(c)
3640

3741
@task
3842
def rebuild(c):
39-
"""`build` with the delete switch"""
43+
"""Builds with the delete switch"""
4044
c.run('echo "Re-building your Pelican website"')
41-
c.run(f'pelican -d -s {CONFFILE} {PELICANOPTS}')
45+
c.run('pelican -d -s {conffile} {opts}'.format(**CONFIG))
4246

4347
@task
4448
def publish(c):
4549
"""Builds the Pelican blog with deployment settings"""
4650
c.run('echo "Publishing your Pelican website"')
47-
c.run(f'pelican {INPUTDIR} -o {OUTPUTDIR} -s {PUBLISHCONF} {PELICANOPTS}')
51+
c.run('pelican {inputdir} -o {outputdir} -s {publishconf} {opts}'
52+
.format(**CONFIG)
53+
)
4854

4955
@task
5056
def autoreload(c):
5157
"""Starts the autoreload server to help during writing of blog articles"""
5258
c.run('echo "Running autoreload server. Press CTRL+C to stop"')
53-
c.run(f'pelican -r {INPUTDIR} -o {OUTPUTDIR} -s {CONFFILE} {PELICANOPTS}')
59+
c.run('pelican -r {inputdir} -o {outputdir} -s {conffile} {opts}'
60+
.format(**CONFIG)
61+
)
5462

5563
@task
5664
def regenerate(c):
@@ -65,11 +73,11 @@ class AddressReuseTCPServer(RootedHTTPServer):
6573
allow_reuse_address = True
6674

6775
server = AddressReuseTCPServer(
68-
OUTPUTDIR,
69-
('', PORT),
76+
CONFIG['outputdir'],
77+
('', CONFIG['port']),
7078
ComplexHTTPRequestHandler)
7179

72-
sys.stderr.write('Serving on port {port} ...\n'.format(port=PORT))
80+
sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG))
7381
server.serve_forever()
7482

7583
@task
@@ -81,17 +89,20 @@ def runserver(c):
8189
def devserver(c):
8290
"""Starts the devserver"""
8391
c.run('echo "Running Pelican DevServer. Press CTRL+C to stop"')
84-
c.run(f'pelican -lr {INPUTDIR} -o {OUTPUTDIR} -s {CONFFILE} {PELICANOPTS} -p {PORT}')
92+
c.run(
93+
'pelican -lr {inputdir} -o {outputdir} -s {conffile} {opts} -p {port}'
94+
.format(**CONFIG)
95+
)
8596

8697
@task
8798
def reserve(c):
88-
"""`build`, then `serve`"""
99+
"""Builds, then serves"""
89100
build(c)
90101
serve(c)
91102

92103
@task
93104
def preview(c):
94-
"""Build production version of site"""
105+
"""Builds the production version of site"""
95106
c.run('pelican -s publishconf.py')
96107

97108
@task
@@ -102,9 +113,15 @@ def revert(c):
102113
if not os.getenv('TRAVIS_PULL_REQUEST'):
103114
c.run('echo "Build errors were encountered. Reverting last commit..."')
104115
c.run('git revert HEAD -n')
105-
c.run('git commit -m "Revert to last commit because errors were found."')
116+
c.run(
117+
'git commit -m "Revert to last commit because errors were found."'
118+
)
106119
c.run('git checkout -b errors')
107-
c.run(f'git push -f https://{GITHUB_TOKEN}@github.com/PythonClassmates/PythonClassmates.org.git errors:master')
120+
c.run(
121+
'git push -f https://{github}@github.com/'
122+
'PythonClassmates/PythonClassmates.org.git errors:master'
123+
.format(**CONFIG)
124+
)
108125
c.run('echo "Last commit reverted"')
109126
else:
110127
c.run('echo "In a pull request. Nothing to revert."')

0 commit comments

Comments
 (0)