Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building in non-initialized project without explicit parameter #482

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/tito/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def __init__(self, name=None, build_dir=None,
if args and 'test' in args:
self.test = True

self.without_init = self._get_optional_arg(kwargs, "without_init", False)
self.ignore_missing_config = \
self._get_optional_arg(kwargs, "ignore_missing_config", False)

# Location where we do all tito work and store resulting rpms:
self.rpmbuild_basedir = build_dir
Expand Down Expand Up @@ -419,7 +420,7 @@ def __init__(self, name=None, tag=None, build_dir=None,
self.relative_project_dir = get_relative_project_dir(
project_name=self.project_name, commit=self.git_commit_id)
if self.relative_project_dir is None and self.test:
if not self.without_init:
if not self.ignore_missing_config:
warn_out(".tito/packages/%s doesn't exist "
"in git, using current directory" % self.project_name)
self.relative_project_dir = get_relative_project_dir_cwd(
Expand Down Expand Up @@ -475,8 +476,8 @@ def _get_build_version(self):
if not self.test:
error_out(["Unable to lookup latest package info.",
"Perhaps you need to tag first?"])
if not self.without_init:
warn_out("unable to lookup latest package "
if not self.ignore_missing_config:
warn_out("Unable to lookup latest package "
"tag, building untagged test project")
build_version = get_spec_version_and_release(self.start_dir,
find_spec_like_file(self.start_dir))
Expand Down
49 changes: 34 additions & 15 deletions src/tito/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ def load(self):
self._check_required_config(self.config)
return self.config

@property
def tito_props_path(self):
"""
Return absolute path to the `tito.props` file
"""
rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
return os.path.join(rel_eng_dir, TITO_PROPS)

def _read_config(self):
"""
Read global build.py configuration from the .tito dir of the git
Expand All @@ -86,14 +94,6 @@ def _read_config(self):
NOTE: We always load the latest config file, not tito.props as it
was for the tag being operated on.
"""
# List of filepaths to config files we'll be loading:
rel_eng_dir = os.path.join(find_git_root(), tito_config_dir())
filename = os.path.join(rel_eng_dir, TITO_PROPS)
if not os.path.exists(filename):
error_out("Unable to locate branch configuration: %s\n"
"Please run 'tito init' or use '--without-init' parameter"
% filename)

# Load the global config. Later, when we know what tag/package we're
# building, we may also load that and potentially override some global
# settings.
Expand Down Expand Up @@ -282,11 +282,29 @@ def initial_config(self):
})
return config

def _check_config_and_load(self, loader):
path = loader.tito_props_path
if os.path.exists(path):
self.config = loader.load()
return

# When working in non-initialized project, only building is allowed
if not isinstance(self, BuildModule):
error_out("Unable to locate branch configuration: %s\n"
"Please run 'tito init'" % loader.tito_props_path)

if not self.options.ignore_missing_config:
warn_out("Tito project wasn't initialized, "
"using the default configuration")
warn_out("Consider `tito init' or the `--ignore-missing-config' "
"parameter to silent the warnings")

self.config = self.initial_config


def load_config(self, package_name, build_dir, tag):
if self.options.without_init:
self.config = self.initial_config
else:
self.config = ConfigLoader(package_name, build_dir, tag).load()
loader = ConfigLoader(package_name, build_dir, tag)
self._check_config_and_load(loader)

if self.config.has_option(BUILDCONFIG_SECTION,
"offline"):
Expand Down Expand Up @@ -348,8 +366,9 @@ def __init__(self):

self.parser.add_option("--test", dest="test", action="store_true",
help="use current branch HEAD instead of latest package tag")
self.parser.add_option("--without-init", action="store_true",
help="Ignore missing .tito directory")
self.parser.add_option("--ignore-missing-config", action="store_true",
help=("Acknowledge working in non-initialized project "
"and silencing all related warnings"))
self.parser.add_option("--no-cleanup", dest="no_cleanup",
action="store_true",
help="do not clean up temporary tito build directories/files, and disable rpmbuild %clean")
Expand Down Expand Up @@ -396,7 +415,7 @@ def main(self, argv):
kwargs = {
'dist': self.options.dist,
'test': self.options.test,
'without_init': self.options.without_init,
'ignore_missing_config': self.options.ignore_missing_config,
'offline': self.options.offline,
'auto_install': self.options.auto_install,
'rpmbuild_options': self.options.rpmbuild_options,
Expand Down