Permalink
Browse files

try to protect against shell commands being invoked if imported durin…

…g installation
  • Loading branch information...
1 parent f460fb5 commit 6873b16e10f7db12cb3413dfc3f4945f689892bd @mcdonc mcdonc committed Dec 9, 2011
Showing with 30 additions and 31 deletions.
  1. +30 −31 docs/conf.py
View
@@ -39,20 +39,6 @@ def nothing(*arg):
book = os.environ.get('BOOK')
-# If your extensions are in another directory, add it here. If the directory
-# is relative to the documentation root, use os.path.abspath to make it
-# absolute, like shown here.
-parent = os.path.dirname(os.path.dirname(__file__))
-sys.path.append(os.path.abspath(parent))
-wd = os.getcwd()
-os.chdir(parent)
-os.system('%s setup.py test -q' % sys.executable)
-os.chdir(wd)
-
-for item in os.listdir(parent):
- if item.endswith('.egg'):
- sys.path.append(os.path.join(parent, item))
-
# General configuration
# ---------------------
@@ -141,23 +127,36 @@ def nothing(*arg):
# -----------------------
# Add and use Pylons theme
-from subprocess import call, Popen, PIPE
-
-p = Popen('which git', shell=True, stdout=PIPE)
-git = p.stdout.read().strip()
-cwd = os.getcwd()
-_themes = os.path.join(cwd, '_themes')
-
-if not os.path.isdir(_themes):
- call([git, 'clone', 'git://github.com/Pylons/pylons_sphinx_theme.git',
- '_themes'])
-else:
- os.chdir(_themes)
- call([git, 'checkout', 'master'])
- call([git, 'pull'])
- os.chdir(cwd)
-
-sys.path.append(os.path.abspath('_themes'))
+if 'sphinx-build' in ' '.join(sys.argv): # protect against dumb importers
+ from subprocess import call, Popen, PIPE
+
+ p = Popen('which git', shell=True, stdout=PIPE)
+ git = p.stdout.read().strip()
+ cwd = os.getcwd()
+ _themes = os.path.join(cwd, '_themes')
+
+ if not os.path.isdir(_themes):
+ call([git, 'clone', 'git://github.com/Pylons/pylons_sphinx_theme.git',
+ '_themes'])
+ else:
+ os.chdir(_themes)
+ call([git, 'checkout', 'master'])
+ call([git, 'pull'])
+ os.chdir(cwd)
+
+ sys.path.append(os.path.abspath('_themes'))
+
+ parent = os.path.dirname(os.path.dirname(__file__))
+ sys.path.append(os.path.abspath(parent))
+ wd = os.getcwd()
+ os.chdir(parent)
+ os.system('%s setup.py test -q' % sys.executable)
+ os.chdir(wd)
+
+ for item in os.listdir(parent):
+ if item.endswith('.egg'):
+ sys.path.append(os.path.join(parent, item))
+
html_theme_path = ['_themes']
html_theme = 'pyramid'
html_theme_options = dict(

0 comments on commit 6873b16

Please sign in to comment.