Skip to content

feat: support editable harp install in generated projects #810

@hartym

Description

@hartym

Summary

When running harp create project from an editable/development install of harp, the generated project should use the same editable install by default. This enables a seamless development workflow where changes to harp are immediately reflected in generated projects.

Context

Current behavior: Generated projects always depend on "harp-proxy" from PyPI.

Desired behavior: Auto-detect if harp is installed as editable and generate appropriate dependency.

Files involved:

  • harp/commandline/create.py - command implementation
  • harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/pyproject.toml - template

Implementation

Detection Logic

Check if harp is running from a development environment:

from harp import ROOT_DIR
import os

def is_editable_install():
    """Detect if harp is installed as editable (development mode)."""
    return os.path.exists(os.path.join(ROOT_DIR, ".git"))

CLI Changes

Add --pypi flag to force PyPI version even when editable is detected:

@click.option("--pypi", is_flag=True, help="Force PyPI dependency even if running from editable install")
def create(template, name, no_app, no_config, pypi):

Template Changes

Update cookiecutter.json to include new variable:

{
  "harp_dependency": "harp-proxy",
  ...
}

Update pyproject.toml template:

dependencies = [
    "{{cookiecutter.harp_dependency}}",
]

Dependency Generation

from harp import ROOT_DIR

if pypi or not is_editable_install():
    harp_dependency = "harp-proxy"
else:
    # Editable install: use absolute file:// URL
    harp_dependency = f"harp-proxy @ file://{ROOT_DIR}"

extra_context["harp_dependency"] = harp_dependency

Behavior Matrix

Current Install --pypi flag Result
PyPI No "harp-proxy"
PyPI Yes "harp-proxy"
Editable No "harp-proxy @ file:///path/to/harp"
Editable Yes "harp-proxy"

Testing Scenarios

  1. PyPI install: Generated project has "harp-proxy" dependency
  2. Editable install: Generated project has "harp-proxy @ file:///path/to/harp" dependency
  3. Editable with --pypi: Generated project has "harp-proxy" dependency

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions