Skip to content

Add --single-dependency flag to jhack sync#242

Open
PietroPasotti wants to merge 1 commit intomainfrom
feat/single-dependency-sync
Open

Add --single-dependency flag to jhack sync#242
PietroPasotti wants to merge 1 commit intomainfrom
feat/single-dependency-sync

Conversation

@PietroPasotti
Copy link
Copy Markdown
Collaborator

Summary

Adds a --single-dependency / -d flag to jhack sync that watches a local Python package directory and syncs changes into the charm's remote venv site-packages.

Closes #238

Usage

jhack sync opensearch/0 --single-dependency=./opensearch_single_kernel

Instead of the current workaround:

jhack sync --source ./opensearch_single_kernel/ \
  --remote-root /var/lib/juju/agents/unit-opensearch-0/charm/venv/lib/python3.12/site-packages/opensearch_single_kernel/

What it does

  1. Auto-detects the package name from pyproject.toml ([project].name or [tool.poetry].name) or setup.cfg ([metadata].name), with PEP 503 normalization (lowercase, hyphens → underscores). Falls back to the directory name.

  2. Discovers the remote Python version by listing <charm_venv>/lib/ on the target unit via juju ssh, so the user doesn't need to know or specify python3.12 vs python3.10 etc.

  3. Constructs the full remote path automatically:
    <venv>/lib/<python3.X>/site-packages/<pkg_name>/

  4. Validates flag incompatibilities — errors out early if combined with --venv, --remote-root, or --source (which are all overridden by --single-dependency).

Implementation details

  • New helpers: _resolve_package_name() and _discover_remote_python_version() in jhack/utils/sync.py
  • New local_root_override parameter on push_to_remote_juju_unit() to correctly map files outside CWD to remote paths (fully backward-compatible — defaults to os.getcwd() when unset)
  • All existing tests pass (208 passed)

Adds a --single-dependency/-d flag that watches a local Python package
directory and syncs changes into the charm's remote venv site-packages.

The package name is auto-detected from pyproject.toml/setup.cfg (with
PEP 503 normalization), falling back to the directory name. The remote
Python version is discovered by listing the venv/lib/ directory on the
target unit.

Mutually exclusive with --venv, --remote-root, and --source.

Closes #238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify a relative path to charm using jhack sync

1 participant