Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Yaml playground #2821

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions nikola/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@

"""The main function of Nikola."""

import importlib.machinery
import os
import shutil
import sys
import traceback
from collections import defaultdict

import yaml
from blinker import signal
from doit.cmd_auto import Auto as DoitAuto
from doit.cmd_base import TaskLoader
Expand All @@ -57,7 +59,6 @@
pass # This is only so raw_input/input does nicer things if it's available


import importlib.machinery

config = {}

Expand Down Expand Up @@ -124,16 +125,27 @@ def main(args=None):
try:
loader = importlib.machinery.SourceFileLoader("conf", conf_filename)
conf = loader.load_module()
config = conf.__dict__
if 'yaml_config' in conf.__dict__:
config = conf.__dict__.pop('yaml_config')
config.update(conf.__dict__)
except Exception:
# Try loading gustom config path
if os.path.exists(conf_filename):
msg = traceback.format_exc(0)
LOGGER.error('"{0}" cannot be parsed.\n{1}'.format(conf_filename, msg))
return 1
elif needs_config_file and conf_filename_changed:
LOGGER.error('Cannot find configuration file "{0}".'.format(conf_filename))
return 1
config = {}
else: # Try loading conf.yaml only
try:
with open('conf.yaml') as inf:
config = yaml.load(inf) or {'foo': 'bar'}
conf_filename = 'conf.yaml'
except Exception:
LOGGER.error('Error parsing conf.yaml')
config = {}
raise

if conf_filename_changed:
LOGGER.info("Using config file '{0}'".format(conf_filename))
Expand Down
Loading