Skip to content

Commit

Permalink
Eliminate old-fashioned type annotations in check_branch.py script
Browse files Browse the repository at this point in the history
  • Loading branch information
achave11-ucsc committed Jan 15, 2025
1 parent f9e4c5d commit 9357280
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions scripts/check_branch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import sys
from typing import (
Optional,
Sequence,
)

Expand All @@ -16,17 +15,17 @@
"""


def default_deployment(branch: Optional[str]) -> Optional[str]:
def default_deployment(branch: str | None) -> str | None:
deployments = config.shared_deployments_for_branch(branch)
return None if deployments is None else deployments[0].name


class BranchDeploymentMismatch(Exception):

def __init__(self,
branch: Optional[str],
branch: str | None,
deployment: config.Deployment,
allowed: Optional[Sequence[config.Deployment]]
allowed: Sequence[config.Deployment] | None
) -> None:
branch = 'Detached head' if branch is None else f'Branch {branch!r}'
if allowed is None:
Expand All @@ -37,15 +36,15 @@ def __init__(self,
f'only {allowed}personal deployments.')


def check_branch(branch: Optional[str], deployment: str) -> None:
def check_branch(branch: str | None, deployment: str) -> None:
deployment = config.Deployment(deployment)
if deployment.is_shared:
deployments = config.shared_deployments_for_branch(branch)
if deployments is None or deployment not in deployments:
raise BranchDeploymentMismatch(branch, deployment, deployments)


def gitlab_branch() -> Optional[str]:
def gitlab_branch() -> str | None:
"""
Return the current branch if we're on GitLab, else `None`
"""
Expand All @@ -54,7 +53,7 @@ def gitlab_branch() -> Optional[str]:
return os.environ.get('CI_COMMIT_REF_NAME')


def local_branch() -> Optional[str]:
def local_branch() -> str | None:
"""
Return `None` if detached head, else the current branch
"""
Expand Down

0 comments on commit 9357280

Please sign in to comment.