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.3.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.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: auto_app_panel-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 370225cb65e8ef7ff0364017d3dacee6c2a802397dbf4752cc94cb2f651c3cad
MD5 9d96a482606e568f65525372911e8b3f
BLAKE2b-256 c86913dff8b5e266bf908d0ef787643870e19d85812a08f5426faa8533d34f53

See more details on using hashes here.

File details

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

File metadata

  • Download URL: auto_app_panel-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 008f203f142cc1adaf587f45d8eec85c5b942d770d5d8a8dfea799886b5f9e82
MD5 67136631bec7ef29c62070c8e433d77f
BLAKE2b-256 138c8350b551c4ffce695842078708cdde8c330b746d5a4c2d57acbaacf26835

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