summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-08-06 15:39:13 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-08-06 15:39:13 -0700
commit7b5f69de3f7b52b718507fe16c2560901e48a70c (patch)
tree66dc1930c069e34ed7ed45113b033d66721a5728
parent9532822afccc8db328e07992313d458192f2a367 (diff)
downloadattobuild-7b5f69de3f7b52b718507fe16c2560901e48a70c.tar.gz
attobuild-7b5f69de3f7b52b718507fe16c2560901e48a70c.tar.bz2
attobuild-7b5f69de3f7b52b718507fe16c2560901e48a70c.tar.xz
attobuild-7b5f69de3f7b52b718507fe16c2560901e48a70c.zip
Refactor checks and vars
-rw-r--r--attoconf/_version.py2
-rw-r--r--attoconf/core.py17
-rw-r--r--attoconf/lib/arches.py5
-rw-r--r--attoconf/lib/install.py25
-rw-r--r--attoconf/lib/make.py7
-rw-r--r--attoconf/tests/test_core.py20
-rw-r--r--attoconf/types.py8
7 files changed, 53 insertions, 31 deletions
diff --git a/attoconf/_version.py b/attoconf/_version.py
index d7460a2..41d536a 100644
--- a/attoconf/_version.py
+++ b/attoconf/_version.py
@@ -11,7 +11,7 @@ minor = 3
# Incremented if there is a bugfix release.
# Might not be contiguous.
-patch = 2
+patch = 3
# Reserved for distributors and forks.
# Contains arbitrary text, but no parentheses or newlines.
diff --git a/attoconf/core.py b/attoconf/core.py
index b200cc1..0fb780a 100644
--- a/attoconf/core.py
+++ b/attoconf/core.py
@@ -94,15 +94,21 @@ class Project(object):
'''
if name in self.options:
raise KeyError(name)
- assert type.__module__ == 'attoconf.types', '%s.%s' % (type.__module__, type.__name__)
- if var is None:
- var = as_var(name)
+ if check is not None:
+ assert type.__module__ == 'attoconf.types'
+ if var is None:
+ var = as_var(name)
+ else:
+ # used by some tests ... should this be fixed there instead?
+ if help_var is None:
+ help_var = as_var(name)
if init is not None:
init = type(init)
self.options[name] = Option(init=init, type=type, var=var)
if check is not None:
self.checks.append(
- lambda bld: check(bld, bld.vars[var][0]) )
+ lambda bld: check(bld, **{help_var: bld.vars[var][0]}) )
+
if help_var is None:
help_var = var
if help_def is None:
@@ -144,7 +150,8 @@ class Build(object):
self.project = project
self.builddir = trim_trailing_slashes(builddir)
self.vars = {o.var: (o.init, 'default')
- for o in project.options.itervalues()}
+ for o in project.options.itervalues()
+ if o.var is not None}
def apply_arg(self, arg):
''' Parse a single argument, expanding aliases.
diff --git a/attoconf/lib/arches.py b/attoconf/lib/arches.py
index c168292..595b396 100644
--- a/attoconf/lib/arches.py
+++ b/attoconf/lib/arches.py
@@ -20,6 +20,9 @@ from __future__ import print_function, division, absolute_import
from ..classy import ClassyProject
from ..types import triple
+def build(build, BUILD):
+ pass
+
def host(build, HOST):
if HOST is None:
BUILD, origin = build.vars['BUILD']
@@ -41,7 +44,7 @@ class Arches2(ClassyProject):
super(Arches2, self).arches()
self.add_help('System types:', hidden=False)
self.add_option('--build', init=None,
- type=triple, check=None,
+ type=triple, check=build,
help='configure for building on BUILD', hidden=False,
help_def='native')
self.add_option('--host', init=None,
diff --git a/attoconf/lib/install.py b/attoconf/lib/install.py
index 444c167..a807666 100644
--- a/attoconf/lib/install.py
+++ b/attoconf/lib/install.py
@@ -23,6 +23,18 @@ from ..classy import ClassyProject
from ..types import shell_word, version, filepath, quoted_string
+def package(build, PACKAGE):
+ pass
+
+def package_version(build, VERSION):
+ pass
+
+def package_name(build, NAME):
+ pass
+
+def prefix(build, PREFIX):
+ pass
+
def exec_prefix(build, EPREFIX):
if EPREFIX is None:
PREFIX, origin = build.vars['PREFIX']
@@ -86,6 +98,9 @@ def includedir(build, DIR):
origin = 'derived from PREFIX'
build.vars['INCLUDEDIR'] = (os.path.join(PREFIX, 'include'), origin)
+def oldincludedir(build, DIR):
+ pass
+
def datarootdir(build, DIR):
if DIR is None:
PREFIX, origin = build.vars['PREFIX']
@@ -182,16 +197,16 @@ class Install(ClassyProject):
def general(self):
super(Install, self).general()
self.add_option('--package', init=self.package,
- type=shell_word, check=None,
+ type=shell_word, check=package,
help='Short name of this package (don\'t change!)',
hidden=True)
self.add_option('--package-version', init=self.package_version,
- type=version, check=None,
+ type=version, check=package_version,
help='Version of this package (change in configure)',
hidden=True,
help_var='VERSION')
self.add_option('--package-name', init=self.package_name,
- type=quoted_string, check=None,
+ type=quoted_string, check=package_name,
help='Long name of this package (don\'t change)',
hidden=True,
help_var='NAME')
@@ -201,7 +216,7 @@ class Install(ClassyProject):
self.add_help('Installation directories:', hidden=False)
self.add_option('--prefix', init='/usr/local',
- type=filepath, check=None,
+ type=filepath, check=prefix,
help='install architecture-independent files in PREFIX',
hidden=False)
self.add_option('--exec-prefix', init=None,
@@ -245,7 +260,7 @@ class Install(ClassyProject):
help='C header files', hidden=False,
help_var='DIR', help_def='PREFIX/include')
self.add_option('--oldincludedir', init='/usr/include',
- type=filepath, check=None,
+ type=filepath, check=oldincludedir,
help='C header files for non-gcc', hidden=False,
help_var='DIR')
self.add_option('--datarootdir', init=None,
diff --git a/attoconf/lib/make.py b/attoconf/lib/make.py
index 890361a..816c444 100644
--- a/attoconf/lib/make.py
+++ b/attoconf/lib/make.py
@@ -45,13 +45,6 @@ class MakeHook(object):
out.write('\n')
# TODO preserve *original* order?
for var, (val, origin) in sorted(build.vars.iteritems()):
- if val is None:
- if origin == 'default':
- continue
- # is it a good idea for Nones to survive this long?
- # especially conditional ones ...
- var = '# ' + var
- val = 'not defined'
out.write('%s = %s # %s\n' % (var, val, origin))
if self.infile is not None:
out.write('\n# The rest was copied from %s\n' % self.infile)
diff --git a/attoconf/tests/test_core.py b/attoconf/tests/test_core.py
index c10e8c7..fbbe622 100644
--- a/attoconf/tests/test_core.py
+++ b/attoconf/tests/test_core.py
@@ -20,7 +20,7 @@ from __future__ import print_function, division, absolute_import
import unittest
from attoconf.core import Project, Build
-from attoconf.types import uint, shell_word
+from attoconf.types import uint, shell_word, shell_partial_word
from cStringIO import StringIO
import sys
@@ -95,14 +95,14 @@ General:
self.assertEquals(build.relative_source(), '../foo')
def test_configure(self):
- def check_foo(bld, foo):
- self.assertEqual(foo, 'B')
- def check_bar(bld, bar):
- self.assertEqual(bar, 1)
- def check_qux(bld, qux):
- self.assertEqual(qux, None)
- def check_var(bld, var):
- self.assertEqual(var, 'value')
+ def check_foo(bld, FOO):
+ self.assertEqual(FOO, 'B')
+ def check_bar(bld, BAR):
+ self.assertEqual(BAR, 1)
+ def check_qux(bld, QUX):
+ self.assertEqual(QUX, None)
+ def check_var(bld, VAR):
+ self.assertEqual(VAR, 'value')
proj = Project('.')
proj.add_alias('--alias', ['--foo=A', '--bar=1', '--foo=B'],
@@ -117,7 +117,7 @@ General:
type=uint, check=check_qux,
help='help for int qux', hidden=False)
proj.add_option('VAR', init='',
- type=shell_word, check=check_var,
+ type=shell_partial_word, check=check_var,
help='help for string VAR', hidden=False)
build = Build(proj, '.')
diff --git a/attoconf/types.py b/attoconf/types.py
index ae0ca44..b2b5745 100644
--- a/attoconf/types.py
+++ b/attoconf/types.py
@@ -80,12 +80,16 @@ class ShellList(object):
def shell_word(s):
if s != shell_quote(s):
- if s == '':
- return "''"
raise ValueError('not a word: %r' % s)
return s
+def shell_partial_word(s):
+ if s == '':
+ return s
+ return shell_word(s)
+
+
def quoted_string(s):
return shell_quote(s)