Pyvers

0.2.2 · active · verified Sat Apr 11

Pyvers is a Python library designed to manage multiple versions of project dependencies locally within a `.pyvers` directory. It helps isolate project environments and ensures consistent dependency versions across development teams. The current version is 0.2.2, with releases occurring periodically, focusing on core functionality and stability.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Pyvers project, add a dependency to its configuration, list current dependencies, and then install them into the local `.pyvers` environment. It sets up a temporary directory to avoid affecting your current workspace.

import os
import shutil
import json
from pyvers import Pyvers

temp_project_name = "my_pyvers_project_quickstart"
project_root = os.path.join(os.getcwd(), temp_project_name)

# Clean up previous run if exists
if os.path.exists(project_root):
    shutil.rmtree(project_root)

os.makedirs(project_root)
print(f"Created temporary project directory: {project_root}")

try:
    pyvers_manager = Pyvers(project_path=project_root)

    # 1. Initialize the Pyvers project
    print("Initializing Pyvers project...")
    pyvers_manager.init()
    print(f"Pyvers project initialized at {os.path.join(project_root, '.pyvers')}")

    # 2. Add a dependency to the pyvers.json config
    dep_name = "requests"
    dep_version = "2.28.1"
    print(f"Adding dependency: {dep_name}@{dep_version} (type='prod')...")
    pyvers_manager.add_dependency(name=dep_name, version=dep_version, dep_type="prod")
    print(f"Dependency '{dep_name}' added to config.")

    # 3. List dependencies from the config
    print("\nListing dependencies from config:")
    deps = pyvers_manager.list_dependencies()
    if deps:
        for dep in deps:
            print(f"  - {dep.name} @ {dep.version} ({dep.type})")
    else:
        print("  No dependencies found in config.")
    
    # 4. Install dependencies (creates/updates local virtual environment)
    print("\nInstalling dependencies...")
    # In a real scenario, this would install the added 'requests' package into '.pyvers/env'
    # For this quickstart, we just demonstrate the call.
    pyvers_manager.install()
    print("Dependencies installed to local .pyvers environment.")

finally:
    # Clean up the temporary directory
    if os.path.exists(project_root):
        shutil.rmtree(project_root)
        print(f"\nCleaned up temporary project directory: {project_root}")

view raw JSON →