mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-24 04:32:46 +00:00
Stop passing all CLI args to builders.
Instead using a kwargs solution for optional things to be passed through. Will allow for easier use of builders in other components which do not have a set of CLI args to pass in. (i.e. releasers)
This commit is contained in:
parent
b05c4dd519
commit
9f8d535eb4
4 changed files with 47 additions and 35 deletions
|
@ -39,7 +39,7 @@ class Builder(object):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
name - Package name that is being built.
|
name - Package name that is being built.
|
||||||
|
@ -56,8 +56,6 @@ class Builder(object):
|
||||||
|
|
||||||
user_config - User configuration from ~/.titorc.
|
user_config - User configuration from ~/.titorc.
|
||||||
|
|
||||||
options - Parsed CLI options.
|
|
||||||
|
|
||||||
args - Optional arguments specific to each builder. Can be passed
|
args - Optional arguments specific to each builder. Can be passed
|
||||||
in explicitly by user on the CLI, or via a release target config
|
in explicitly by user on the CLI, or via a release target config
|
||||||
entry. Only for things which vary on invocations of the builder,
|
entry. Only for things which vary on invocations of the builder,
|
||||||
|
@ -75,20 +73,18 @@ class Builder(object):
|
||||||
self.no_cleanup = False
|
self.no_cleanup = False
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
# Probably not a great idea to be passing in CLI options directly to
|
# Optional keyword arguments:
|
||||||
# an object that gets re-used. This is however optional.
|
self.dist = self._get_optional_arg(kwargs, 'dist', None)
|
||||||
if options is not None:
|
self.test = self._get_optional_arg(kwargs, 'test', False)
|
||||||
self.dist = options.dist
|
self.offline = self._get_optional_arg(kwargs, 'offline', False)
|
||||||
self.test = options.test
|
self.auto_install = self._get_optional_arg(kwargs, 'auto_install',
|
||||||
self.offline = options.offline
|
False)
|
||||||
self.auto_install = options.auto_install
|
self.rpmbuild_options = self._get_optional_arg(kwargs,
|
||||||
self.rpmbuild_options = options.rpmbuild_options
|
'rpmbuild_options', None)
|
||||||
else:
|
|
||||||
self.dist = self.test = self.offline = self.auto_install = \
|
if 'options' in kwargs:
|
||||||
self.rpmbuild_options = None
|
print("WARNING: 'options' no longer a supported builder "
|
||||||
self.dist = None
|
"constructor argument.")
|
||||||
self.test = False
|
|
||||||
self.offline = False
|
|
||||||
|
|
||||||
if not self.rpmbuild_options:
|
if not self.rpmbuild_options:
|
||||||
self.rpmbuild_options = ''
|
self.rpmbuild_options = ''
|
||||||
|
@ -159,6 +155,15 @@ class Builder(object):
|
||||||
|
|
||||||
self._check_required_args()
|
self._check_required_args()
|
||||||
|
|
||||||
|
def _get_optional_arg(self, kwargs, arg, default):
|
||||||
|
"""
|
||||||
|
Return the value of an optional keyword argument if it's present,
|
||||||
|
otherwise the default provided.
|
||||||
|
"""
|
||||||
|
if arg in kwargs:
|
||||||
|
return kwargs[arg]
|
||||||
|
return default
|
||||||
|
|
||||||
def _check_required_args(self):
|
def _check_required_args(self):
|
||||||
for arg in self.REQUIRED_ARGS:
|
for arg in self.REQUIRED_ARGS:
|
||||||
if arg not in self.args:
|
if arg not in self.args:
|
||||||
|
@ -447,12 +452,12 @@ class NoTgzBuilder(Builder):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
Builder.__init__(self, name=name, version=version, tag=tag,
|
Builder.__init__(self, name=name, version=version, tag=tag,
|
||||||
build_dir=build_dir, pkg_config=pkg_config,
|
build_dir=build_dir, pkg_config=pkg_config,
|
||||||
global_config=global_config, user_config=user_config,
|
global_config=global_config, user_config=user_config,
|
||||||
options=options, args=args)
|
args=args, **kwargs)
|
||||||
|
|
||||||
# When syncing files with CVS, copy everything from git:
|
# When syncing files with CVS, copy everything from git:
|
||||||
self.cvs_copy_extensions = ("", )
|
self.cvs_copy_extensions = ("", )
|
||||||
|
@ -514,12 +519,12 @@ class CvsBuilder(NoTgzBuilder):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
NoTgzBuilder.__init__(self, name=name, version=version, tag=tag,
|
NoTgzBuilder.__init__(self, name=name, version=version, tag=tag,
|
||||||
build_dir=build_dir, pkg_config=pkg_config,
|
build_dir=build_dir, pkg_config=pkg_config,
|
||||||
global_config=global_config, user_config=user_config,
|
global_config=global_config, user_config=user_config,
|
||||||
options=options, args=args)
|
args=args, **kwargs)
|
||||||
|
|
||||||
# TODO: Hack to override here, patches are in a weird place with this
|
# TODO: Hack to override here, patches are in a weird place with this
|
||||||
# builder.
|
# builder.
|
||||||
|
@ -622,12 +627,12 @@ class UpstreamBuilder(NoTgzBuilder):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
NoTgzBuilder.__init__(self, name=name, version=version, tag=tag,
|
NoTgzBuilder.__init__(self, name=name, version=version, tag=tag,
|
||||||
build_dir=build_dir, pkg_config=pkg_config,
|
build_dir=build_dir, pkg_config=pkg_config,
|
||||||
global_config=global_config, user_config=user_config,
|
global_config=global_config, user_config=user_config,
|
||||||
options=options, args=args)
|
args=args, **kwargs)
|
||||||
|
|
||||||
if not pkg_config or not pkg_config.has_option("buildconfig",
|
if not pkg_config or not pkg_config.has_option("buildconfig",
|
||||||
"upstream_name"):
|
"upstream_name"):
|
||||||
|
@ -826,12 +831,12 @@ class MockBuilder(Builder):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
Builder.__init__(self, name=name, version=version, tag=tag,
|
Builder.__init__(self, name=name, version=version, tag=tag,
|
||||||
build_dir=build_dir, pkg_config=pkg_config,
|
build_dir=build_dir, pkg_config=pkg_config,
|
||||||
global_config=global_config, user_config=user_config,
|
global_config=global_config, user_config=user_config,
|
||||||
options=options, args=args)
|
args=args, **kwargs)
|
||||||
|
|
||||||
self.mock_tag = args['mock']
|
self.mock_tag = args['mock']
|
||||||
self.mock_cmd_args = ""
|
self.mock_cmd_args = ""
|
||||||
|
@ -909,12 +914,12 @@ class BrewDownloadBuilder(Builder):
|
||||||
|
|
||||||
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
def __init__(self, name=None, version=None, tag=None, build_dir=None,
|
||||||
pkg_config=None, global_config=None, user_config=None,
|
pkg_config=None, global_config=None, user_config=None,
|
||||||
options=None, args=None):
|
args=None, **kwargs):
|
||||||
|
|
||||||
Builder.__init__(self, name=name, version=version, tag=tag,
|
Builder.__init__(self, name=name, version=version, tag=tag,
|
||||||
build_dir=build_dir, pkg_config=pkg_config,
|
build_dir=build_dir, pkg_config=pkg_config,
|
||||||
global_config=global_config, user_config=user_config,
|
global_config=global_config, user_config=user_config,
|
||||||
options=options, args=args)
|
args=args, **kwargs)
|
||||||
|
|
||||||
self.brew_tag = 'meow' # args['brewtag']
|
self.brew_tag = 'meow' # args['brewtag']
|
||||||
self.dist_tag = args['disttag']
|
self.dist_tag = args['disttag']
|
||||||
|
|
|
@ -382,11 +382,18 @@ class BuildModule(BaseCliModule):
|
||||||
self.options.tag, self.options.no_cleanup)
|
self.options.tag, self.options.no_cleanup)
|
||||||
|
|
||||||
args = self._parse_builder_args()
|
args = self._parse_builder_args()
|
||||||
|
kwargs = {
|
||||||
|
'dist': self.options.dist,
|
||||||
|
'test': self.options.test,
|
||||||
|
'offline': self.options.offline,
|
||||||
|
'auto_install': self.options.auto_install,
|
||||||
|
'rpmbuild_options': self.options.rpmbuild_options,
|
||||||
|
}
|
||||||
|
|
||||||
builder = create_builder(package_name, build_tag,
|
builder = create_builder(package_name, build_tag,
|
||||||
build_version, self.options, self.pkg_config,
|
build_version, self.pkg_config,
|
||||||
build_dir, self.global_config, self.user_config, args,
|
build_dir, self.global_config, self.user_config, args,
|
||||||
builder_class=self.options.builder)
|
builder_class=self.options.builder, **kwargs)
|
||||||
return builder.run(self.options)
|
return builder.run(self.options)
|
||||||
|
|
||||||
def _validate_options(self):
|
def _validate_options(self):
|
||||||
|
|
|
@ -91,9 +91,9 @@ def error_out(error_msgs):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def create_builder(package_name, build_tag, build_version, options,
|
def create_builder(package_name, build_tag, build_version,
|
||||||
pkg_config, build_dir, global_config, user_config, args,
|
pkg_config, build_dir, global_config, user_config, args,
|
||||||
builder_class=None):
|
builder_class=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Create (but don't run) the builder class. Builder object may be
|
Create (but don't run) the builder class. Builder object may be
|
||||||
used by other objects without actually having run() called.
|
used by other objects without actually having run() called.
|
||||||
|
@ -127,8 +127,8 @@ def create_builder(package_name, build_tag, build_version, options,
|
||||||
pkg_config=pkg_config,
|
pkg_config=pkg_config,
|
||||||
global_config=global_config,
|
global_config=global_config,
|
||||||
user_config=user_config,
|
user_config=user_config,
|
||||||
options=options,
|
args=args,
|
||||||
args=args)
|
**kwargs)
|
||||||
return builder
|
return builder
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Releaser(object):
|
||||||
# While we create a builder here, we don't actually call run on it
|
# While we create a builder here, we don't actually call run on it
|
||||||
# unless the releaser needs to:
|
# unless the releaser needs to:
|
||||||
self.builder = create_builder(name, tag,
|
self.builder = create_builder(name, tag,
|
||||||
version, None, pkg_config,
|
version, pkg_config,
|
||||||
build_dir, global_config, user_config, self.builder_args)
|
build_dir, global_config, user_config, self.builder_args)
|
||||||
self.project_name = self.builder.project_name
|
self.project_name = self.builder.project_name
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ class YumRepoReleaser(Releaser):
|
||||||
# Use the builder from the release target, rather than the default
|
# Use the builder from the release target, rather than the default
|
||||||
# one defined for this git repo or sub-package:
|
# one defined for this git repo or sub-package:
|
||||||
self.builder = create_builder(name, tag,
|
self.builder = create_builder(name, tag,
|
||||||
version, None, pkg_config,
|
version, pkg_config,
|
||||||
build_dir, global_config, user_config, self.builder_args,
|
build_dir, global_config, user_config, self.builder_args,
|
||||||
builder_class=self.releaser_config.get(self.target, 'builder'))
|
builder_class=self.releaser_config.get(self.target, 'builder'))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue