Skip to content

workenv

wrknv.wenv.workenv

Workenv Management

Manages wrknv's own virtual environment.

Classes

WorkenvManager

Manages wrknv's own workenv virtual environment.

Functions
create_workenv classmethod
create_workenv(
    base_path: Path | None = None, force: bool = False
) -> Path

Create a new workenv virtual environment.

Source code in wrknv/wenv/workenv.py
@classmethod
def create_workenv(cls, base_path: Path | None = None, force: bool = False) -> Path:
    """Create a new workenv virtual environment."""
    workenv_path = cls.get_workenv_path(base_path)

    if workenv_path.exists() and not force:
        print_info(f"Workenv already exists at {workenv_path}", Emoji.SUCCESS)
        return workenv_path

    if workenv_path.exists() and force:
        print_info(f"Removing existing workenv at {workenv_path}", Emoji.CLEAN)
        shutil.rmtree(workenv_path)

    print_info(f"Creating workenv at {workenv_path}", Emoji.BUILD)
    workenv_path.parent.mkdir(parents=True, exist_ok=True)

    # Create virtual environment
    run(
        [sys.executable, "-m", "venv", str(workenv_path)],
        check=True,
    )

    # Install wrknv in development mode
    pip_path = cls._get_pip_path(workenv_path)
    wrknv_root = Path(__file__).parent.parent.parent.parent

    print_info("Installing wrknv in development mode...", Emoji.INSTALL)
    run(
        [str(pip_path), "install", "-e", str(wrknv_root)],
        check=True,
    )

    # Install development dependencies
    print_info("Installing development dependencies...", Emoji.PACKAGE)
    run(
        [str(pip_path), "install", "-e", f"{wrknv_root}[dev]"],
        check=True,
    )

    print_success(f"Workenv created successfully at {workenv_path}", Emoji.SUCCESS)
    return workenv_path
generate_env_scripts classmethod
generate_env_scripts(
    base_path: Path | None = None,
) -> dict[str, Path]

Generate env.sh and env.ps1 scripts for the workenv.

Source code in wrknv/wenv/workenv.py
    @classmethod
    def generate_env_scripts(cls, base_path: Path | None = None) -> dict[str, Path]:
        """Generate env.sh and env.ps1 scripts for the workenv."""
        if base_path is None:
            base_path = Path.cwd()

        workenv_name = cls.get_workenv_name()

        # For now, skip the template generation due to Jinja2 issues
        # Just create simple activation scripts
        scripts = {}

        # Create simple env.sh if it doesn't exist
        env_sh_path = base_path / "env.sh"
        if not env_sh_path.exists():
            env_sh_content = f"""#!/usr/bin/env bash
# Generated by wrknv - Simple activation script

# Activate the workenv
source workenv/{workenv_name}/bin/activate

echo "   Python: $(which python)"
echo "   wrknv: $(which wrknv)"
"""
            env_sh_path.write_text(env_sh_content)
            env_sh_path.chmod(0o755)
        scripts["env.sh"] = env_sh_path

        # Create simple env.ps1
        env_ps1_path = base_path / "env.ps1"
        env_ps1_content = f"""# Generated by wrknv - Simple activation script

# Activate the workenv
& workenv\\{workenv_name}\\Scripts\\Activate.ps1

Write-Host "   Python: $(Get-Command python | Select-Object -ExpandProperty Source)"
Write-Host "   wrknv: $(Get-Command wrknv | Select-Object -ExpandProperty Source)"
"""
        env_ps1_path.write_text(env_ps1_content)
        scripts["env.ps1"] = env_ps1_path

        print_success("Generated activation scripts:", Emoji.SUCCESS)
        print_info(f"  • env.sh: {env_sh_path}", Emoji.CONFIG)
        print_info(f"  • env.ps1: {env_ps1_path}", Emoji.CONFIG)

        return scripts
get_workenv_name classmethod
get_workenv_name() -> str

Get the workenv name for current platform.

Source code in wrknv/wenv/workenv.py
@classmethod
def get_workenv_name(cls) -> str:
    """Get the workenv name for current platform."""
    system = platform.system().lower()
    machine = platform.machine().lower()

    # Normalize platform names
    if system == "darwin":
        system = "darwin"
    elif system == "linux":
        system = "linux"
    elif system == "windows":
        system = "windows"
    else:
        system = system

    # Normalize architecture
    if machine in ("x86_64", "amd64"):
        machine = "amd64"
    elif machine in ("arm64", "aarch64"):
        machine = "arm64"
    else:
        machine = machine

    return f"wrknv_{system}_{machine}"
get_workenv_path classmethod
get_workenv_path(base_path: Path | None = None) -> Path

Get the path to the workenv directory.

Source code in wrknv/wenv/workenv.py
@classmethod
def get_workenv_path(cls, base_path: Path | None = None) -> Path:
    """Get the path to the workenv directory."""
    if base_path is None:
        base_path = Path.cwd()
    return base_path / "workenv" / cls.get_workenv_name()
setup_workenv classmethod
setup_workenv(
    base_path: Path | None = None, force: bool = False
) -> None

Complete workenv setup including creation and scripts.

Source code in wrknv/wenv/workenv.py
@classmethod
def setup_workenv(cls, base_path: Path | None = None, force: bool = False) -> None:
    """Complete workenv setup including creation and scripts."""
    # Create workenv
    cls.create_workenv(base_path, force)

    # Generate activation scripts
    cls.generate_env_scripts(base_path)

    # Print usage instructions
    print_info("\nTo activate the workenv:", Emoji.INFO)
    if platform.system() == "Windows":
        print_info("  PowerShell: .\\env.ps1", Emoji.CONFIG)
    else:
        print_info("  Bash/Zsh: source ./env.sh", Emoji.CONFIG)

Functions