Skip to content

Commit

Permalink
Merge pull request #3613 from getnikola/fix-3612-doit-0.36.0
Browse files Browse the repository at this point in the history
Fix #3612 — doit 0.36.0 compatibility
  • Loading branch information
Kwpolska committed Apr 22, 2022
2 parents 9b2e8ad + a4c67b3 commit 14194fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Features
* Gallery index pages support the `status` flag (Issue #3598)
* Add ``start_at`` option to youtube directive (Issue #3603)

Bugfixes
--------

* Compatibility with doit 0.36.0 (Issue #3612)

Note: ``nikola doit_auto`` is not available if using doit>=0.36.0.

Bugfixes
--------
Expand Down
35 changes: 23 additions & 12 deletions nikola/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
from collections import defaultdict

from blinker import signal
from doit.cmd_auto import Auto as DoitAuto
from doit.cmd_base import TaskLoader, _wrap
from doit.cmd_base import TaskLoader2, _wrap
from doit.cmd_clean import Clean as DoitClean
from doit.cmd_completion import TabCompletion
from doit.cmd_help import Help as DoitHelp
Expand Down Expand Up @@ -247,31 +246,41 @@ def clean_tasks(self, tasks, dryrun, *a):

# Nikola has its own "auto" commands that uses livereload.
# Expose original doit "auto" command as "doit_auto".
DoitAuto.name = 'doit_auto'
# doit_auto is not available with doit>=0.36.0.
try:
from doit.cmd_auto import Auto as DoitAuto
DoitAuto.name = 'doit_auto'
except ImportError:
DoitAuto = None


class NikolaTaskLoader(TaskLoader):
class NikolaTaskLoader(TaskLoader2):
"""Nikola-specific task loader."""

def __init__(self, nikola, quiet=False):
"""Initialize the loader."""
super().__init__()
self.nikola = nikola
self.quiet = quiet

def load_tasks(self, cmd, opt_values, pos_args):
"""Load Nikola tasks."""
def load_doit_config(self):
"""Load doit configuration."""
if self.quiet:
DOIT_CONFIG = {
doit_config = {
'verbosity': 0,
'reporter': 'zero',
}
else:
DOIT_CONFIG = {
doit_config = {
'reporter': ExecutedOnlyReporter,
'outfile': sys.stderr,
}
DOIT_CONFIG['default_tasks'] = ['render_site', 'post_render']
DOIT_CONFIG.update(self.nikola._doit_config)
doit_config['default_tasks'] = ['render_site', 'post_render']
doit_config.update(self.nikola._doit_config)
return doit_config

def load_tasks(self, cmd, pos_args):
"""Load Nikola tasks."""
try:
tasks = generate_tasks(
'render_site',
Expand All @@ -286,15 +295,17 @@ def load_tasks(self, cmd, opt_values, pos_args):
raise
_print_exception()
sys.exit(3)
return tasks + latetasks, DOIT_CONFIG
return tasks + latetasks


class DoitNikola(DoitMain):
"""Nikola-specific implementation of DoitMain."""

# overwite help command
DOIT_CMDS = list(DoitMain.DOIT_CMDS) + [Help, Build, Clean, DoitAuto]
DOIT_CMDS = list(DoitMain.DOIT_CMDS) + [Help, Build, Clean]
TASK_LOADER = NikolaTaskLoader
if DoitAuto is not None:
DOIT_CMDS.append(DoitAuto)

def __init__(self, nikola, quiet=False):
"""Initialzie DoitNikola."""
Expand Down

0 comments on commit 14194fe

Please sign in to comment.