CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-poetry-core

Poetry PEP 517 Build Backend for building Python packages with lightweight, compliant, self-contained build system

Pending
Overview
Eval results
Files

vcs-support.mddocs/

VCS Support

Version control system integration for handling Git repositories and dependency sources from VCS. Poetry Core provides Git support for accessing dependencies from version control systems.

Core Import

from poetry.core.vcs import get_vcs
from poetry.core.vcs.git import Git
``` { .api }

## Capabilities

### VCS Detection and Access

Detects and provides access to version control systems in a given directory.

```python { .api }
def get_vcs(directory: Path) -> Git | None:
    """
    Detect and return VCS instance for a directory.
    
    Args:
        directory: Path to check for VCS repository
        
    Returns:
        Git instance if directory is in a Git repository, None otherwise
        
    Note:
        Currently only supports Git repositories. Checks if directory
        is ignored by Git and returns None if so.
    """

Git Repository Operations

The Git class provides comprehensive Git repository operations for dependency handling and metadata extraction.

class Git:
    """
    Git version control system support for Poetry Core.
    
    Provides repository operations, URL parsing, and dependency handling
    for Git-based dependencies.
    """
    
    def __init__(self, work_dir: Path):
        """
        Initialize Git instance for a working directory.
        
        Args:
            work_dir: Path to Git repository root
        """
    
    @property
    def work_dir(self) -> Path:
        """Get the working directory path"""
    
    def clone(self, repository: str, dest: Path) -> str:
        """
        Clone a Git repository.
        
        Args:
            repository: Git repository URL
            dest: Destination path for clone
            
        Returns:
            Path to cloned repository
        """
    
    def checkout(self, rev: str, folder: Path | None = None) -> str:
        """
        Checkout specific revision.
        
        Args:
            rev: Git revision (branch, tag, commit hash)
            folder: Optional working directory
            
        Returns:
            Checked out revision hash
        """
    
    def rev_parse(self, rev: str, folder: Path | None = None) -> str:
        """
        Parse revision to get commit hash.
        
        Args:
            rev: Git revision to parse
            folder: Optional working directory
            
        Returns:
            Full commit hash
        """
    
    def get_ignored_files(self, folder: Path | None = None) -> list[str]:
        """
        Get list of files ignored by Git.
        
        Args:
            folder: Optional working directory
            
        Returns:
            List of ignored file paths
        """
    
    @classmethod
    def normalize_url(cls, url: str) -> str:
        """
        Normalize Git URL to standard format.
        
        Args:
            url: Git URL to normalize
            
        Returns:
            Normalized Git URL
        """
    
    @classmethod  
    def parse_url(cls, url: str) -> dict[str, str | None]:
        """
        Parse Git URL into components.
        
        Args:
            url: Git URL to parse
            
        Returns:
            Dictionary with URL components (protocol, resource, pathname, etc.)
        """

Usage Examples

Detecting VCS in Directory

from pathlib import Path
from poetry.core.vcs import get_vcs

# Check if current directory is in a Git repository
project_path = Path.cwd()
vcs = get_vcs(project_path)

if vcs:
    print(f"Found Git repository at: {vcs.work_dir}")
else:
    print("No VCS found or directory is ignored")

Working with Git Repositories

from pathlib import Path
from poetry.core.vcs.git import Git

# Initialize Git instance for repository
repo_path = Path("/path/to/repo")
git = Git(repo_path)

# Clone a repository
dest_path = Path("/tmp/cloned-repo")
git.clone("https://github.com/user/repo.git", dest_path)

# Checkout specific revision
commit_hash = git.checkout("v1.2.3")
print(f"Checked out: {commit_hash}")

# Parse revision to get full hash
full_hash = git.rev_parse("HEAD")
print(f"Current commit: {full_hash}")

# Get ignored files
ignored = git.get_ignored_files()
print(f"Ignored files: {ignored}")

URL Parsing and Normalization

from poetry.core.vcs.git import Git

# Parse Git URL
url = "git+https://github.com/user/repo.git@v1.2.3#egg=package"
parsed = Git.parse_url(url)
print(f"Protocol: {parsed['protocol']}")
print(f"Resource: {parsed['resource']}")
print(f"Revision: {parsed['rev']}")

# Normalize URL
normalized = Git.normalize_url("git@github.com:user/repo.git")
print(f"Normalized: {normalized}")

Git URL Formats

Poetry Core supports various Git URL formats:

Standard Git URLs

  • git://github.com/user/repo.git
  • git+ssh://git@github.com/user/repo.git
  • git+https://github.com/user/repo.git

SSH URLs

  • git@github.com:user/repo.git
  • ssh://git@github.com/user/repo.git

HTTP/HTTPS URLs

  • https://github.com/user/repo.git
  • http://example.com/repo.git

With Revisions and Subdirectories

  • git+https://github.com/user/repo.git@v1.2.3
  • git+https://github.com/user/repo.git@main#subdirectory=packages/core
  • git+https://github.com/user/repo.git@abc123#egg=package&subdirectory=src

Exceptions

class GitError(RuntimeError):
    """
    Raised when Git operations fail.
    
    This includes clone failures, checkout errors, revision parsing
    problems, and other Git command execution issues.
    """

Integration with Dependencies

The VCS support integrates with Poetry's dependency system through VCSDependency:

from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.constraints.version import parse_constraint

# Create VCS dependency
vcs_dep = VCSDependency(
    name="my-package",
    vcs="git", 
    source="https://github.com/user/repo.git",
    rev="v1.2.3",
    constraint=parse_constraint("*")
)

print(f"VCS: {vcs_dep.vcs}")
print(f"Source: {vcs_dep.source}")
print(f"Revision: {vcs_dep.rev}")

Install with Tessl CLI

npx tessl i tessl/pypi-poetry-core

docs

build-backend.md

builders.md

configuration.md

constraints.md

factory-core.md

index.md

json-validation.md

packages.md

utilities.md

vcs-support.md

version-system.md

tile.json