Skip to content

Commit

Permalink
Process the selected and excluded branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshshukla99 committed Mar 3, 2024
1 parent 02ce7a9 commit 74aa322
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions sphinx_versioned/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def __init__(self, config: dict) -> None:
self._versions_to_build = []
self._failed_build = []

# selectively build branches / build all branches
self._versions_to_pre_build = (
self._select_specific_branches() if self.select_branches else self._get_all_versions()
)
# Get all versions and make a lookup table
self._all_branches = self._get_all_versions()
self._lookup_branch = {x.name: x for x in self._all_branches}

self._select_exclude_branches()

# if `--force` is supplied with no `--main-branch`, make the `_active_branch` as the `main_branch`
if not self.main_branch:
Expand Down Expand Up @@ -101,27 +102,46 @@ def _get_all_versions(self) -> list:
log.warning(f"git detached {self.versions.repo.head.is_detached}")
_all_versions.append(PseudoBranch(self.versions.repo.head.object.hexsha))

# self._log_versions(_all_versions)
log.debug(f"Found versions: {[x.name for x in _all_versions]}")
return _all_versions

def _select_specific_branches(self) -> list:
log.debug(f"Instructions to select: `{self.select_branches}`")

_all_versions = {x.name: x for x in self._get_all_versions()}
_select_specific_branches = []
def _select_branches(self) -> None:
if not self.select_branches:
self._versions_to_pre_build = self._all_branches
return

for tag in self.select_branches:
if tag in _all_versions.keys():
log.info(f"Selecting tag for further processing: {tag}")
_select_specific_branches.append(_all_versions[tag])
if tag in self._lookup_branch.keys():
self._versions_to_pre_build.append(self._lookup_branch.get(tag))
elif self.force_branches:
log.warning(f"Forcing build for branch `{tag}`, be careful, it may or may not exist!")
_select_specific_branches.append(PseudoBranch(tag))
self._versions_to_pre_build.append(PseudoBranch(tag))
else:
log.critical(f"Branch not found: `{tag}`, use `--force` to force the build")
log.critical(f"Branch not found/selected: `{tag}`, use `--force` to force the build")

return

def _exclude_branches(self) -> None:
if not self.exclude_branches:
return

return _select_specific_branches
_names_versions_to_pre_build = [x.name for x in self._versions_to_pre_build]
for tag in self.exclude_branches:
if tag in _names_versions_to_pre_build:
self._versions_to_pre_build.remove(self._lookup_branch.get(tag))

return

def _select_exclude_branches(self) -> list:
log.debug(f"Instructions to select: `{self.select_branches}`")
log.debug(f"Instructions to exclude: `{self.exclude_branches}`")
self._versions_to_pre_build = []

self._select_branches()
self._exclude_branches()

log.info(f"selected branches: `{[x.name for x in self._versions_to_pre_build]}`")
return

def _generate_top_level_index(self) -> None:
"""Generate a top-level ``index.html`` which redirects to the main-branch version specified
Expand Down

0 comments on commit 74aa322

Please sign in to comment.