-
Notifications
You must be signed in to change notification settings - Fork 11
git init
compatibility, Git.version()
#491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tony
wants to merge
13
commits into
master
Choose a base branch
from
git-init-compatibility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2345aeb
pyproject(doctest) Use list, reruns
tony 8abeebd
ai(rules[claude]) Add `CLAUDE.md` for claude code
tony 975feca
ai(rules[claude]) Update instructions
tony 38c8ec7
_vendor: Add `Version` object from `packaging`
tony 78dedad
Git(feat[version]): Add structured version info via build_options()
tony 56aff59
docs(CHANGES) Note `version()`
tony b36b939
!squash more
tony a863883
!squash test_git
tony f1a5e76
docs(CHANGES) Note `version()` returning `Version`
tony ebf115a
!squash git version
tony 3c854f7
docs(CHANGES) Note `version()` returning `Version`
tony 544534a
docs(MIGRATION) Note `version()` returning `Version`
tony 28bf62b
.tool-versions(uv) uv 0.7.3 -> 0.7.5
tony File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
uv 0.7.3 | ||
uv 0.7.5 | ||
python 3.13.3 3.12.10 3.11.12 3.10.17 3.9.22 3.8.20 3.7.17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,259 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
||
## CRITICAL REQUIREMENTS | ||
|
||
### Test Success | ||
- ALL tests MUST pass for code to be considered complete and working | ||
- Never describe code as "working as expected" if there are ANY failing tests | ||
- Even if specific feature tests pass, failing tests elsewhere indicate broken functionality | ||
- Changes that break existing tests must be fixed before considering implementation complete | ||
- A successful implementation must pass linting, type checking, AND all existing tests | ||
|
||
## Project Overview | ||
|
||
libvcs is a lite, typed Python tool for: | ||
- Detecting and parsing URLs for Git, Mercurial, and Subversion repositories | ||
- Providing command abstractions for git, hg, and svn | ||
- Synchronizing repositories locally | ||
- Creating pytest fixtures for testing with temporary repositories | ||
|
||
The library powers [vcspull](https://www.github.com/vcs-python/vcspull/), a tool for managing and synchronizing multiple git, svn, and mercurial repositories. | ||
|
||
## Development Environment | ||
|
||
This project uses: | ||
- Python 3.9+ | ||
- [uv](https://github.com/astral-sh/uv) for dependency management | ||
- [ruff](https://github.com/astral-sh/ruff) for linting and formatting | ||
- [mypy](https://github.com/python/mypy) for type checking | ||
- [pytest](https://docs.pytest.org/) for testing | ||
|
||
## Common Commands | ||
|
||
### Setting Up Environment | ||
|
||
```bash | ||
# Install dependencies | ||
uv pip install --editable . | ||
uv pip sync | ||
|
||
# Install with development dependencies | ||
uv pip install --editable . -G dev | ||
``` | ||
|
||
### Running Tests | ||
|
||
```bash | ||
# Run all tests | ||
make test | ||
# or directly with pytest | ||
uv run pytest | ||
|
||
# Run a single test file | ||
uv run pytest tests/sync/test_git.py | ||
|
||
# Run a specific test | ||
uv run pytest tests/sync/test_git.py::test_remotes | ||
|
||
# Run tests with test watcher | ||
make start | ||
# or | ||
uv run ptw . | ||
``` | ||
|
||
### Linting and Type Checking | ||
|
||
```bash | ||
# Run ruff for linting | ||
make ruff | ||
# or directly | ||
uv run ruff check . | ||
|
||
# Format code with ruff | ||
make ruff_format | ||
# or directly | ||
uv run ruff format . | ||
|
||
# Run ruff linting with auto-fixes | ||
uv run ruff check . --fix --show-fixes | ||
|
||
# Run mypy for type checking | ||
make mypy | ||
# or directly | ||
uv run mypy src tests | ||
|
||
# Watch mode for linting (using entr) | ||
make watch_ruff | ||
make watch_mypy | ||
``` | ||
|
||
### Development Workflow | ||
|
||
Follow this workflow for code changes: | ||
|
||
1. **Format First**: `uv run ruff format .` | ||
2. **Run Tests**: `uv run pytest` | ||
3. **Run Linting**: `uv run ruff check . --fix --show-fixes` | ||
4. **Check Types**: `uv run mypy` | ||
5. **Verify Tests Again**: `uv run pytest` | ||
|
||
### Documentation | ||
|
||
```bash | ||
# Build documentation | ||
make build_docs | ||
|
||
# Start documentation server with auto-reload | ||
make start_docs | ||
|
||
# Update documentation CSS/JS | ||
make design_docs | ||
``` | ||
|
||
## Code Architecture | ||
|
||
libvcs is organized into three main modules: | ||
|
||
1. **URL Detection and Parsing** (`libvcs.url`) | ||
- Base URL classes in `url/base.py` | ||
- VCS-specific implementations in `url/git.py`, `url/hg.py`, and `url/svn.py` | ||
- URL registry in `url/registry.py` | ||
- Constants in `url/constants.py` | ||
|
||
2. **Command Abstraction** (`libvcs.cmd`) | ||
- Command classes for git, hg, and svn in `cmd/git.py`, `cmd/hg.py`, and `cmd/svn.py` | ||
- Built on top of Python's subprocess module (via `_internal/subprocess.py`) | ||
|
||
3. **Repository Synchronization** (`libvcs.sync`) | ||
- Base sync classes in `sync/base.py` | ||
- VCS-specific sync implementations in `sync/git.py`, `sync/hg.py`, and `sync/svn.py` | ||
|
||
4. **Internal Utilities** (`libvcs._internal`) | ||
- Subprocess wrappers in `_internal/subprocess.py` | ||
- Data structures in `_internal/dataclasses.py` and `_internal/query_list.py` | ||
- Runtime helpers in `_internal/run.py` and `_internal/shortcuts.py` | ||
|
||
5. **pytest Plugin** (`libvcs.pytest_plugin`) | ||
- Provides fixtures for creating temporary repositories for testing | ||
|
||
## Testing Strategy | ||
|
||
libvcs uses pytest for testing with many custom fixtures. The pytest plugin (`pytest_plugin.py`) defines fixtures for creating temporary repositories for testing. These include: | ||
|
||
- `create_git_remote_repo`: Creates a git repository for testing | ||
- `create_hg_remote_repo`: Creates a Mercurial repository for testing | ||
- `create_svn_remote_repo`: Creates a Subversion repository for testing | ||
- `git_repo`, `svn_repo`, `hg_repo`: Pre-made repository instances | ||
- `set_home`, `gitconfig`, `hgconfig`, `git_commit_envvars`: Environment fixtures | ||
|
||
These fixtures handle setup and teardown automatically, creating isolated test environments. | ||
|
||
For running tests with actual VCS commands, tests will be skipped if the corresponding VCS binary is not installed. | ||
|
||
### Example Fixture Usage | ||
|
||
```python | ||
def test_repo_sync(git_repo): | ||
# git_repo is already a GitSync instance with a clean repository | ||
# Use it directly in your tests | ||
assert git_repo.get_revision() == "initial" | ||
``` | ||
|
||
### Parameterized Tests | ||
|
||
Use `typing.NamedTuple` for parameterized tests: | ||
|
||
```python | ||
class RepoFixture(t.NamedTuple): | ||
test_id: str # For test naming | ||
repo_args: dict[str, t.Any] | ||
expected_result: str | ||
|
||
@pytest.mark.parametrize( | ||
list(RepoFixture._fields), | ||
REPO_FIXTURES, | ||
ids=[test.test_id for test in REPO_FIXTURES], | ||
) | ||
def test_sync( | ||
# Parameters and fixtures... | ||
): | ||
# Test implementation | ||
``` | ||
|
||
## Coding Standards | ||
|
||
### Imports | ||
|
||
- Use namespace imports: `import enum` instead of `from enum import Enum` | ||
- For typing, use `import typing as t` and access via namespace: `t.NamedTuple`, etc. | ||
- Use `from __future__ import annotations` at the top of all Python files | ||
|
||
### Docstrings | ||
|
||
Follow NumPy docstring style for all functions and methods: | ||
|
||
```python | ||
"""Short description of the function or class. | ||
|
||
Detailed description using reStructuredText format. | ||
|
||
Parameters | ||
---------- | ||
param1 : type | ||
Description of param1 | ||
param2 : type | ||
Description of param2 | ||
|
||
Returns | ||
------- | ||
type | ||
Description of return value | ||
""" | ||
``` | ||
|
||
### Git Commit Standards | ||
|
||
Format commit messages as: | ||
``` | ||
Component/File(commit-type[Subcomponent/method]): Concise description | ||
|
||
why: Explanation of necessity or impact. | ||
what: | ||
- Specific technical changes made | ||
- Focused on a single topic | ||
|
||
refs: #issue-number, breaking changes, or relevant links | ||
``` | ||
|
||
Common commit types: | ||
- **feat**: New features or enhancements | ||
- **fix**: Bug fixes | ||
- **refactor**: Code restructuring without functional change | ||
- **docs**: Documentation updates | ||
- **chore**: Maintenance (dependencies, tooling, config) | ||
- **test**: Test-related updates | ||
- **style**: Code style and formatting | ||
|
||
Example: | ||
``` | ||
url/git(feat[GitURL]): Add support for custom SSH port syntax | ||
|
||
why: Enable parsing of Git URLs with custom SSH ports | ||
what: | ||
- Add port capture to SCP_REGEX pattern | ||
- Update GitURL.to_url() to include port if specified | ||
- Add tests for the new functionality | ||
|
||
refs: #123 | ||
``` | ||
|
||
## Debugging Tips | ||
|
||
When stuck in debugging loops: | ||
|
||
1. **Pause and acknowledge the loop** | ||
2. **Minimize to MVP**: Remove all debugging cruft and experimental code | ||
3. **Document the issue** comprehensively for a fresh approach | ||
4. **Format for portability** (using quadruple backticks) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# via https://github.com/pypa/packaging/blob/22.0/packaging/_structures.py | ||
# This file is dual licensed under the terms of the Apache License, Version | ||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
# for complete details. | ||
from __future__ import annotations | ||
|
||
|
||
class InfinityType: | ||
def __repr__(self) -> str: | ||
return "Infinity" | ||
|
||
def __hash__(self) -> int: | ||
return hash(repr(self)) | ||
|
||
def __lt__(self, other: object) -> bool: | ||
return False | ||
|
||
def __le__(self, other: object) -> bool: | ||
return False | ||
|
||
def __eq__(self, other: object) -> bool: | ||
return isinstance(other, self.__class__) | ||
|
||
def __gt__(self, other: object) -> bool: | ||
return True | ||
|
||
def __ge__(self, other: object) -> bool: | ||
return True | ||
|
||
def __neg__(self: object) -> NegativeInfinityType: | ||
return NegativeInfinity | ||
|
||
|
||
Infinity = InfinityType() | ||
|
||
|
||
class NegativeInfinityType: | ||
def __repr__(self) -> str: | ||
return "-Infinity" | ||
|
||
def __hash__(self) -> int: | ||
return hash(repr(self)) | ||
|
||
def __lt__(self, other: object) -> bool: | ||
return True | ||
|
||
def __le__(self, other: object) -> bool: | ||
return True | ||
|
||
def __eq__(self, other: object) -> bool: | ||
return isinstance(other, self.__class__) | ||
|
||
def __gt__(self, other: object) -> bool: | ||
return False | ||
|
||
def __ge__(self, other: object) -> bool: | ||
return False | ||
|
||
def __neg__(self: object) -> InfinityType: | ||
return Infinity | ||
|
||
|
||
NegativeInfinity = NegativeInfinityType() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): Potential Markdown formatting typo.
There's an extra asterisk in
MVP**:
. For proper bolding use**MVP**:
.