Skip to content

Commit 898a374

Browse files
committed
Update fabfile to be language-specific
You must now build for a specific language; this allows for different translations to progress at their own pace.
1 parent 81ecb97 commit 898a374

2 files changed

Lines changed: 76 additions & 74 deletions

File tree

‎README.rst‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ build process very easy.
4646

4747
If you just want to render the HTML version, it's sufficient to run::
4848

49-
fab build
49+
$ fab build:en
50+
51+
Replace `en` with the language you'd like to build.
5052

5153
This will create a directory ``_build``, containing the HTML version.
5254

@@ -57,22 +59,20 @@ Other `builders <http://sphinx.pocoo.org/builders.html#builders>`_ can be
5759
passed as argument. For instance use ``singlehtml`` to render the whole
5860
tutorial into a single HTML file::
5961

60-
fab build:singlehtml
62+
$ fab build:en,singlehtml
6163

6264
Translation
6365
===========
6466

6567
After editing the tutorial, it is desirable to update translations for it.
6668

67-
1. Translation templates (.pot) must be created or updated - ``fab gen_pots``
68-
2. Templates must merged/built into po translation files - ``fab update_pos:de``
69-
70-
.. note:: Both 1 and 2 can be done with ``fab update_pos``
69+
1. New translation templates (.pot) must be created, then po translation
70+
files are updated (or created for the first time) - ``fab update_pos:de``
71+
2. po files must be checked and translated correctly
72+
3. ``fab build:de`` will compile po files, and build the docs for that
73+
language.
7174

72-
3. po files must be checked and translated correctly
73-
4. ``fab build`` will compile po files, and build the docs for each language
74-
75-
.. note:: only po files should be committed to version control. pot and mo
75+
.. note:: only .po files should be committed to version control. .pot and .mo
7676
files are built automatically.
7777

7878
Deploy
@@ -82,12 +82,18 @@ The workshop is deployed as a `GitHub Page`_. A good way to do
8282
that is described `here <https://gist.github.com/791759>`_. To simplify this
8383
process, you can use a nifty fabric target::
8484

85-
fab setup
85+
$ fab setup
86+
87+
This recreates the ``_build/html`` folder, cloning the folder to the
88+
``gh-pages`` branch of this repo. Then you should build updates for the
89+
desired language. Then `cd` into this folder, and git push the updates to
90+
update the branch. Like so::
8691

87-
This recreates the ``_build/html`` folder by building the project, while the
88-
folder is cloned to the ``gh-pages`` branch of this repo. You can simply
89-
``cd`` into this folder thereafter and push new updates,
90-
or use ``fab build`` to rebuild it.
92+
$ fab build:en
93+
$ cd _build/html
94+
$ git status
95+
$ git commit --all
96+
$ git push
9197

9298
License
9399
=======

‎fabfile.py‎

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from fabric.api import local
2-
from fabric.context_managers import lcd
32
import os
4-
try:
3+
import sys
4+
if sys.version_info[0] < 3:
55
import SimpleHTTPServer as httpserver
66
import SocketServer as socketserver
7-
except ImportError:
7+
else:
88
import http.server as httpserver
99
import socketserver
1010

@@ -14,7 +14,7 @@
1414
SOURCE_DIR = os.path.join(BASE_DIR, 'source')
1515
LOCALE_DIR = os.path.join(SOURCE_DIR, 'locale',
1616
'%s', 'LC_MESSAGES')
17-
LANGUAGES = {'en', 'de'}
17+
LANGUAGES = set(['en', 'de'])
1818
MAIN_TARGET = 'html'
1919
REPOSITORY = 'git@github.com:OpenTechSchool/python-beginners.git'
2020
SERVE_PORT = 8000
@@ -27,27 +27,46 @@ def setup():
2727
local('mkdir -p %s' % target_dir)
2828
local('git clone %s -b %s --single-branch %s' %
2929
(REPOSITORY, 'gh-pages', target_dir))
30-
with lcd(target_dir):
31-
local('rm -rf ./*')
32-
local('touch .nojekyll')
33-
build()
3430

3531

