Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

⚙️ Lite, typed, pythonic utilities for git, svn, mercurial, etc.

License

NotificationsYou must be signed in to change notification settings

vcs-python/libvcs

 
 

Repository files navigation

libvcs is a lite,typed, pythonic tool box fordetection and parsing of URLs, commanding, and syncing withgit,hg, andsvn. Powersvcspull.

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

Toget started, see thequickstart for more.

$pip install --user libvcs

URL Parser

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

Validate:

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

Parse and adjust a Git URL:

>>>fromlibvcs.url.gitimportGitURL>>>git_location=GitURL(url='git@github.com:vcs-python/libvcs.git')>>>git_locationGitURL(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:

>>>fromlibvcs.url.gitimportGitURL>>>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 theparser document.

Commands

Simplesubprocess wrappers aroundgit(1),hg(1),svn(1). Here isGit w/Git.clone:

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

Sync

Create aGitSyncobject of the project to inspect / checkout / update:

importpathlibfromlibvcs.sync.gitimportGitSyncrepo=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 localrepositories and working copies for git, svn, and mercurial. They are automatically cleaned up aftereach test.

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

importpathlibfromlibvcs.pytest_pluginimportCreateProjectCallbackFixtureProtocolfromlibvcs.sync.gitimportGitSyncdeftest_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()assertgit_repo.get_revision()=="initial"assertgit_repo_checkout_dir.exists()assertpathlib.Path(git_repo_checkout_dir/".git").exists()

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

Donations

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

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

More information

DocsBuild Status

About

⚙️ Lite, typed, pythonic utilities for git, svn, mercurial, etc.

Topics

Resources

License

Stars

Watchers

Forks

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp