Skip to content

Commit 5408ca5

Browse files
committed
docs(guides): Add async examples to README, quickstart, pytest-plugin
why: Help users discover and adopt async APIs. what: - Add async section to README with concurrent clone example - Add async quickstart examples with asyncio.run() patterns - Document async pytest fixtures in pytest-plugin guide
1 parent 1450748 commit 5408ca5

3 files changed

Lines changed: 136 additions & 0 deletions

File tree

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,46 @@ def test_my_git_tool(
149149
assert (checkout_path / ".git").is_dir()
150150
```
151151

152+
### 5. Async Support
153+
Run VCS operations asynchronously for better concurrency when managing multiple repositories.
154+
155+
[**Learn more about Async Support**](https://libvcs.git-pull.com/topics/asyncio.html)
156+
157+
```python
158+
import asyncio
159+
import pathlib
160+
from libvcs.sync._async.git import AsyncGitSync
161+
162+
async def main():
163+
repo = AsyncGitSync(
164+
url="https://github.com/vcs-python/libvcs",
165+
path=pathlib.Path.cwd() / "libvcs",
166+
)
167+
await repo.obtain()
168+
await repo.update_repo()
169+
170+
asyncio.run(main())
171+
```
172+
173+
Clone multiple repositories concurrently:
174+
175+
```python
176+
import asyncio
177+
from libvcs.sync._async.git import AsyncGitSync
178+
179+
async def clone_all(repos: list[tuple[str, str]]):
180+
tasks = [
181+
AsyncGitSync(url=url, path=path).obtain()
182+
for url, path in repos
183+
]
184+
await asyncio.gather(*tasks) # All clone in parallel
185+
186+
asyncio.run(clone_all([
187+
("https://github.com/vcs-python/libvcs", "./libvcs"),
188+
("https://github.com/vcs-python/vcspull", "./vcspull"),
189+
]))
190+
```
191+
152192
## Project Information
153193

154194
- **Python Support**: 3.10+

docs/pytest-plugin.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,64 @@ def setup(set_hgconfig: None):
131131
pass
132132
```
133133

134+
## Async Fixtures
135+
136+
For async testing with [pytest-asyncio], libvcs provides async fixture variants:
137+
138+
[pytest-asyncio]: https://pytest-asyncio.readthedocs.io/
139+
140+
### Configuration
141+
142+
Add pytest-asyncio to your test dependencies and configure strict mode:
143+
144+
```toml
145+
# pyproject.toml
146+
[tool.pytest.ini_options]
147+
asyncio_mode = "strict"
148+
asyncio_default_fixture_loop_scope = "function"
149+
```
150+
151+
### Available Async Fixtures
152+
153+
- {func}`async_git_repo` - An {class}`~libvcs.sync._async.git.AsyncGitSync` instance ready for testing
154+
- `async_create_git_remote_repo` - Factory to create temporary git repositories
155+
156+
### Usage Example
157+
158+
```python
159+
import pytest
160+
161+
@pytest.mark.asyncio
162+
async def test_async_repo_operations(async_git_repo):
163+
"""Test async repository operations."""
164+
# async_git_repo is an AsyncGitSync instance
165+
status = await async_git_repo.cmd.status()
166+
assert 'On branch' in status
167+
168+
# Update the repo
169+
await async_git_repo.update_repo()
170+
```
171+
172+
### Creating Repositories in Async Tests
173+
174+
```python
175+
import pytest
176+
from libvcs.sync._async.git import AsyncGitSync
177+
178+
@pytest.mark.asyncio
179+
async def test_clone_repo(tmp_path, create_git_remote_repo):
180+
"""Test cloning a repository asynchronously."""
181+
remote = create_git_remote_repo()
182+
repo = AsyncGitSync(
183+
url=f'file://{remote}',
184+
path=tmp_path / 'clone',
185+
)
186+
await repo.obtain()
187+
assert (tmp_path / 'clone' / '.git').exists()
188+
```
189+
190+
See {doc}`/topics/asyncio` for more async patterns.
191+
134192
## Examples
135193

136194
For usage examples, refer to libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests).

docs/quickstart.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,41 @@ origin.prune()
9898
```
9999

100100
See {doc}`/cmd/git/index` for the full API reference.
101+
102+
### Async Usage
103+
104+
All APIs have async equivalents for non-blocking operations:
105+
106+
```python
107+
import asyncio
108+
from libvcs.cmd._async.git import AsyncGit
109+
110+
async def main():
111+
git = AsyncGit(path='/path/to/repo')
112+
113+
# Non-blocking git operations
114+
await git.run(['init'])
115+
status = await git.status()
116+
print(status)
117+
118+
asyncio.run(main())
119+
```
120+
121+
For repository synchronization:
122+
123+
```python
124+
import asyncio
125+
from libvcs.sync._async.git import AsyncGitSync
126+
127+
async def main():
128+
repo = AsyncGitSync(
129+
url='https://github.com/vcs-python/libvcs',
130+
path='/tmp/libvcs',
131+
)
132+
await repo.obtain() # Clone
133+
await repo.update_repo() # Update
134+
135+
asyncio.run(main())
136+
```
137+
138+
See {doc}`/topics/asyncio` for the complete async guide.

0 commit comments

Comments
 (0)