Poetry PEP 517 Build Backend for building Python packages with lightweight, compliant, self-contained build system
—
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.
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.
"""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.)
"""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")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}")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}")Poetry Core supports various Git URL formats:
git://github.com/user/repo.gitgit+ssh://git@github.com/user/repo.gitgit+https://github.com/user/repo.gitgit@github.com:user/repo.gitssh://git@github.com/user/repo.githttps://github.com/user/repo.githttp://example.com/repo.gitgit+https://github.com/user/repo.git@v1.2.3git+https://github.com/user/repo.git@main#subdirectory=packages/coregit+https://github.com/user/repo.git@abc123#egg=package&subdirectory=srcclass GitError(RuntimeError):
"""
Raised when Git operations fail.
This includes clone failures, checkout errors, revision parsing
problems, and other Git command execution issues.
"""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