A Python library for managing source code repositories, interacting with Docker registries, handling MyST markdown operations, and spawning JupyterHub instances locally.
Project description
MyST Libre
Following the REES, myst-libre
streamlines building ✨MyST articles✨ in containers.
- A repository containing MyST sources
- A Docker image (built by
binderhub
) in a public (or private) registry, including:- Dependencies to execute notebooks/markdown files in the MyST repository
- JupyterHub (typically part of images built by
binderhub
)
- Input data required by the executable content (optional)
Given these resources, myst-libre starts a Docker container, mounts the MyST repository and data (if available), and builds a MyST publication.
[!NOTE] This project was started to support publishing MyST articles as living preprints on
NeuroLibre
.
Installation
External dependencies
[!IMPORTANT] Ensure the following prerequisites are installed:
- Node.js (For MyST) installation guide
- Docker installation guide
Install myst-libre
pip install myst-libre
Set up environment variables:
If you are using a private image registry, create a .env
file in the project root and add the following:
DOCKER_PRIVATE_REGISTRY_USERNAME=your_username
DOCKER_PRIVATE_REGISTRY_PASSWORD=your_password
Quick Start
Import libraries and define REES resources
from myst_libre.tools import JupyterHubLocalSpawner, MystMD
from myst_libre.rees import REES
from myst_libre.builders import MystBuilder
rees_resources = REES(dict(
registry_url="https://your-registry.io",
gh_user_repo_name = "owner/repository",
gh_repo_commit_hash = "full_SHA_commit_A",
binder_image_tag = "full_SHA_commit_A_or_B",
dotenv = '/path/to/dotenv'))
[!NOTE] Currently, the assumption is that the Docker image was built by binderhub from a REES-compliant repository that also includes the MyST content. Therefore,
binder_image_tag
andgh_repo_commit_hash
are simply two different commits in the same (gh_repo_user_name
) repository. However,binder_image_tag
is not allowed to be ahead ofgh_repo_commit_hash
.
Fetch resources and spawn JupyterHub in the respective container
hub = JupyterHubLocalSpawner(rees_resources,
host_build_source_parent_dir = '/tmp/myst_repos',
container_build_source_mount_dir = '/home/jovyan', #default
host_data_parent_dir = "/tmp/myst_data", #optional
container_data_mount_dir = '/home/jovyan/data', #optional
)
hub.spawn_jupyter_hub()
- MyST repository will be cloned at:
tmp/
└── myst_repos/
└── owner/
└── repository/
└── full_commit_SHA_A/
├── myst.yml
├── _toc.yml
├── binder/
│ ├── requirements.txt (or other REES dependencies)
│ └── data_requirement.json (optional)
├── content/
│ ├── my_notebook.ipynb
│ └── my_myst_markdown.md
├── paper.md
└── paper.bib
Repository will be mounted to the container as /tmp/myst_repos/owner/repository/full_commit_SHA_A:/home/jovyan
.
- If a
repo2data
manifest is found in the repository, the data will be downloaded to and cached at:
tmp/
└── myst_data/
└── my-dataset
otherwise, it can be manually defined for an existing data under /tmp/myst_data
as follows:
rees_resources.dataset_name = "my-dataset"
In either case, data will be mounted as /tmp/myst_data/my-dataset:/home/jovyan/data/my-dataset
. If no data is provided, this step will be skipped.
Build your MyST article
MystBuilder(hub).build()
Check out the built document
In your terminal:
npx serve /tmp/myst_repos/owner/repository/full_commit_SHA_A/_build/html
Visit ✨http://localhost:3000
✨.
Table of Contents
Usage
Authentication
The Authenticator
class handles loading authentication credentials from environment variables.
from myst_libre.tools.authenticator import Authenticator
auth = Authenticator()
print(auth._auth)
Docker Registry Client
The DockerRegistryClient class provides methods to interact with a Docker registry.
from myst_libre.tools.docker_registry_client import DockerRegistryClient
client = DockerRegistryClient(registry_url='https://my-registry.example.com', gh_user_repo_name='user/repo')
token = client.get_token()
print(token)
Build Source Manager
The BuildSourceManager class manages source code repositories.
from myst_libre.tools.build_source_manager import BuildSourceManager
manager = BuildSourceManager(gh_user_repo_name='user/repo', gh_repo_commit_hash='commit_hash')
manager.git_clone_repo('/path/to/clone')
project_name = manager.get_project_name()
print(project_name)
Module and Class Descriptions
AbstractClass
Description: Provides basic logging functionality and colored printing capabilities.
Authenticator
Description: Handles authentication by loading credentials from environment variables.
Inherited from: AbstractClass
Inputs: Environment variables DOCKER_PRIVATE_REGISTRY_USERNAME
and DOCKER_PRIVATE_REGISTRY_PASSWORD
RestClient
Description: Provides a client for making REST API calls.
Inherited from: Authenticator
DockerRegistryClient
Description: Manages interactions with a Docker registry.
Inherited from: Authenticator
Inputs:
registry_url
: URL of the Docker registrygh_user_repo_name
: GitHub user/repository nameauth
: Authentication credentials
BuildSourceManager
Description: Manages source code repositories.
Inherited from: AbstractClass
Inputs:
gh_user_repo_name
: GitHub user/repository namegh_repo_commit_hash
: Commit hash of the repository
JupyterHubLocalSpawner
Description: Manages JupyterHub instances locally.
Inherited from: AbstractClass
Inputs:
rees
: Instance of the REES classregistry_url
: URL of the Docker registrygh_user_repo_name
: GitHub user/repository nameauth
: Authentication credentialsbinder_image_tag
: Docker image tagbuild_src_commit_hash
: Commit hash of the repositorycontainer_data_mount_dir
: Directory to mount data in the containercontainer_build_source_mount_dir
: Directory to mount build source in the containerhost_data_parent_dir
: Host directory for datahost_build_source_parent_dir
: Host directory for build source
MystMD
Description: Manages MyST markdown operations such as building and converting files.
Inherited from: AbstractClass
Inputs:
build_dir
: Directory where the build will take placeenv_vars
: Environment variables needed for the build processexecutable
: Name of the MyST executable (default is 'myst')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file myst_libre-0.1.27.tar.gz
.
File metadata
- Download URL: myst_libre-0.1.27.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca2ba5c2920cd548deb6b611f50a9c471ece418d921a7286dd384708bc78ad0c |
|
MD5 | d1ff5c826bc09f54cc9a43e67458bb1a |
|
BLAKE2b-256 | a307224cea7a8ae751845a05cd6dbcc9d506e282d0f9c7586ef2f87d6639475c |
Provenance
The following attestation bundles were made for myst_libre-0.1.27.tar.gz
:
Publisher:
publish.yml
on neurolibre/myst-libre
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
myst_libre-0.1.27.tar.gz
- Subject digest:
ca2ba5c2920cd548deb6b611f50a9c471ece418d921a7286dd384708bc78ad0c
- Sigstore transparency entry: 150549080
- Sigstore integration time:
- Predicate type:
File details
Details for the file myst_libre-0.1.27-py3-none-any.whl
.
File metadata
- Download URL: myst_libre-0.1.27-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b436bdd5e4ea1adfcc71516ac6af3ed44d5ee10a2c034b51db4b45f0480b3aa |
|
MD5 | 42a9edb0bbf3689d3fa3d36a27e9b2d5 |
|
BLAKE2b-256 | 09d4b9884d0b9c48bec7fa2ba5ee7e815779648f4e0c7f1996c84c4f24e78a42 |
Provenance
The following attestation bundles were made for myst_libre-0.1.27-py3-none-any.whl
:
Publisher:
publish.yml
on neurolibre/myst-libre
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
myst_libre-0.1.27-py3-none-any.whl
- Subject digest:
4b436bdd5e4ea1adfcc71516ac6af3ed44d5ee10a2c034b51db4b45f0480b3aa
- Sigstore transparency entry: 150549082
- Sigstore integration time:
- Predicate type: