Skip to content

Commit

Permalink
Reorder members to eliminate forward references
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed May 25, 2024
1 parent 5e002c1 commit 3df842e
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/azul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,45 +974,6 @@ def domain_name(self) -> str:
def private_api(self) -> bool:
return self._boolean(self.environ['AZUL_PRIVATE_API'])

@property
def _shared_deployments(self) -> Mapping[Optional[str], Sequence['Deployment']]:
"""
Maps a branch name to a sequence of names of shared deployments the
branch can be deployed to. The key of None signifies any other branch
not mapped explicitly, or a detached head.
"""
# FIXME: Eliminate local import
# https://github.com/DataBiosphere/azul/issues/3133
import json
deployments = json.loads(self.environ['azul_shared_deployments'])
require(all(isinstance(v, list) and v for v in deployments.values()),
'Invalid value for azul_shared_deployments')
return frozendict(
(k if k else None, tuple(self.Deployment(n) for n in v))
for k, v in deployments.items()
)

def shared_deployments_for_branch(self,
branch: str | None,
) -> Sequence['Deployment'] | None:
"""
The list of names of shared deployments the given branch can be deployed
to or `None` of no such deployments exist. An argument of `None`
indicates a detached head. If a list is returned, it will not be empty
and the first element denotes the default deployment. The default
deployment is the one that GitLab deploys a branch to when it builds a
commit on that branch.
"""
deployments = self._shared_deployments
try:
return deployments[branch]
except KeyError:
return None if branch is None else deployments.get(None)

@property
def deployment(self) -> 'Deployment':
return self.Deployment(self.deployment_stage)

@attr.s(frozen=True, kw_only=False, auto_attribs=True)
class Deployment:
name: str
Expand Down Expand Up @@ -1104,6 +1065,45 @@ def is_lower_sandbox(self) -> bool:
and config.Deployment(config.main_deployment_stage).is_lower
)

@property
def deployment(self) -> Deployment:
return self.Deployment(self.deployment_stage)

@property
def _shared_deployments(self) -> Mapping[Optional[str], Sequence[Deployment]]:
"""
Maps a branch name to a sequence of names of shared deployments the
branch can be deployed to. The key of None signifies any other branch
not mapped explicitly, or a detached head.
"""
# FIXME: Eliminate local import
# https://github.com/DataBiosphere/azul/issues/3133
import json
deployments = json.loads(self.environ['azul_shared_deployments'])
require(all(isinstance(v, list) and v for v in deployments.values()),
'Invalid value for azul_shared_deployments')
return frozendict(
(k if k else None, tuple(self.Deployment(n) for n in v))
for k, v in deployments.items()
)

def shared_deployments_for_branch(self,
branch: str | None,
) -> Sequence[Deployment] | None:
"""
The list of names of shared deployments the given branch can be deployed
to or `None` of no such deployments exist. An argument of `None`
indicates a detached head. If a list is returned, it will not be empty
and the first element denotes the default deployment. The default
deployment is the one that GitLab deploys a branch to when it builds a
commit on that branch.
"""
deployments = self._shared_deployments
try:
return deployments[branch]
except KeyError:
return None if branch is None else deployments.get(None)

class BrowserSite(TypedDict):
domain: str
bucket: str
Expand Down

0 comments on commit 3df842e

Please sign in to comment.