mirror of https://github.com/ansible/ansible.git
Implement a framework for having common code for release scripts (#55893)
* Implement a framework for having common code for release scripts * Release scripts will go through hacking/build-ansible. build-ansible is a pluggable script which will set a directory that has common code for non-enduser scripts. It will then invoke the plugin which implements that subcommand. Uses straight.plugin for loading each sub-command. * We're going to add tools which are needed to test ansible (the changelog generation, for instance) so we need to include the pieces relevant to that in the tarball. * Add straight.plugin to the sanity test requirements for the same reason * Skip compile test just for build-ansible plugins which won't be run as part of sanity tests.pull/56004/head
parent
5d4c73e197
commit
3161a91d7e
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
# PYTHON_ARGCOMPLETE_OK
|
||||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import argparse
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from straight.plugin import load
|
||||
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError:
|
||||
argcomplete = None
|
||||
|
||||
|
||||
def set_sys_path(this_script=__file__):
|
||||
"""Add path to the common librarydirectory to :attr:`sys.path`"""
|
||||
hacking_dir = os.path.dirname(this_script)
|
||||
libdir = os.path.abspath(os.path.join(hacking_dir, 'build_library'))
|
||||
|
||||
if libdir not in sys.path:
|
||||
sys.path.insert(0, libdir)
|
||||
|
||||
|
||||
set_sys_path()
|
||||
|
||||
from build_ansible import commands
|
||||
|
||||
|
||||
def create_arg_parser(program_name):
|
||||
"""
|
||||
Creates a command line argument parser
|
||||
|
||||
:arg program_name: The name of the script. Used in help texts
|
||||
"""
|
||||
parser = argparse.ArgumentParser(prog=program_name,
|
||||
description="Implements utilities to build Ansible")
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entrypoint of the script
|
||||
|
||||
"It all starts here"
|
||||
"""
|
||||
subcommands = load('build_ansible.command_plugins', subclasses=commands.Command)
|
||||
|
||||
arg_parser = create_arg_parser(os.path.basename(sys.argv[0]))
|
||||
subparsers = arg_parser.add_subparsers(title='Subcommands', dest='command',
|
||||
help='for help use build-ansible SUBCOMMANDS -h')
|
||||
subcommands.pipe('init_parser', subparsers.add_parser)
|
||||
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(arg_parser)
|
||||
|
||||
args = arg_parser.parse_args(sys.argv[1:])
|
||||
|
||||
for subcommand in subcommands:
|
||||
if subcommand.name == args.command:
|
||||
sys.exit(subcommand.main(args))
|
||||
|
||||
print('Error: Select a subcommand')
|
||||
arg_parser.print_usage()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,50 @@
|
||||
# coding: utf-8
|
||||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from abc import ABCMeta, abstractmethod, abstractproperty
|
||||
|
||||
|
||||
class Command:
|
||||
"""
|
||||
Subcommands of :program:`build-ansible`.
|
||||
|
||||
This defines an interface that all subcommands must conform to. :program:`build-ansible` will
|
||||
require that these things are present in order to proceed.
|
||||
"""
|
||||
@staticmethod
|
||||
@abstractproperty
|
||||
def name():
|
||||
"""Name of the command. The same as the string is invoked with"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def init_parser(add_parser):
|
||||
"""
|
||||
Initialize and register an argparse ArgumentParser
|
||||
|
||||
:arg add_parser: function which creates an ArgumentParser for the main program.
|
||||
|
||||
Implementations should first create an ArgumentParser using `add_parser` and then populate
|
||||
it with the command line arguments that are needed.
|
||||
|
||||
.. seealso:
|
||||
`add_parser` information in the :py:meth:`ArgumentParser.add_subparsers` documentation.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def main(arguments):
|
||||
"""
|
||||
Run the command
|
||||
|
||||
:arg arguments: The **parsed** command line args
|
||||
|
||||
This is the Command's entrypoint. The command line args are already parsed but from here
|
||||
on, the command can do its work.
|
||||
"""
|
@ -1,3 +1,3 @@
|
||||
# The following are only run by release engineers who can be asked to have newer Python3 on their systems
|
||||
hacking/release-announcement.py
|
||||
hacking/porting-guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/porting_guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/release_announcement.py
|
||||
|
@ -1,3 +1,3 @@
|
||||
# The following are only run by release engineers who can be asked to have newer Python3 on their systems
|
||||
hacking/release-announcement.py
|
||||
hacking/porting-guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/porting_guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/release_announcement.py
|
||||
|
@ -1,3 +1,3 @@
|
||||
# The following are only run by release engineers who can be asked to have newer Python3 on their systems
|
||||
hacking/release-announcement.py
|
||||
hacking/porting-guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/porting_guide.py
|
||||
hacking/build_library/build_ansible/command_plugins/release_announcement.py
|
||||
|
Loading…
Reference in New Issue