release.source¶
The source repository and the release repository of a model.
A release exports the tracked files of a model package from its source
repository (e.g. a monorepo of models) into a checkout of the release
repository. The functions here check both repositories and write the package;
every refusal is a ReleaseError. Git is called through a Runner, so the
tests can replace it.
ReleaseError
¶
Bases: Exception
A refusal of the release command, the message is for the user.
Runner
¶
Bases: Protocol
Runs a command in a folder, see run.
SourceRepo
dataclass
¶
The clean source repository of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
Path
|
the top level folder of the git repository. |
commit |
str
|
the commit the release is built from. |
ReleaseRepo
dataclass
¶
The checkout of the release repository.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
the folder of the checkout. |
last_tag |
str | None
|
the highest released version, |
ahead |
int
|
the number of local commits which |
run
¶
Run a command and return its stdout.
A command whose output is parsed (git, gh, docker queries) is captured. A long
step of the build or the publishing (uv, the analyses of the model, docker
build) is streamed: its output goes to the terminal as it runs. The command
does not inherit VIRTUAL_ENV: the environment the release runs in is the
one of the source repository, uv in the release repository uses its own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Sequence[str]
|
the command and its arguments. |
required |
cwd
|
Path
|
the working directory. |
required |
stream
|
bool
|
show the output of the command instead of capturing it. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The standard output of the command, empty if it is streamed. |
Raises:
| Type | Description |
|---|---|
ReleaseError
|
if the command fails or does not exist; the message has the command and the tail of its standard error (a streamed command has shown its standard error already). |
current_runner
¶
Get the runner of the commands of a release in this context.
Returns:
| Type | Description |
|---|---|
Runner
|
The runner of an enclosing |
using_runner
¶
Run the commands of the kind release with a runner in this context.
The kind runs inside of sbmlsim.run.execute, which takes no runner; the
build of a release through the run layer
(sbmlsim.release.workflow.execute_release) passes its runner so.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runner
|
Runner
|
runs git, uv and the analyses of the build. |
required |
Yields:
| Type | Description |
|---|---|
Generator[None]
|
Nothing; the runner holds until the block ends. |
source_repo
¶
source_repo(project, runner=run)
Find the source repository of a project and check it is clean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
the project, its |
required |
runner
|
Runner
|
runs the git commands. |
run
|
Returns:
| Type | Description |
|---|---|
SourceRepo
|
The root and the current commit of the repository. |
Raises:
| Type | Description |
|---|---|
ReleaseError
|
if there are uncommitted or untracked files. |
clone_url
¶
The URL the release repository is cloned from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository
|
str
|
the GitHub repository as |
required |
Returns:
| Type | Description |
|---|---|
str
|
The https URL of the repository. |
parse_version
¶
Parse a version of a release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
the version |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
The three numbers of the version. |
Raises:
| Type | Description |
|---|---|
ReleaseError
|
if the version is not |
locked_version
¶
Get the version of a package of uv.lock.
uv locks a local package (a path, directory or editable source) whose version
is dynamic without a version, e.g. a checkout of the framework given as
framework_path; its version is then the kind and the location of its
source, e.g. editable /home/user/sbmlsim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
Mapping[str, Any]
|
a |
required |
Returns:
| Type | Description |
|---|---|
str
|
The locked version or the description of the local source. |
source_framework
¶
Get the version of the framework which the source repository locks.
The release repository is locked to the library versions of the source (see
sbmlsim.release.project), so this is the framework of the release,
whichever version runs the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceRepo
|
the source repository. |
required |
framework
|
str
|
the name of the framework, see
|
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The locked version (see |
str | None
|
without the framework in it. |
release_repo
¶
release_repo(settings, path, runner=run, *, checkout=None)
Find or clone the release repository and bring it to origin/main.
The clone is the one of an out, <out>/repository: a missing one is
cloned (_clone), and a fresh or reused clone is brought to
origin/main (_to_origin), so a checkout it was cloned from is only a
cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ReleaseSettings
|
the release settings of the model. |
required |
path
|
Path
|
the clone the release is built in, cloned when it does not exist. |
required |
runner
|
Runner
|
runs the git commands. |
run
|
checkout
|
Path | None
|
a checkout of the release repository which a missing |
None
|
Returns:
| Type | Description |
|---|---|
ReleaseRepo
|
The clone, its highest released version and the number of its |
ReleaseRepo
|
commits which are not pushed (only the release commit of a release |
ReleaseRepo
|
which failed while publishing may be, see |
An empty repository (a new repository on GitHub without a commit) has no release and no commit ahead.
Raises:
| Type | Description |
|---|---|
ReleaseError
|
if |
check_version
¶
Check that a version is newer than the last release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
the new version |
required |
last_tag
|
str | None
|
the last released version, |
required |
Raises:
| Type | Description |
|---|---|
ReleaseError
|
if a version is malformed or |
package_dirs
¶
Get the folders of the package of a project, pkg/models/hctz of pkg.models.hctz.
Raises:
| Type | Description |
|---|---|
ReleaseError
|
for a project without a package, which is not released. |
export_package
¶
export_package(
project, settings, source, release_path, runner=run
)
Write the tracked files of the model package into the release repository.
The files below src/<package as folders> are replaced. The parent folders
of the package (and src) are namespace folders, so an __init__.py there is removed
and none is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
the project, |
required |
settings
|
ReleaseSettings
|
the release settings, |
required |
source
|
SourceRepo
|
the source repository. |
required |
release_path
|
Path
|
the checkout of the release repository. |
required |
runner
|
Runner
|
runs the git commands. |
run
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The written files, relative to |
Raises:
| Type | Description |
|---|---|
ReleaseError
|
for a project without a package. |