Skip to content

Commit

Permalink
Merge pull request #74 from gaow/master
Browse files Browse the repository at this point in the history
Rebuild file if source file has a newer time stamp
  • Loading branch information
choldgraf authored Jan 9, 2019
2 parents 774e3b6 + 673f97e commit 64c5980
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions scripts/generate_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def _case_sensitive_fs(path):
path_new_folder = path_url_folder.replace(os.sep + CONTENT_FOLDER_NAME, os.sep + BUILD_FOLDER_NAME)
path_new_file = op.join(path_new_folder, op.basename(path_url_page).replace('.ipynb', '.md'))

if overwrite is False and op.exists(path_new_file):
if overwrite is False and op.exists(path_new_file) \
and os.stat(path_new_file).st_mtime > os.stat(path_url_page).st_mtime:
n_skipped_files += 1
continue

Expand Down Expand Up @@ -308,7 +309,7 @@ def _case_sensitive_fs(path):
print("\n===========")
print("Generated {} new files\nSkipped {} already-built files".format(n_built_files, n_skipped_files))
if n_built_files == 0:
print("Delete the markdown files in '{}' for any pages that you wish to re-build.".format(BUILD_FOLDER_NAME))
print("Delete the markdown files in '{}' for any pages that you wish to re-build, or use --overwrite option to re-build all.".format(BUILD_FOLDER_NAME))
print("\nYour Jupyter Book is now in `{}/`.".format(BUILD_FOLDER_NAME))
print("\nDemo your Jupyter book with `make serve` or push to GitHub!")

Expand Down
23 changes: 22 additions & 1 deletion scripts/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def is_not_in(lines, check):
is_in = False
return is_in

def replace_in_file(from_text, to_text, filename):
with open(filename, "r") as sources:
lines = sources.readlines()
with open(filename, "w") as sources:
for line in lines:
sources.write(line.replace(from_text, to_text))

####################################################
# Delete old build and create a new one
curdir = op.dirname(op.abspath(__file__))
Expand Down Expand Up @@ -80,4 +87,18 @@ def test_split_yaml():
assert (_split_yaml(['\n', '\n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) ==
(['foo\n'], ['baz\n', 'barf\n']))
assert (_split_yaml([' \n', ' \n', '---\n', 'foo\n', '---\n', 'baz\n', 'barf\n']) ==
(['foo\n'], ['baz\n', 'barf\n']))
(['foo\n'], ['baz\n', 'barf\n']))

def test_notebook_update():
source_file = op.join(curdir, 'site', 'content', 'tests', 'features.md')
target_file = op.join(curdir, 'site', '_build', 'tests', 'features.md')
source_text = 'https://'
target_text = 'www.'
# replace source_text with target_text in source_file
assert is_not_in(open(target_file).readlines(), target_text)
replace_in_file(source_text, target_text, source_file)
out = subprocess.check_call(cmd)
assert is_in(open(target_file).readlines(), target_text)
replace_in_file(target_text, source_text, source_file)
out = subprocess.check_call(cmd)
assert is_not_in(open(target_file).readlines(), target_text)

0 comments on commit 64c5980

Please sign in to comment.