36-
def build(target=MAIN_TARGET):
37-
for language in LANGUAGES:
38-
build_language(language, target)
32+
def build(language=None, target=MAIN_TARGET):
33+
if language is None:
34+
print('Please build a specific language; one of')
35+
print(', '.join(LANGUAGES))
36+
exit()
37+
elif language not in LANGUAGES:
38+
exit('Language %s not available.' % language)
39+
if os.path.isdir(LOCALE_DIR % language):
40+
compile_pos(language)
41+
args = [
42+
'sphinx-build',
43+
'-b', # builder type
44+
target,
45+
'-d', # doctree path
46+
os.path.join(BUILD_DIR, 'doctrees'),
47+
'-D',
48+
'language=%s' % language,
49+
SOURCE_DIR,
50+
os.path.join(BUILD_DIR, target, language), # output path
51+
]
52+
local(' '.join(args))
3953
if 'html' in target:
4054
static_files = os.path.join(BASE_DIR, '_static', '*')
4155
target_dir = os.path.join(BUILD_DIR, target)
4256
local('cp %s %s' % (static_files, target_dir))
4357

4458

45-
def clean(target=MAIN_TARGET):
46-
local('rm -rf %s' % os.path.join(BUILD_DIR, target))
59+
def clean(language=None, target=MAIN_TARGET):
60+
if language is not None:
61+
local('rm -rf %s' % os.path.join(BUILD_DIR, target, language))
62+
else:
63+
local('rm -rf %s' % os.path.join(BUILD_DIR, target))
4764

4865

49-
def serve(port=SERVE_PORT, serve_dir=BUILD_DIR+'/'+MAIN_TARGET):
66+
def serve(port=SERVE_PORT, serve_dir=None):
5067
"""Run a web server to serve the built project"""
68+
if serve_dir is None:
69+
serve_dir = os.path.join(BUILD_DIR, MAIN_TARGET)
5170
port = int(port)
5271
os.chdir(serve_dir)
5372
handler = httpserver.SimpleHTTPRequestHandler
@@ -56,44 +75,26 @@ def serve(port=SERVE_PORT, serve_dir=BUILD_DIR+'/'+MAIN_TARGET):
5675
httpd.serve_forever()
5776

5877

59-
def build_language(language, target=MAIN_TARGET):
60-
if os.path.isdir(LOCALE_DIR % language):
61-
compile_pos(language)
78+
def update_pos(language):
79+
"""Update .po files if the source has changed"""
80+
if language not in LANGUAGES:
81+
exit('Language %s not available.' % language)
82+
_gen_pots(language)
6283
args = [
63-
'sphinx-build',
64-
'-b', # builder type
65-
target,
66-
'-d', # doctree path
67-
os.path.join(BUILD_DIR, 'doctrees'),
68-
'-D',
69-
'language=%s' % language,
70-
SOURCE_DIR,
71-
os.path.join(BUILD_DIR, target, language), # output path
84+
'sphinx-intl update',
85+
'-l %s ' % language,
86+
'-p',
87+
os.path.join(BUILD_DIR, 'locale', language),
88+
'-c',
89+
os.path.join(SOURCE_DIR, 'conf.py'),
7290
]
7391
local(' '.join(args))
7492

7593

76-
def update_pos(language=None):
77-
"""Update .po files if the source has changed"""
78-
gen_pots(language)
79-
if language is None:
80-
lang_set = LANGUAGES - {'en'}
81-
else:
82-
lang_set = language
83-
for language in lang_set:
84-
args = [
85-
'sphinx-intl update',
86-
'-l %s ' % language,
87-
'-p',
88-
os.path.join(BUILD_DIR, 'locale', language),
89-
'-c',
90-
os.path.join(SOURCE_DIR, 'conf.py'),
91-
]
92-
local(' '.join(args))
93-
94-
9594
def compile_pos(language):
9695
"""Compile .po files into .mo files"""
96+
if language not in LANGUAGES:
97+
exit('Language %s not available.' % language)
9798
args = [
9899
'sphinx-intl build',
99100
'-l %s' % language,
@@ -103,18 +104,13 @@ def compile_pos(language):
103104
local(' '.join(args))
104105

105106

106-
def gen_pots(language=None):
107+
def _gen_pots(language):
107108
"""Generate .pot templates from sphinx source files"""
108-
if language is None:
109-
lang_set = LANGUAGES - {'en'}
110-
else:
111-
lang_set = language
112-
for language in lang_set:
113-
args = [
114-
'sphinx-build',
115-
'-b gettext',
116-
'-D language=%s' % language,
117-
SOURCE_DIR,
118-
os.path.join(BUILD_DIR, 'locale', language),
119-
]
120-
local(' '.join(args))
109+
args = [
110+
'sphinx-build',
111+
'-b gettext',
112+
'-D language=%s' % language,
113+
SOURCE_DIR,
114+
os.path.join(BUILD_DIR, 'locale', language),
115+
]
116+
local(' '.join(args))

0 commit comments

Comments
 (0)