Commits

Georg Brandl committed d2c9092

Allow build without conf.py using -C command line switch.

Comments (0)

Files changed (4)

   - 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
 
    .. 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.)

sphinx/cmdline.py

                       (default: outdir/.doctrees)
          -c <path> -- path where configuration file (conf.py) is located
                       (default: same as sourcedir)
+         -C        -- use no config file at all, only -D options
          -D <setting=value> -- override a setting in configuration
          -A <name=value>    -- pass a value into the templates, for HTML builder
          -N        -- do not do colored output
         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])
                 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('=')
     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