From 73c7733c6d539116c0034294b683059ee745b926 2013-09-04 05:29:23 From: Jonathan Frederic Date: 2013-09-04 05:29:23 Subject: [PATCH] Function -> variable --- diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py index abff42e..d7a8840 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, format_date +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, @@ -282,7 +282,7 @@ class Exporter(LoggingConfigurable): resources['metadata']['name'] = notebook_name modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename)) - resources['metadata']['modified_date'] = format_date(modified_date) + 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 90cd063..ed913fc 100755 --- a/IPython/nbconvert/preprocessors/sphinx.py +++ b/IPython/nbconvert/preprocessors/sphinx.py @@ -30,7 +30,7 @@ from pygments.formatters import LatexFormatter # Our own imports # Configurable traitlets from IPython.utils.traitlets import Unicode, Bool -from IPython.utils.text import format_date +from IPython.utils import text # Needed to override preprocessor from .base import (Preprocessor) @@ -159,7 +159,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"] = format_date(date.today()) + resources["sphinx"]["date"] = date.today().strftime(text.date_format) else: resources["sphinx"]["date"] = resources['metadata']['modified_date'] @@ -221,7 +221,7 @@ class SphinxPreprocessor(Preprocessor): if resources['metadata']['modified_date']: default_date = resources['metadata']['modified_date'] else: - default_date = format_date(date.today()) + default_date = date.today().strftime(text.date_format) user_date = console.input("Date (deafults to \"" + default_date + "\"): ") if len(user_date.strip()) == 0: diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 1a3546a..ad761d7 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -29,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 = date.strftime("%B %d, %Y") +else: + date_format = date.strftime("%B %-d, %Y") + + #----------------------------------------------------------------------------- # Code #----------------------------------------------------------------------------- @@ -712,21 +724,3 @@ def columnize(items, separator=' ', displaywidth=80): fmatrix = [filter(None, x) for x in matrix] sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['columns_width'])]) return '\n'.join(map(sjoin, fmatrix))+'\n' - - -def format_date(date): - """ Format a datetime object as a string. - - Parameters - ---------- - date : datetime object - Date to be formatted. - - Returns - ------- - The formatted date string (ie "July 1, 1990") - """ - if sys.platform == 'win32': - return date.strftime("%B {0}, %Y").format(date.day) - else: - return date.strftime("%B %-d, %Y") \ No newline at end of file