Skip to content

Commit

Permalink
Building in non-initialized project without explicit parameter
Browse files Browse the repository at this point in the history
Fix #472
  • Loading branch information
FrostyX committed Jan 11, 2024
1 parent 39943ba commit b0e494f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/tito/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def _get_build_version(self):
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 "
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
45 changes: 32 additions & 13 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.without_init:
warn_out("Tito project wasn't initialized, "
"using the default configuration")
warn_out("Consider `tito init' or the `--without-init' "
"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 @@ -349,7 +367,8 @@ 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")
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

0 comments on commit b0e494f

Please sign in to comment.