Skip to main content

Lite, typed, python utilities for Git, SVN, Mercurial, etc.

Project description

libvcs · Python Package License Code Coverage

libvcs is a lite, typed, pythonic tool box for detection and parsing of URLs, commanding, and syncing with git, hg, and svn. Powers vcspull.

Overview

Supports Python 3.9 and above

Features for Git, Subversion, and Mercurial:

  • Detect and parse VCS URLs
  • Command VCS via python API
  • Sync repos locally
  • Test fixtures for temporary local repos and working copies

To get started, see the quickstart for more.

$ pip install --user libvcs

URL Parser

You can validate and parse Git, Mercurial, and Subversion URLs through libvcs.url:

Validate:

>>> from libvcs.url.git import GitURL

>>> GitURL.is_valid(url='https://github.com/vcs-python/libvcs.git')
True

Parse and adjust a Git URL:

>>> from libvcs.url.git import GitURL

>>> git_location = GitURL(url='git@github.com:vcs-python/libvcs.git')

>>> git_location
GitURL(url=git@github.com:vcs-python/libvcs.git,
        user=git,
        hostname=github.com,
        path=vcs-python/libvcs,
        suffix=.git,
        rule=core-git-scp)

Switch repo libvcs -> vcspull:

>>> from libvcs.url.git import GitURL

>>> git_location = GitURL(url='git@github.com:vcs-python/libvcs.git')

>>> git_location.path = 'vcs-python/vcspull'

>>> git_location.to_url()
'git@github.com:vcs-python/vcspull.git'

# Switch them to gitlab:
>>> git_location.hostname = 'gitlab.com'

# Export to a `git clone` compatible URL.
>>> git_location.to_url()
'git@gitlab.com:vcs-python/vcspull.git'

See more in the parser document.

Commands

Simple subprocess wrappers around git(1), hg(1), svn(1). Here is Git w/ Git.clone:

import pathlib
from libvcs.cmd.git import Git

git = Git(dir=pathlib.Path.cwd() / 'my_git_repo')
git.clone(url='https://github.com/vcs-python/libvcs.git')

Sync

Create a GitSync object of the project to inspect / checkout / update:

import pathlib
from libvcs.sync.git import GitSync

repo = GitSync(
   url="https://github.com/vcs-python/libvcs",
   dir=pathlib.Path().cwd() / "my_repo",
   remotes={
       'gitlab': 'https://gitlab.com/vcs-python/libvcs'
   }
)

# Update / clone repo:
>>> repo.update_repo()

# Get revision:
>>> repo.get_revision()
u'5c227e6ab4aab44bf097da2e088b0ff947370ab8'

Pytest plugin

libvcs also provides a test rig for local repositories. It automatically can provide clean local repositories and working copies for git, svn, and mercurial. They are automatically cleaned up after each test.

It works by bootstrapping a temporary $HOME environment in a TmpPathFactory for automatic cleanup.

import pathlib

from libvcs.pytest_plugin import CreateProjectCallbackFixtureProtocol
from libvcs.sync.git import GitSync


def test_repo_git_remote_checkout(
    create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
    tmp_path: pathlib.Path,
    projects_path: pathlib.Path,
) -> None:
    git_server = create_git_remote_repo()
    git_repo_checkout_dir = projects_path / "my_git_checkout"
    git_repo = GitSync(dir=str(git_repo_checkout_dir), url=f"file://{git_server!s}")

    git_repo.obtain()
    git_repo.update_repo()

    assert git_repo.get_revision() == "initial"

    assert git_repo_checkout_dir.exists()
    assert pathlib.Path(git_repo_checkout_dir / ".git").exists()

Learn more on the docs at https://libvcs.git-pull.com/pytest-plugin.html

Donations

Your donations fund development of new features, testing and support. Your money will go directly to maintenance and development of the project. If you are an individual, feel free to give whatever feels right for the value you get out of the project.

See donation options at https://www.git-pull.com/support.html.

More information

Docs Build Status

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libvcs-0.20.0.tar.gz (70.9 kB view details)

Uploaded Source

Built Distribution

libvcs-0.20.0-py3-none-any.whl (70.6 kB view details)

Uploaded Python 3

File details

Details for the file libvcs-0.20.0.tar.gz.

File metadata

  • Download URL: libvcs-0.20.0.tar.gz
  • Upload date:
  • Size: 70.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for libvcs-0.20.0.tar.gz
Algorithm Hash digest
SHA256 f45049b5d47209ce021d7e597d697dfe8f39fdbeb0e832c2e2a5d8426bdc465b
MD5 5a2ef932f8e6362c1564cf41d1e56bd7
BLAKE2b-256 4eb803009389080770c9b84ca53ffbcddc2b4ba29648b8f4cdbf5227e544998c

See more details on using hashes here.

Provenance

File details

Details for the file libvcs-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: libvcs-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 70.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for libvcs-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dff730ceb75cf396409ca105f282635807e9a953b383e5b94fd28a4a90e6cb7
MD5 8d1420b2ba90767248c8cec7081d850f
BLAKE2b-256 f9f8d9e6d53850dce5b1021f954c206403d467133e96e505b3cae7562a17b008

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page