Skip to main content

Automatically generate a Code Ocean App Panel from an argument parser defined in code.

Project description

auto-app-panel

Automatically generate a Code Ocean App Panel from an argument parser defined in code.

PyPI Python version

Coverage mypy CI/CD GitHub issues

Status

  • Initial release supporting extraction from pydantic_settings.BaseSettings and argparse.ArgumentParser classes at top-level of a specified Python file.

TODO

  • support classes defined inside functions or conditionals
  • preserve groups and other formatting in existing app panel
  • create explicit string/number/integer Parameter classes to support additional constraints (e.g. min/max length for strings, regex validators etc.) - see codeocean sdk for full schema

Usage

Typical Workflow

  1. Develop your code with a class for parsing capsule parameters at the top-level of the file (not inside a function or conditional)
  2. Run the tool in a Code Ocean cloud workstation terminal, pointing to the file containing the parameter-parsing class:
    pip install auto-app-panel
    auto-app-panel /root/capsule/code/run.py
    
    This generates /root/capsule/.codeocean/app-panel.json, which configures the capsule's App Panel GUI.
  3. Re-run the tool when you add/modify parameters (use --strategy preserve to keep any edits made in the App Panel GUI/in an existing app-panel.json)
  4. Verify that the App Panel is visible and has all expected fields when you exit the cloud workstation

Command Line Interface

auto-app-panel SOURCE [OUTPUT] [OPTIONS]

Arguments:

  • SOURCE - Path to Python file containing argument parsing class (required)
  • OUTPUT - Output path for app-panel.json (default: /root/capsule/.codeocean/app-panel.json)

Options:

  • --strategy [overwrite|preserve] - Merge strategy (default: preserve)
    • overwrite: Updates parameter values from code, preserves existing descriptions
    • preserve: Keeps all existing values, only adds new parameters
  • --no-backup - Skip creating timestamped backup of existing file

Example files

Input Python file (run.py):

import time

import pydantic
import pydantic_settings

class Params(pydantic_settings.BaseSettings):
    max_workers: int | None = pydantic.Field(6, description="Number of parallel workers. Leave empty or set to 0 to use max available.")
    threshold: float = 0.5    
    output_dir: str = pydantic.Field("/root/capsule/results/dryrun", description="Output path for results, posix format.")
    save_intermediate: bool = False
    
    # other attributes that are not parsed from command-line inputs (e.g. PrivateAttr or @computed_field) are ignored
    _start_time: float = pydantic.PrivateAttr(time.time())

    # Ensure class parses arguments from command line (and set priority of other sources):
    @classmethod  
    def settings_customise_sources(
        cls,
        settings_cls,
        init_settings,
        *args,
        **kwargs,
    ):
        # instantiating the class will use arguments passed directly, or provided via the command line/app panel
        # - the order of the sources below defines the priority (highest to lowest):
        # - for each field in the class, the first source that contains a value will be used
        return (
            init_settings,
            pydantic_settings.sources.JsonConfigSettingsSource(settings_cls, json_file='parameters.json'),
            pydantic_settings.CliSettingsSource(settings_cls, cli_parse_args=True),
        )

Generate file at standard path:

auto-app-panel /root/capsule/code/run.py

Generated app-panel.json:

{
    "version": 1,
    "named_parameters": true,
    "parameters": [
        {
            "id": "a1b2c3d4e5f6g7h8",
            "name": "max_workers",
            "param_name": "max_workers",
            "description": "Number of parallel workers",
            "help_text": "Number of parallel workers",
            "type": "text",
            "value_type": "integer",
            "default_value": "6"
        },
        {
            "id": "i9j0k1l2m3n4o5p6",
            "name": "threshold",
            "param_name": "threshold",
            "type": "text",
            "value_type": "number",
            "default_value": "0.5"
        },
        {
            "id": "q7r8s9t0u1v2w3x4",
            "name": "output_dir",
            "param_name": "output_dir",
            "description": "Output path for results, posix format.",
            "help_text": "Output path for results, posix format.",
            "type": "text",
            "value_type": "string",
            "default_value": "/root/capsule/results/dryrun"
        },
        {
            "id": "y5z6a7b8c9d0e1f2",
            "name": "save_intermediate",
            "param_name": "save_intermediate",
            "type": "text",
            "value_type": "integer",
            "default_value": "0",
            "minimum": 0,
            "maximum": 1
        }
    ]
}

Development

Clone the repository and setup with uv sync.

Run tests with uv run task test.

Pushing to main or creating a PR to main will trigger CI/CD. Updates on main that pass all tests will trigger a minor version bump, then be published on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_app_panel-0.1.2.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

auto_app_panel-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file auto_app_panel-0.1.2.tar.gz.

File metadata

  • Download URL: auto_app_panel-0.1.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for auto_app_panel-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0e20b4a375a3e0d0bd70bfe0677b9056f0d87fd514a8ec99edd5029adce1fd4b
MD5 17b87d321581a0afbb1817be1bf4e1f4
BLAKE2b-256 ba14576a925453949f183129c52ad6e54902140a42bf5064378cb0aa00bd85d4

See more details on using hashes here.

File details

Details for the file auto_app_panel-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: auto_app_panel-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for auto_app_panel-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fec82e3d689cc401d95fef603e2caaa617f38e6c0e2a1d44a0840abc01e2a459
MD5 3dbf8c7417bd2617f552832514b9ca77
BLAKE2b-256 e9a58f78f22c5e186111c7fb0a2e50567b05e364829c1c59765e822abf7eb911

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page