diff --git a/CHANGES b/CHANGES index b2afba121..c236960a6 100644 --- a/CHANGES +++ b/CHANGES @@ -145,6 +145,9 @@ New features added - Added a command-line switch ``-A``: it can be used to supply additional values into the HTML templates. + - Added a command-line switch ``-C``: if it is given, no configuration + file ``conf.py`` is required. + - Added a distutils command `build_sphinx`: When Sphinx is installed, you can call ``python setup.py build_sphinx`` for projects that have Sphinx documentation, which will build the docs and place them in diff --git a/doc/intro.rst b/doc/intro.rst index af3cc1aaa..47e016b37 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -105,6 +105,11 @@ The :program:`sphinx-build` script has several more options: .. versionadded:: 0.3 +**-C** + Don't look for a configuration file; only take options via the ``-D`` option. + + .. versionadded:: 0.5 + **-D** *setting=value* Override a configuration value set in the :file:`conf.py` file. (The value must be a string value.) diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 96dc8dd51..1add81934 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -37,6 +37,7 @@ Options: -b -- builder to use; default is html (default: outdir/.doctrees) -c -- path where configuration file (conf.py) is located (default: same as sourcedir) + -C -- use no config file at all, only -D options -D -- override a setting in configuration -A -- pass a value into the templates, for HTML builder -N -- do not do colored output @@ -55,13 +56,14 @@ def main(argv): nocolor() try: - opts, args = getopt.getopt(argv[1:], 'ab:d:c:D:A:NEqP') + opts, args = getopt.getopt(argv[1:], 'ab:d:c:CD:A:NEqP') + allopts = set(opt[0] for opt in opts) srcdir = confdir = path.abspath(args[0]) if not path.isdir(srcdir): print >>sys.stderr, 'Error: Cannot find source directory.' return 1 if not path.isfile(path.join(srcdir, 'conf.py')) and \ - '-c' not in (opt[0] for opt in opts): + '-c' not in allopts and '-C' not in allopts: print >>sys.stderr, 'Error: Source directory doesn\'t contain conf.py file.' return 1 outdir = path.abspath(args[1]) @@ -104,6 +106,8 @@ def main(argv): print >>sys.stderr, \ 'Error: Configuration directory doesn\'t contain conf.py file.' return 1 + elif opt == '-C': + confdir = None elif opt == '-D': try: key, val = val.split('=') diff --git a/sphinx/config.py b/sphinx/config.py index 012668e79..fa04ac2a8 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -94,13 +94,15 @@ class Config(object): def __init__(self, dirname, filename, overrides): self.overrides = overrides self.values = Config.config_values.copy() - config = {'__file__': path.join(dirname, filename)} - olddir = os.getcwd() - try: - os.chdir(dirname) - execfile(config['__file__'], config) - finally: - os.chdir(olddir) + config = {} + if dirname is not None: + config['__file__'] = path.join(dirname, filename) + olddir = os.getcwd() + try: + os.chdir(dirname) + execfile(config['__file__'], config) + finally: + os.chdir(olddir) self._raw_config = config # these two must be preinitialized because extensions can add their # own config values