diff --git a/src/tito/builder.py b/src/tito/builder.py index 8543af5..cda53ba 100644 --- a/src/tito/builder.py +++ b/src/tito/builder.py @@ -39,7 +39,7 @@ class Builder(object): def __init__(self, name=None, version=None, tag=None, build_dir=None, pkg_config=None, global_config=None, user_config=None, - options=None, args=None): + args=None, **kwargs): """ name - Package name that is being built. @@ -56,8 +56,6 @@ class Builder(object): user_config - User configuration from ~/.titorc. - options - Parsed CLI options. - args - Optional arguments specific to each builder. Can be passed in explicitly by user on the CLI, or via a release target config entry. Only for things which vary on invocations of the builder, @@ -75,20 +73,18 @@ class Builder(object): self.no_cleanup = False self.args = args - # Probably not a great idea to be passing in CLI options directly to - # an object that gets re-used. This is however optional. - if options is not None: - self.dist = options.dist - self.test = options.test - self.offline = options.offline - self.auto_install = options.auto_install - self.rpmbuild_options = options.rpmbuild_options - else: - self.dist = self.test = self.offline = self.auto_install = \ - self.rpmbuild_options = None - self.dist = None - self.test = False - self.offline = False + # Optional keyword arguments: + self.dist = self._get_optional_arg(kwargs, 'dist', None) + self.test = self._get_optional_arg(kwargs, 'test', False) + self.offline = self._get_optional_arg(kwargs, 'offline', False) + self.auto_install = self._get_optional_arg(kwargs, 'auto_install', + False) + self.rpmbuild_options = self._get_optional_arg(kwargs, + 'rpmbuild_options', None) + + if 'options' in kwargs: + print("WARNING: 'options' no longer a supported builder " + "constructor argument.") if not self.rpmbuild_options: self.rpmbuild_options = '' @@ -159,6 +155,15 @@ class Builder(object): 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): for arg in self.REQUIRED_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, 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, build_dir=build_dir, pkg_config=pkg_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: self.cvs_copy_extensions = ("", ) @@ -514,12 +519,12 @@ class CvsBuilder(NoTgzBuilder): def __init__(self, name=None, version=None, tag=None, build_dir=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, build_dir=build_dir, pkg_config=pkg_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 # builder. @@ -622,12 +627,12 @@ class UpstreamBuilder(NoTgzBuilder): def __init__(self, name=None, version=None, tag=None, build_dir=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, build_dir=build_dir, pkg_config=pkg_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", "upstream_name"): @@ -826,12 +831,12 @@ class MockBuilder(Builder): def __init__(self, name=None, version=None, tag=None, build_dir=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, build_dir=build_dir, pkg_config=pkg_config, global_config=global_config, user_config=user_config, - options=options, args=args) + args=args, **kwargs) self.mock_tag = args['mock'] self.mock_cmd_args = "" @@ -909,12 +914,12 @@ class BrewDownloadBuilder(Builder): def __init__(self, name=None, version=None, tag=None, build_dir=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, build_dir=build_dir, pkg_config=pkg_config, global_config=global_config, user_config=user_config, - options=options, args=args) + args=args, **kwargs) self.brew_tag = 'meow' # args['brewtag'] self.dist_tag = args['disttag'] diff --git a/src/tito/cli.py b/src/tito/cli.py index 590c5f1..d7bfff6 100644 --- a/src/tito/cli.py +++ b/src/tito/cli.py @@ -382,11 +382,18 @@ class BuildModule(BaseCliModule): self.options.tag, self.options.no_cleanup) 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, - build_version, self.options, self.pkg_config, + build_version, self.pkg_config, 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) def _validate_options(self): diff --git a/src/tito/common.py b/src/tito/common.py index 2df69bc..3883556 100644 --- a/src/tito/common.py +++ b/src/tito/common.py @@ -91,9 +91,9 @@ def error_out(error_msgs): 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, - builder_class=None): + builder_class=None, **kwargs): """ Create (but don't run) the builder class. Builder object may be 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, global_config=global_config, user_config=user_config, - options=options, - args=args) + args=args, + **kwargs) return builder diff --git a/src/tito/release.py b/src/tito/release.py index 64ba1b3..d29dde0 100644 --- a/src/tito/release.py +++ b/src/tito/release.py @@ -55,7 +55,7 @@ class Releaser(object): # While we create a builder here, we don't actually call run on it # unless the releaser needs to: self.builder = create_builder(name, tag, - version, None, pkg_config, + version, pkg_config, build_dir, global_config, user_config, self.builder_args) 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 # one defined for this git repo or sub-package: self.builder = create_builder(name, tag, - version, None, pkg_config, + version, pkg_config, build_dir, global_config, user_config, self.builder_args, builder_class=self.releaser_config.get(self.target, 'builder'))