From 5e4d9f3b3cd383de57a1c0efb43b2a0cc9a82778 2013-09-04 18:37:55 From: Thomas Kluyver Date: 2013-09-04 18:37:55 Subject: [PATCH] Merge pull request #4085 from jdfreder/fix_sphinx_data_win_again nbconvert: Fix sphinx preprocessor date format string for Windows --- diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py index e84b6fe..8666a92 100755 --- a/IPython/nbconvert/exporters/exporter.py +++ b/IPython/nbconvert/exporters/exporter.py @@ -33,7 +33,7 @@ from IPython.config import Config from IPython.nbformat import current as nbformat from IPython.utils.traitlets import MetaHasTraits, DottedObjectName, Unicode, List, Dict, Any from IPython.utils.importstring import import_item -from IPython.utils.text import indent +from IPython.utils import text from IPython.utils import py3compat from IPython.nbconvert import preprocessors as nbpreprocessors @@ -47,7 +47,7 @@ from IPython.nbconvert import filters JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols'] default_filters = { - 'indent': indent, + 'indent': text.indent, 'markdown2html': filters.markdown2html, 'ansi2html': filters.ansi2html, 'filter_data_type': filters.DataTypeFilter, @@ -283,7 +283,7 @@ class Exporter(LoggingConfigurable): resources['metadata']['name'] = notebook_name modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename)) - resources['metadata']['modified_date'] = modified_date.strftime("%B %d, %Y") + resources['metadata']['modified_date'] = modified_date.strftime(text.date_format) with io.open(filename) as f: return self.from_notebook_node(nbformat.read(f, 'json'), resources=resources,**kw) diff --git a/IPython/nbconvert/preprocessors/sphinx.py b/IPython/nbconvert/preprocessors/sphinx.py index 6974291..f3a30d6 100755 --- a/IPython/nbconvert/preprocessors/sphinx.py +++ b/IPython/nbconvert/preprocessors/sphinx.py @@ -29,6 +29,7 @@ from pygments.formatters import LatexFormatter # Our own imports # Configurable traitlets from IPython.utils.traitlets import Unicode, Bool +from IPython.utils import text # Needed to override preprocessor from .base import (Preprocessor) @@ -157,7 +158,7 @@ class SphinxPreprocessor(Preprocessor): if self.publish_date: resources["sphinx"]["date"] = self.publish_date elif len(resources['metadata']['modified_date'].strip()) == 0: - resources["sphinx"]["date"] = date.today().strftime("%B %-d, %Y") + resources["sphinx"]["date"] = date.today().strftime(text.date_format) else: resources["sphinx"]["date"] = resources['metadata']['modified_date'] @@ -219,7 +220,7 @@ class SphinxPreprocessor(Preprocessor): if resources['metadata']['modified_date']: default_date = resources['metadata']['modified_date'] else: - default_date = date.today().strftime("%B %-d, %Y") + default_date = date.today().strftime(text.date_format) user_date = console.input("Date (deafults to \"" + default_date + "\"): ") if len(user_date.strip()) == 0: @@ -261,4 +262,3 @@ class SphinxPreprocessor(Preprocessor): 6: "(for international documents)"} return console.prompt_dictionary(styles, menu_comments=comments) - diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 55b8861..2980e0e 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -21,6 +21,7 @@ Inheritance diagram: import os import re +import sys import textwrap from string import Formatter @@ -28,6 +29,18 @@ from IPython.external.path import path from IPython.testing.skipdoctest import skip_doctest_py3, skip_doctest from IPython.utils import py3compat + +#----------------------------------------------------------------------------- +# Declarations +#----------------------------------------------------------------------------- + +# datetime.strftime date format for ipython +if sys.platform == 'win32': + date_format = "%B %d, %Y" +else: + date_format = "%B %-d, %Y" + + #----------------------------------------------------------------------------- # Code #-----------------------------------------------------------------------------