Skip to content

Commit

Permalink
Merge pull request #7 from cvxgrp/6-experiments-as-first-template
Browse files Browse the repository at this point in the history
6 experiments as first template
  • Loading branch information
tschm authored Jan 8, 2025
2 parents 59a531c + 7ed070c commit 368286a
Show file tree
Hide file tree
Showing 24 changed files with 912 additions and 58 deletions.
23 changes: 0 additions & 23 deletions .devcontainer/devcontainer.json

This file was deleted.

3 changes: 0 additions & 3 deletions .devcontainer/startup.sh

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
#- id: check-yaml

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.8.4'
Expand Down Expand Up @@ -37,7 +37,7 @@ repos:
rev: v1.5.5
hooks:
- id: insert-license
files: ^(cvx)
files: ^cvx/.*\.py$
args:
['--license-filepath', 'copyright.txt', '--no-extra-eol']

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
[![Downloads](https://static.pepy.tech/personalized-badge/cradle?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](https://pepy.tech/project/cradle)
[![Coverage Status](https://coveralls.io/repos/github/cvxgrp/cradle/badge.png?branch=main)](https://coveralls.io/github/cvxgrp/cradle?branch=main)

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/cvxgrp/cradle)
cradle is a command line tool to create repos based on a group of templates.

We demonstrate how to deploy to simple command line apps using uvx.
## Install gh

Please install GitHub's official command line tool [gh](https://github.com/cli/cli).

## Using the cradle tool

## Install uvx

Expand Down
76 changes: 50 additions & 26 deletions cvx/cradle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,27 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
cli to get weather data
"""

import os
import tempfile
from pathlib import Path

import questionary
from copier import run_copy
from loguru import logger

from .git import assert_git_version

_templates = Path(__file__).parent / "templates"


def worker(template: str, dst_path, vcs_ref="HEAD", user_defaults=None):
"""Run copier to copy the template to the destination path"""
if user_defaults is None:
_worker = run_copy(src_path=template, dst_path=dst_path, vcs_ref=vcs_ref)
return _worker
from cvx.cradle.utils.git import assert_git_version

# important for testing
_worker = run_copy(
src_path=template,
dst_path=dst_path,
vcs_ref=vcs_ref,
unsafe=True,
defaults=True,
user_defaults=user_defaults,
)
from .utils.shell import run_shell_command
from .utils.ui import worker

return _worker
_templates = Path(__file__).parent / "templates"


def cli(template: str = None, dst: str = None, vcs_ref: str = "HEAD", user_defaults=None) -> None:
"""
CLI for Factory
Args:
template: (optional) template. Use a git URI, e.g. 'git@qromatiq.codes:adia/black/templates/package.git'
template: (optional) template. Use a git URI, e.g. 'git@...'
dst: (optional) destination. Use a path
"""
# check the git version
Expand All @@ -74,3 +55,46 @@ def cli(template: str = None, dst: str = None, vcs_ref: str = "HEAD", user_defau
).ask()

template = templates[result]

# Create a random path
path = dst or Path(tempfile.mkdtemp())
logger.info(f"Path to (re)construct your project: {path}")

# Copy material into the random path
_worker = worker(template=template, dst_path=path, vcs_ref=vcs_ref, user_defaults=user_defaults)

logger.info("Values entered and defined")
for name, value in _worker.answers.user.items():
logger.info(f"{name}: {value}")

command = _worker.answers.user["command"]

run_shell_command(command)

ssh_uri = _worker.answers.user["ssh_uri"]

home = os.getcwd()
logger.info(f"Home: {home}")

# move into the folder used by the Factory
os.chdir(path)

# Initialize the git repository
run_shell_command("git init --initial-branch=main")

# add everything
run_shell_command("git add .")

# make the initial commit
run_shell_command("git commit -am.")

# add the remote origin
run_shell_command(f"git remote add origin {ssh_uri}")

# push everything into the repo
os.system("git push -u origin main")

# go back to the repo
os.chdir(home)

logger.info(f"You may have to perform 'git clone {ssh_uri}'")
48 changes: 48 additions & 0 deletions cvx/cradle/questions/questions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
project_name:
type: str
help: "Your project name? It must start with a lowercase letter, followed by letters, digits, or underscores."
validator: >-
{% if not (project_name | regex_search('^[a-z][a-z0-9_]+$')) %}
project_name must start with a lowercase letter, followed by one or more lowercase letters, digits, or underscores.
{% endif %}
username:
type: str
default: 'tschm'
help: "Home of your future repo (either 'cvxgrp' or your private GitHub account name)"
validator: >-
{% if not username %}
Username cannot be empty.
{% endif %}
description:
type: str
help: "Enter a brief description of your project."
default: "Some computations"
validator: >-
{% if not description %}
Description cannot be empty.
{% endif %}
status:
type: str
help: "What is the visibility status of the repository?"
choices:
- "public"
- "private"
- "internal"
default: "public"
validator: >-
{% if status not in ['public', 'private', 'internal'] %}
Status must be one of: public, private, or internal.
{% endif %}
command:
type: str
default: "gh repo create {{username}}/{{ project_name | lower }} --{{status}} --description '{{description}}'"
when: false

ssh_uri:
type: str
default: "git@github.com:{{username}}/{{ project_name | lower }}.git"
when: false
30 changes: 30 additions & 0 deletions cvx/cradle/templates/experiments/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Marimo Dev Container",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"hostRequirements": {
"cpus": 4
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {}
},
"forwardPorts": [8080],
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": ".venv/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"marimo.pythonPath": ".venv/bin/python",
"marimo.marimoPath": ".venv/bin/marimo"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"marimo-team.vscode-marimo"
]
}
},
"onCreateCommand": ".devcontainer/startup.sh",
"postStartCommand": "uv run marimo --yes edit --host=localhost --port=8080 --headless --no-token",
"remoteUser": "vscode"
}
5 changes: 5 additions & 0 deletions cvx/cradle/templates/experiments/.devcontainer/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
uv pip install --no-cache-dir marimo
uv pip install --no-cache-dir -r requirements.txt
17 changes: 17 additions & 0 deletions cvx/cradle/templates/experiments/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
41 changes: 41 additions & 0 deletions cvx/cradle/templates/experiments/.github/workflows/marimo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: MARIMO

on:
push

permissions:
contents: read


jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@7768fe6bf07695625e41df8b6253deeb006301d9

- name: Create virtual environment
run: |
uv venv
- name: Install dependencies with uv
run: |
uv pip install --no-cache-dir -r requirements.txt
- name: Install marimo
run: |
uv pip install --no-cache-dir marimo
- name: Convert notebooks to HTML
run: |
mkdir -p html_exports
for file in notebooks/*.py; do
if [ -f "$file" ]; then
filename=$(basename "$file" .py)
echo "Converting $filename.py to HTML..."
# Can't work as it relies on license files not part of this repo
# uv run marimo export html "$file" -o "html_exports/${filename}.html"
fi
done
4 changes: 4 additions & 0 deletions cvx/cradle/templates/experiments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.venv
__pycache__
.ruff_cache
45 changes: 45 additions & 0 deletions cvx/cradle/templates/experiments/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.6'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
# Run the formatter
- id: ruff-format

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.43.0
hooks:
- id: markdownlint-fix

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
hooks:
- id: check-renovate
args: [ "--verbose" ]

- id: check-github-workflows
args: ["--verbose"]

- repo: https://github.com/rhysd/actionlint
rev: v1.7.6
hooks:
- id: actionlint
args: [ -ignore, SC ]

- repo: https://github.com/crate-ci/typos
rev: v1.29.4
hooks:
- id: typos
1 change: 1 addition & 0 deletions cvx/cradle/templates/experiments/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Loading

0 comments on commit 368286a

Please sign in to comment.