From 2467c3a3bdefd1d06f02afc1a6b9ac5bf272ca0e Mon Sep 17 00:00:00 2001 From: kennyballou Date: Sat, 9 Mar 2013 18:37:54 -0700 Subject: Update documentation to reflect option changes --- docs/source/xenant.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/source/xenant.rst b/docs/source/xenant.rst index e9456fa..156883f 100644 --- a/docs/source/xenant.rst +++ b/docs/source/xenant.rst @@ -47,27 +47,27 @@ Xnt has a number of other commands that can be invoked besides those defined in the current directory's `build.py` file. One will need a build file to run. The others, however, do not. -* ``help`` prints a summary message, including information about the version of - Xnt, license, and usage. +* ``-h`` or ``--help`` prints a summary message, including information about + the version of Xnt, license, and usage. Usage:: - $ xnt help + $ xnt --help -* ``list-targets`` does exactly what the name should suggest: it prints a list - of the targets found in the current directory's `build.py` script, along with - any docstrings that may be defined with them. +* ``-l`` or ``--list-targets`` does exactly what the name should suggest: it + prints a list of the targets found in the current directory's `build.py` + script, along with any docstrings that may be defined with them. Usage:: - $ xnt list-targets + $ xnt --list-targets -* ``version`` prints Xnt's installed version. +* ``--version`` prints Xnt's installed version. Usage:: - $ xnt version + $ xnt --version .. _xntOptions: @@ -82,7 +82,7 @@ Usage:: Where options can be any and all of the following (unless otherwise specified): -* ``-v``: add verbose output to the execution of Xnt +* ``-v`` or ``--verbose``: add verbose output to the execution of Xnt .. _xntPropertiesParameters: -- cgit v1.2.1 From 793bdd9d0fd2403e665ea2e117fb72096cec091b Mon Sep 17 00:00:00 2001 From: kennyballou Date: Sat, 9 Mar 2013 20:22:42 -0700 Subject: Add build-file specification option --- pylint.conf | 2 +- xnt/tasks.py | 6 ++++-- xnt/tests/xenantargparsertests.py | 26 ++++++++++++++++++++++++++ xnt/xenant.py | 27 ++++++++++++++++++++------- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/pylint.conf b/pylint.conf index a56e0a5..aa74eda 100644 --- a/pylint.conf +++ b/pylint.conf @@ -249,7 +249,7 @@ max-attributes=7 min-public-methods=1 # Maximum number of public methods for a class (see R0904). -max-public-methods=55 +max-public-methods=60 [EXCEPTIONS] diff --git a/xnt/tasks.py b/xnt/tasks.py index 679701c..02cde24 100644 --- a/xnt/tasks.py +++ b/xnt/tasks.py @@ -120,7 +120,7 @@ def log(msg="", lvl=logging.INFO): """Log message using tasks global logger""" LOGGER.log(lvl, msg) -def xntcall(path, targets=None, props=None): +def xntcall(buildfile, targets=None, props=None): """Invoke xnt on another build file in a different directory param: path - to the build file (including build file) @@ -128,9 +128,11 @@ def xntcall(path, targets=None, props=None): param: props - dictionary of properties to pass to the build module """ from xnt.xenant import invoke_build, load_build + build = load_build(buildfile) + path = os.path.dirname(buildfile) cwd = os.getcwd() os.chdir(path) - error_code = invoke_build(load_build(path), targets=targets, props=props) + error_code = invoke_build(build, targets=targets, props=props) os.chdir(cwd) return error_code diff --git a/xnt/tests/xenantargparsertests.py b/xnt/tests/xenantargparsertests.py index 3a22b33..04c8d1c 100644 --- a/xnt/tests/xenantargparsertests.py +++ b/xnt/tests/xenantargparsertests.py @@ -128,5 +128,31 @@ class XenantArgParserTests(unittest.TestCase): self.assertIsNotNone(args["targets"]) self.assertEqual(len(args["targets"]), 0) + def test_build_file_spec_short(self): + """Test build file option""" + args_in = ["-b", "mybuildfile.py"] + args = xnt.xenant.parse_args(args_in) + self.assertIsNotNone(args) + self.assertFalse(args["verbose"]) + self.assertFalse(args["list-targets"]) + self.assertIsNotNone(args["build-file"]) + self.assertEqual(args["build-file"], "mybuildfile.py") + self.assertIsNone(args["properties"]) + self.assertIsNotNone(args["targets"]) + self.assertEqual(len(args["targets"]), 0) + + def test_build_file_spec_long(self): + """Test build file option""" + args_in = ["--build-file", "mybuildfile.py"] + args = xnt.xenant.parse_args(args_in) + self.assertIsNotNone(args) + self.assertFalse(args["verbose"]) + self.assertFalse(args["list-targets"]) + self.assertIsNotNone(args["build-file"]) + self.assertEqual(args["build-file"], "mybuildfile.py") + self.assertIsNone(args["properties"]) + self.assertIsNotNone(args["targets"]) + self.assertEqual(len(args["targets"]), 0) + if __name__ == "__main__": unittest.main() diff --git a/xnt/xenant.py b/xnt/xenant.py index 9e5a3df..5e8dc66 100644 --- a/xnt/xenant.py +++ b/xnt/xenant.py @@ -33,12 +33,15 @@ def main(): """Xnt Entry Point""" start_time = time.time() args = parse_args(sys.argv[1:]) + build_file = "./build.py" if args["verbose"]: LOGGER.setLevel(logging.DEBUG) + if args["build-file"]: + build_file = args["build-file"] if args["list-targets"]: - error_code = list_targets(load_build()) + error_code = list_targets(load_build(build_file)) else: - error_code = invoke_build(load_build(), + error_code = invoke_build(load_build(build_file), args["targets"], args["properties"]) elapsed_time = time.time() - start_time @@ -47,15 +50,20 @@ def main(): LOGGER.info("Failure") from xnt.tasks import rm rm("build.pyc", - "__pycache__") + "__pycache__", + build_file + "c", + os.path.join(os.path.dirname(build_file), "__pycache__")) if error_code != 0: sys.exit(error_code) -def load_build(path=""): +def load_build(buildfile="./build.py"): """Load build file Load the build.py and return the resulting import """ + path = os.path.dirname(buildfile) + build = os.path.basename(buildfile) + buildmodule = os.path.splitext(build)[0] if not path: path = os.getcwd() else: @@ -63,17 +71,17 @@ def load_build(path=""): sys.path.append(path) cwd = os.getcwd() os.chdir(path) - if not os.path.exists("build.py"): + if not os.path.exists(build): LOGGER.error("There was no build file") sys.exit(1) try: - return __import__("build", fromlist=[]) + return __import__(buildmodule, fromlist=[]) except ImportError: LOGGER.error("HOW?!") return None finally: sys.path.remove(path) - del sys.modules["build"] + del sys.modules[buildmodule] os.chdir(cwd) def invoke_build(build, targets=None, props=None): @@ -147,6 +155,11 @@ def parse_args(args_in): action="version", version=__version__, help="Print Xnt Version and quit") + parser.add_argument( + "-b", "--build-file", + dest="build-file", + help="""Specify a build file if different than defaut or in different + path""") parser.add_argument("-l", "--list-targets", action="store_true", dest="list-targets", -- cgit v1.2.1 From bef742210b3f620b6e805a77a5320b79ab78b985 Mon Sep 17 00:00:00 2001 From: kennyballou Date: Sat, 9 Mar 2013 20:28:43 -0700 Subject: Update documentation about build files --- README.rst | 3 +++ docs/source/taskreference.rst | 5 ++--- docs/source/xenant.rst | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index a9b66f2..f501df3 100644 --- a/README.rst +++ b/README.rst @@ -226,6 +226,9 @@ Where ``[options]`` are one of the following: * ``-v``: verbose, turn on logging +* ``-b BUILDFILE`` or ``--build-file BUILDFILE``: Specify build file + for Xnt to load + And where ``[target]+`` are any target(s) method in your ``build.py`` file or: diff --git a/docs/source/taskreference.rst b/docs/source/taskreference.rst index a65f00e..3a36d21 100644 --- a/docs/source/taskreference.rst +++ b/docs/source/taskreference.rst @@ -89,15 +89,14 @@ Miscellaneous Tasks change; I'm not sure how I feel about that yet.] .. _xnt.tasks.xntcall: -.. function:: xntcall(path, targets=None, props=None) +.. function:: xntcall(buildfile, targets=None, props=None) Invoke the *target(s)* of a build file in a different *path*. *target* is the name of the target to invoke (similar to *target* of a regular invocation. - *path* is the relative or full path to where the "sub" *build.py* file can - be found. + *buildfile* is the path (relative or full) and build file to use Compile Tasks ============= diff --git a/docs/source/xenant.rst b/docs/source/xenant.rst index 156883f..f5907bb 100644 --- a/docs/source/xenant.rst +++ b/docs/source/xenant.rst @@ -84,6 +84,9 @@ Where options can be any and all of the following (unless otherwise specified): * ``-v`` or ``--verbose``: add verbose output to the execution of Xnt +* ``-b BUILDFILE`` or ``--build-file BUILDFILE``: specifiy to Xnt the build + module to load + .. _xntPropertiesParameters: Properties and Parameter Passing -- cgit v1.2.1