Skip to content

[Python3] Added support to make book at python 3 environment #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ Issues and pull requests are more than welcome!

## Building the Book

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:
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:

$ pip install markdown
$ pip install pygments
$ pip install smartypants
$ pip3 install markdown
$ pip3 install pygments
$ pip3 install smartypants

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

$ python script/format.py
$ python3 script/format.py

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:

$ python script/format.py --watch
$ python3 script/format.py --watch

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

Expand Down
31 changes: 17 additions & 14 deletions script/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,18 @@ def format_file(path, nav, skip_up_to_date):
elif command == 'outline':
isoutline = True
else:
print "UNKNOWN COMMAND:", command, args
print ("UNKNOWN COMMAND:", command, args)

elif extension != "xml" and stripped.startswith('#'):
# Build the page navigation from the headers.
index = stripped.find(" ")
headertype = stripped[:index]
header = pretty(stripped[index:].strip())
anchor = header.lower().replace(' ', '-')
anchor = anchor.translate(None, '.?!:/"')
if 2 == sys.version_info[0]:
anchor = anchor.translate(None, '.?!:/"')
else:
anchor = anchor.translate('.?!:/"')

# Add an anchor to the header.
contents += indentation + headertype
Expand Down Expand Up @@ -224,19 +227,19 @@ def format_file(path, nav, skip_up_to_date):
num_chapters += 1
if word_count < 50:
empty_chapters += 1
print " {}".format(basename)
print (" {}".format(basename))
elif word_count < 2000:
empty_chapters += 1
print "{}-{} {} ({} words)".format(
YELLOW, DEFAULT, basename, word_count)
print ("{}-{} {} ({} words)".format(
YELLOW, DEFAULT, basename, word_count))
else:
total_words += word_count
print "{}✓{} {} ({} words)".format(
GREEN, DEFAULT, basename, word_count)
print ("{}✓{} {} ({} words)".format(
GREEN, DEFAULT, basename, word_count))
else:
# Section header chapters aren't counted like regular chapters.
print "{}•{} {} ({} words)".format(
GREEN, DEFAULT, basename, word_count)
print ("{}•{} {} ({} words)".format(
GREEN, DEFAULT, basename, word_count))


def clean_up_xml(output):
Expand Down Expand Up @@ -417,8 +420,8 @@ def include_code(pattern, index, indentation):
else:
code_line = line[blockindent:]
if len(code_line) > 64:
print "Warning long source line ({} chars):\n{}".format(
len(code_line), code_line)
print ("Warning long source line ({} chars):\n{}".format(
len(code_line), code_line))
code += indentation + ' ' + code_line

else:
Expand Down Expand Up @@ -466,7 +469,7 @@ def check_sass():
return

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


searchpath = ('book/*.markdown')
Expand Down Expand Up @@ -494,5 +497,5 @@ def check_sass():
estimated_word_count = total_words + (empty_chapters * average_word_count)
percent_finished = total_words * 100 / estimated_word_count

print "{}/~{} words ({}%)".format(
total_words, estimated_word_count, percent_finished)
print ("{}/~{} words ({}%)".format(
total_words, estimated_word_count, percent_finished))