Skip to content

Commit 1d6147c

Browse files
committed
[Python3] Added support to make book at python 3 environment, change instruction for describe the process how to make with python 3.
1 parent dd008c0 commit 1d6147c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Issues and pull requests are more than welcome!
33

44
## Building the Book
55

6-
The book is written in Markdown (in `book/`). A little Python script (`script/format.py`) converts that along with a SASS file (`asset/style.scss`) and HTML template (`asset/template.html`) to the final HTML (in `html/`). To run the format script locally, you'll need to have Python 2.7-ish, and install Python Markdown, Pygments, and SmartyPants:
6+
The book is written in Markdown (in `book/`). A little Python script (`script/format.py`) converts that along with a SASS file (`asset/style.scss`) and HTML template (`asset/template.html`) to the final HTML (in `html/`). To run the format script locally, you'll need to have Python 3.5-ish, and install Python Markdown, Pygments, and SmartyPants:
77

8-
$ pip install markdown
9-
$ pip install pygments
10-
$ pip install smartypants
8+
$ pip3 install markdown
9+
$ pip3 install pygments
10+
$ pip3 install smartypants
1111

1212
You may need `sudo` for those. Once that's done, you can run:
1313

14-
$ python script/format.py
14+
$ python3 script/format.py
1515

1616
Make sure to run this from the root directory of the repo. That will regenerate all of the chapter and section intro HTML files. If you're editing stuff, the script can also be run in watch mode:
1717

18-
$ python script/format.py --watch
18+
$ python3 script/format.py --watch
1919

2020
That will monitor the file system for changes to the markdown files, SASS file, or HTML template, and reprocess them as needed.
2121

script/format.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,18 @@ def format_file(path, nav, skip_up_to_date):
152152
elif command == 'outline':
153153
isoutline = True
154154
else:
155-
print "UNKNOWN COMMAND:", command, args
155+
print ("UNKNOWN COMMAND:", command, args)
156156

157157
elif extension != "xml" and stripped.startswith('#'):
158158
# Build the page navigation from the headers.
159159
index = stripped.find(" ")
160160
headertype = stripped[:index]
161161
header = pretty(stripped[index:].strip())
162162
anchor = header.lower().replace(' ', '-')
163-
anchor = anchor.translate(None, '.?!:/"')
163+
if 2 == sys.version_info[0]:
164+
anchor = anchor.translate(None, '.?!:/"')
165+
else:
166+
anchor = anchor.translate('.?!:/"')
164167

165168
# Add an anchor to the header.
166169
contents += indentation + headertype
@@ -224,19 +227,19 @@ def format_file(path, nav, skip_up_to_date):
224227
num_chapters += 1
225228
if word_count < 50:
226229
empty_chapters += 1
227-
print " {}".format(basename)
230+
print (" {}".format(basename))
228231
elif word_count < 2000:
229232
empty_chapters += 1
230-
print "{}-{} {} ({} words)".format(
231-
YELLOW, DEFAULT, basename, word_count)
233+
print ("{}-{} {} ({} words)".format(
234+
YELLOW, DEFAULT, basename, word_count))
232235
else:
233236
total_words += word_count
234-
print "{}✓{} {} ({} words)".format(
235-
GREEN, DEFAULT, basename, word_count)
237+
print ("{}✓{} {} ({} words)".format(
238+
GREEN, DEFAULT, basename, word_count))
236239
else:
237240
# Section header chapters aren't counted like regular chapters.
238-
print "{}•{} {} ({} words)".format(
239-
GREEN, DEFAULT, basename, word_count)
241+
print ("{}•{} {} ({} words)".format(
242+
GREEN, DEFAULT, basename, word_count))
240243

241244

242245
def clean_up_xml(output):
@@ -417,8 +420,8 @@ def include_code(pattern, index, indentation):
417420
else:
418421
code_line = line[blockindent:]
419422
if len(code_line) > 64:
420-
print "Warning long source line ({} chars):\n{}".format(
421-
len(code_line), code_line)
423+
print ("Warning long source line ({} chars):\n{}".format(
424+
len(code_line), code_line))
422425
code += indentation + ' ' + code_line
423426

424427
else:
@@ -466,7 +469,7 @@ def check_sass():
466469
return
467470

468471
subprocess.call(['sass', 'asset/style.scss', 'html/style.css'])
469-
print "{}✓{} style.css".format(GREEN, DEFAULT)
472+
print ("{}✓{} style.css".format(GREEN, DEFAULT))
470473

471474

472475
searchpath = ('book/*.markdown')
@@ -494,5 +497,5 @@ def check_sass():
494497
estimated_word_count = total_words + (empty_chapters * average_word_count)
495498
percent_finished = total_words * 100 / estimated_word_count
496499

497-
print "{}/~{} words ({}%)".format(
498-
total_words, estimated_word_count, percent_finished)
500+
print ("{}/~{} words ({}%)".format(
501+
total_words, estimated_word_count, percent_finished))

0 commit comments

Comments
 (0)