From 91b431ce7864b0bf04ef88c71b185f3f8f5a246b Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 17 Jun 2016 15:45:20 +1000 Subject: [PATCH] Move element-info to a standard entry-point Move element-info from a wrapper script to a standard entry-point console_script. Update the documentation to explain how to run it for development. I don't think we should support the idea that you can check-out the code and run ./bin/disk-image-create -- it has dependencies (dib-utils, etc) and needs to be run from a virtualenv (this is what CI in the gate does). A follow-up can clean-up some of the path munging stuff we have for this in disk-image-create. Change-Id: Ic0c03995667f320a27ac30441279f3e6abb6bca8 --- MANIFEST.in | 1 - bin/element-info | 21 ------------------- diskimage_builder/element_dependencies.py | 7 +++++-- doc/source/developer/invocation.rst | 10 +++++++++ lib/common-functions | 3 ++- ...ent-info-entry-point-448bf622be6061a0.yaml | 9 ++++++++ setup.cfg | 2 +- 7 files changed, 27 insertions(+), 26 deletions(-) delete mode 100755 bin/element-info create mode 100644 releasenotes/notes/element-info-entry-point-448bf622be6061a0.yaml diff --git a/MANIFEST.in b/MANIFEST.in index f7f0d66f..858ab9d5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include bin/disk-image-create -include bin/element-info include bin/ramdisk-image-create graft lib graft elements diff --git a/bin/element-info b/bin/element-info deleted file mode 100755 index d395408b..00000000 --- a/bin/element-info +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python -# Copyright 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import sys - -from diskimage_builder.element_dependencies import main - - -sys.exit(main(sys.argv)) diff --git a/diskimage_builder/element_dependencies.py b/diskimage_builder/element_dependencies.py index 0a5ceeee..402f6e67 100644 --- a/diskimage_builder/element_dependencies.py +++ b/diskimage_builder/element_dependencies.py @@ -179,7 +179,7 @@ def find_all_elements(paths=None): return all_elements -def main(argv): +def main(): diskimage_builder.logging_config.setup() parser = argparse.ArgumentParser() @@ -194,7 +194,7 @@ def main(argv): help=('Output eval-able bash strings for ' 'IMAGE_ELEMENT variables')) - args = parser.parse_args(argv[1:]) + args = parser.parse_args(sys.argv[1:]) all_elements = find_all_elements() @@ -232,3 +232,6 @@ def main(argv): print(' '.join(elements)) return 0 + +if __name__ == "__main__": + main() diff --git a/doc/source/developer/invocation.rst b/doc/source/developer/invocation.rst index 7635c139..90c97ba2 100644 --- a/doc/source/developer/invocation.rst +++ b/doc/source/developer/invocation.rst @@ -1,3 +1,13 @@ +Installation +============ + +For general use, you can use distribution packages or install via +``pip`` in a ``virtualenv`` + +For development purposes, you can use ``pip -e`` to install into a +local development/testing ``virtualenv``, or use ``tox -e venv -- +disk-image-create`` to run within a ``tox`` created environment. + Invocation ========== diff --git a/lib/common-functions b/lib/common-functions index 080aae69..42624667 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -194,6 +194,7 @@ function arg_to_elements() { IMAGE_ELEMENT="$RAMDISK_ELEMENT $IMAGE_ELEMENT" fi echo "Building elements: $IMAGE_ELEMENT" + export IMAGE_ELEMENT # element-info will output bash code to create # * IMAGE_ELEMENT @@ -217,7 +218,7 @@ function arg_to_elements() { # element=$i # path=${image_elements[$i] # done - eval "$($SCRIPT_HOME/element-info --env $IMAGE_ELEMENT)" + eval "$(element-info --env $IMAGE_ELEMENT)" echo "Expanded element dependencies to: $IMAGE_ELEMENT" } diff --git a/releasenotes/notes/element-info-entry-point-448bf622be6061a0.yaml b/releasenotes/notes/element-info-entry-point-448bf622be6061a0.yaml new file mode 100644 index 00000000..3f423998 --- /dev/null +++ b/releasenotes/notes/element-info-entry-point-448bf622be6061a0.yaml @@ -0,0 +1,9 @@ +--- +deprecations: + + - The ``element-info`` script is now provided by a standard python + entry-point, rather than an explicit wrapper script. This may + affect you if you were running this script directly out of ``bin`` + in the source directory without installing. See developer notes + for details on using developer-installs with virtual environments + for testing. diff --git a/setup.cfg b/setup.cfg index 7839aeb0..57122888 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,6 @@ packages = scripts = bin/dib-lint bin/disk-image-create - bin/element-info bin/ramdisk-image-create data_files = share/diskimage-builder/elements = elements/* @@ -57,4 +56,5 @@ universal = 1 [entry_points] console_scripts = + element-info = diskimage_builder.element_dependencies:main dib-block-device = diskimage_builder.block_device:main