Skip to content

Commit

Permalink
Anchor relative paths to the site config file.
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
mblayman committed Sep 22, 2015
1 parent a94a060 commit a83908a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions handroll/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ def load_from_file(self, config_file):
self.parser.readfp(f)
if self.parser.has_option('site', 'domain'):
self._domain = self.parser.get('site', 'domain')

if self.parser.has_option('site', 'outdir'):
self.outdir = os.path.abspath(os.path.expanduser(
self.parser.get('site', 'outdir')))
outdir = os.path.expanduser(self.parser.get('site', 'outdir'))
if not os.path.isabs(outdir):
path = os.path.dirname(config_file)
outdir = os.path.abspath(os.sep.join([path, outdir]))
self.outdir = outdir

if self.parser.has_section('site'):
self._find_extensions(self.parser)

Expand Down
7 changes: 5 additions & 2 deletions handroll/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_build_config_from_file(self):

config = configuration.build_config(f.name, args)

expected = os.path.join(os.getcwd(), 'out')
expected = os.path.join(os.path.dirname(f.name), 'out')
self.assertEqual(expected, config.outdir)

def test_finds_active_extensions(self):
Expand Down Expand Up @@ -97,4 +97,7 @@ def test_converts_relative_paths(self):
f.write(conf_file.encode('utf-8'))
config = configuration.Configuration()
config.load_from_file(f.name)
self.assertEqual(os.path.abspath('..'), config.outdir)
# Relative output directories are anchored to the site config file.
self.assertEqual(
os.path.dirname(os.path.dirname(f.name)),
config.outdir)

0 comments on commit a83908a

Please sign in to comment.