|
27 | 27 | """Utility functions."""
|
28 | 28 |
|
29 | 29 | from __future__ import print_function, unicode_literals, absolute_import
|
30 |
| -from collections import defaultdict, Callable |
31 | 30 | import calendar
|
32 | 31 | import datetime
|
33 | 32 | import dateutil.tz
|
|
42 | 41 | import shutil
|
43 | 42 | import subprocess
|
44 | 43 | import sys
|
45 |
| -from zipfile import ZipFile as zipf |
46 |
| -try: |
47 |
| - from imp import reload |
48 |
| -except ImportError: |
49 |
| - pass |
50 |
| - |
51 | 44 | import dateutil.parser
|
52 | 45 | import dateutil.tz
|
53 | 46 | import logbook
|
| 47 | +import warnings |
| 48 | +import PyRSS2Gen as rss |
| 49 | +from collections import defaultdict, Callable |
54 | 50 | from logbook.more import ExceptionHandler, ColorizedStderrHandler
|
55 | 51 | from pygments.formatters import HtmlFormatter
|
| 52 | +from zipfile import ZipFile as zipf |
| 53 | +from doit import tools |
| 54 | +from unidecode import unidecode |
| 55 | +from pkg_resources import resource_filename |
| 56 | +from doit.cmdparse import CmdParse |
56 | 57 |
|
57 | 58 | from nikola import DEBUG
|
58 | 59 |
|
| 60 | +__all__ = ['get_theme_path', 'get_theme_chain', 'load_messages', 'copy_tree', |
| 61 | + 'copy_file', 'slugify', 'unslugify', 'to_datetime', 'apply_filters', |
| 62 | + 'config_changed', 'get_crumbs', 'get_tzname', 'get_asset_path', |
| 63 | + '_reload', 'unicode_str', 'bytes_str', 'unichr', 'Functionary', |
| 64 | + 'TranslatableSetting', 'TemplateHookRegistry', 'LocaleBorg', |
| 65 | + 'sys_encode', 'sys_decode', 'makedirs', 'get_parent_theme_name', |
| 66 | + 'demote_headers', 'get_translation_candidate', 'write_metadata', |
| 67 | + 'ask', 'ask_yesno', 'options2docstring', 'os_path_split', |
| 68 | + 'get_displayed_page_number', 'adjust_name_for_index_path_list', |
| 69 | + 'adjust_name_for_index_path', 'adjust_name_for_index_link', |
| 70 | + 'NikolaPygmentsHTML', 'create_redirect'] |
| 71 | + |
| 72 | +# Are you looking for 'generic_rss_renderer'? |
| 73 | +# It's defined in nikola.nikola.Nikola (the site object). |
| 74 | + |
| 75 | +if sys.version_info[0] == 3: |
| 76 | + # Python 3 |
| 77 | + bytes_str = bytes |
| 78 | + unicode_str = str |
| 79 | + unichr = chr |
| 80 | + raw_input = input |
| 81 | + from imp import reload as _reload |
| 82 | +else: |
| 83 | + bytes_str = str |
| 84 | + unicode_str = unicode # NOQA |
| 85 | + _reload = reload # NOQA |
| 86 | + unichr = unichr |
| 87 | + |
59 | 88 |
|
60 | 89 | class ApplicationWarning(Exception):
|
61 | 90 | pass
|
@@ -100,9 +129,6 @@ def get_logger(name, handlers):
|
100 | 129 | logging.basicConfig(level=logging.INFO)
|
101 | 130 |
|
102 | 131 |
|
103 |
| -import warnings |
104 |
| - |
105 |
| - |
106 | 132 | def showwarning(message, category, filename, lineno, file=None, line=None):
|
107 | 133 | """Show a warning (from the warnings subsystem) to the user."""
|
108 | 134 | try:
|
@@ -159,42 +185,8 @@ def req_missing(names, purpose, python=True, optional=False):
|
159 | 185 |
|
160 | 186 | return msg
|
161 | 187 |
|
162 |
| -if sys.version_info[0] == 3: |
163 |
| - # Python 3 |
164 |
| - bytes_str = bytes |
165 |
| - unicode_str = str |
166 |
| - unichr = chr |
167 |
| - raw_input = input |
168 |
| - from imp import reload as _reload |
169 |
| -else: |
170 |
| - bytes_str = str |
171 |
| - unicode_str = unicode # NOQA |
172 |
| - _reload = reload # NOQA |
173 |
| - unichr = unichr |
174 |
| - |
175 |
| -from doit import tools |
176 |
| -from unidecode import unidecode |
177 |
| -from pkg_resources import resource_filename |
178 |
| -from nikola import filters as task_filters |
179 |
| - |
180 |
| -import PyRSS2Gen as rss |
181 |
| - |
182 |
| -__all__ = ['get_theme_path', 'get_theme_chain', 'load_messages', 'copy_tree', |
183 |
| - 'copy_file', 'slugify', 'unslugify', 'to_datetime', 'apply_filters', |
184 |
| - 'config_changed', 'get_crumbs', 'get_tzname', 'get_asset_path', |
185 |
| - '_reload', 'unicode_str', 'bytes_str', 'unichr', 'Functionary', |
186 |
| - 'TranslatableSetting', 'TemplateHookRegistry', 'LocaleBorg', |
187 |
| - 'sys_encode', 'sys_decode', 'makedirs', 'get_parent_theme_name', |
188 |
| - 'demote_headers', 'get_translation_candidate', 'write_metadata', |
189 |
| - 'ask', 'ask_yesno', 'options2docstring', 'os_path_split', |
190 |
| - 'get_displayed_page_number', 'adjust_name_for_index_path_list', |
191 |
| - 'adjust_name_for_index_path', 'adjust_name_for_index_link', |
192 |
| - 'NikolaPygmentsHTML', 'create_redirect'] |
193 |
| - |
194 |
| -# Are you looking for 'generic_rss_renderer'? |
195 |
| -# It's defined in nikola.nikola.Nikola (the site object). |
196 |
| - |
197 | 188 |
|
| 189 | +from nikola import filters as task_filters # NOQA |
198 | 190 | ENCODING = sys.getfilesystemencoding() or sys.stdin.encoding
|
199 | 191 |
|
200 | 192 |
|
@@ -1287,10 +1279,6 @@ def ask_yesno(query, default=None):
|
1287 | 1279 | return ask_yesno(query, default)
|
1288 | 1280 |
|
1289 | 1281 |
|
1290 |
| -from nikola.plugin_categories import Command |
1291 |
| -from doit.cmdparse import CmdParse |
1292 |
| - |
1293 |
| - |
1294 | 1282 | class CommandWrapper(object):
|
1295 | 1283 | """Converts commands into functions."""
|
1296 | 1284 |
|
@@ -1341,6 +1329,8 @@ def _run(self, cmd_args):
|
1341 | 1329 | self.main.run(cmd_args)
|
1342 | 1330 |
|
1343 | 1331 | def _run_with_kw(self, cmd, *a, **kw):
|
| 1332 | + # cyclic import hack |
| 1333 | + from nikola.plugin_categories import Command |
1344 | 1334 | cmd = self.main.sub_cmds[cmd]
|
1345 | 1335 | options, _ = CmdParse(cmd.options).parse([])
|
1346 | 1336 | options.update(kw)
|
|
0 commit comments