System root ("/") is not a valid path for site_dir or docs_dir.

As neither setting can point at a child dir of the other, "/" would be an
invalid value for either setting. However, given its unique nature,
os.path.abspath does not follow normal bahavior of returning a string without
an ending slash when passed "/". Therefore, we need to special case it.

Fixes #1161.
This commit is contained in:
Waylan Limberg
2017-03-13 20:56:17 -04:00
parent 3833627886
commit 1795d7655a
3 changed files with 8 additions and 6 deletions

View File

@@ -181,8 +181,8 @@ up.
Lets you set the directory containing the documentation source markdown files.
This can either be a relative directory, in which case it is resolved relative
to the directory containing you configuration file, or it can be an absolute
directory path.
to the directory containing your configuration file, or it can be an absolute
directory path from the root of your local file system.
**default**: `'docs'`
@@ -190,8 +190,8 @@ directory path.
Lets you set the directory where the output HTML and other files are created.
This can either be a relative directory, in which case it is resolved relative
to the directory containing you configuration file, or it can be an absolute
directory path.
to the directory containing your configuration file, or it can be an absolute
directory path from the root of your local file system.
**default**: `'site'`

View File

@@ -253,14 +253,14 @@ class SiteDir(Dir):
# Validate that the docs_dir and site_dir don't contain the
# other as this will lead to copying back and forth on each
# and eventually make a deep nested mess.
if (config['docs_dir'] + os.sep).startswith(config['site_dir'] + os.sep):
if (config['docs_dir'] + os.sep).startswith(config['site_dir'].rstrip(os.sep) + os.sep):
raise ValidationError(
("The 'docs_dir' should not be within the 'site_dir' as this "
"can mean the source files are overwritten by the output or "
"it will be deleted if --clean is passed to mkdocs build."
"(site_dir: '{0}', docs_dir: '{1}')"
).format(config['site_dir'], config['docs_dir']))
elif (config['site_dir'] + os.sep).startswith(config['docs_dir'] + os.sep):
elif (config['site_dir'] + os.sep).startswith(config['docs_dir'].rstrip(os.sep) + os.sep):
raise ValidationError(
("The 'site_dir' should not be within the 'docs_dir' as this "
"leads to the build directory being copied into itself and "

View File

@@ -228,6 +228,7 @@ class SiteDirTest(unittest.TestCase):
{'docs_dir': 'docs', 'site_dir': ''},
{'docs_dir': '', 'site_dir': ''},
{'docs_dir': j('..', parent_dir, 'docs'), 'site_dir': 'docs'},
{'docs_dir': 'docs', 'site_dir': '/'}
)
for test_config in test_configs:
@@ -242,6 +243,7 @@ class SiteDirTest(unittest.TestCase):
{'docs_dir': 'docs', 'site_dir': j('docs', 'site')},
{'docs_dir': '.', 'site_dir': 'site'},
{'docs_dir': '', 'site_dir': 'site'},
{'docs_dir': '/', 'site_dir': 'site'},
)
for test_config in test_configs: