Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,46 @@ jobs:
pyversion: '3.11'
- name: Linux py312
pyversion: '3.12'
- name: Linux py313
pyversion: '3.13'
- name: Linux py314
pyversion: '3.14'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python ${{ matrix.pyversion }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.pyversion }}
- name: Install poetry
run: pip install "poetry>=1.4.2,<1.5"
- name: Install dependencies
run: poetry install
run: uv sync
- name: Lint
run: poetry run flake8
run: uv run ruff check
- name: Format
run: uv run ruff format --check
- name: Test
run: poetry run pytest -v --cov=patchdiff --cov-report=term-missing
run: uv run pytest -v --cov=patchdiff --cov-report=term-missing

build:
name: Build and test wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install poetry
run: pip install "poetry>=1.4.2,<1.5"
- name: Install dependencies
run: poetry install
run: uv sync
- name: Build wheel
run: poetry build
run: uv build
- name: Twine check
run: poetry run twine check dist/*
run: uvx twine check dist/*
- name: Upload wheel artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
path: dist
name: dist
Expand All @@ -71,33 +77,27 @@ jobs:
runs-on: ubuntu-latest
needs: [test, build]
if: success() && startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/patchdiff
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: Download wheel artifact
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: dist
- name: Get version from git ref
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Create GH release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: dist
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
token: ${{ secrets.GITHUB_TOKEN }}
files: |
dist/*.tar.gz
dist/*.whl
draft: true
prerelease: false
- name: Upload release assets
# Move back to official action after fix https://github.com/actions/upload-release-asset/issues/4
uses: AButler/upload-release-assets@v2.0
with:
release-tag: ${{ steps.get_version.outputs.VERSION }}
files: 'dist/*.tar.gz;dist/*.whl'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
__pycache__
.vscode
.coverage
dist
dist
uv.lock
4 changes: 2 additions & 2 deletions patchdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def pad(state, op, target=None):
"path": ptr.append(idx_token),
"value": op["value"],
}
return [ops + [full_op], padding + 1]
return [[*ops, full_op], padding + 1]
elif op["op"] == "remove":
full_op = {
"op": "remove",
"path": ptr.append(op["idx"] + padding),
}
return [ops + [full_op], padding - 1]
return [[*ops, full_op], padding - 1]
else:
replace_ptr = ptr.append(op["idx"] + padding)
replace_ops, _ = diff(op["original"], op["value"], replace_ptr)
Expand Down
9 changes: 5 additions & 4 deletions patchdiff/pointer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import re
from typing import Any, Hashable, List, Tuple

from .types import Diffable


tilde0_re = re.compile("~0")
tilde1_re = re.compile("~1")
tilde_re = re.compile("~")
Expand All @@ -19,7 +20,7 @@ def escape(token: str) -> str:


class Pointer:
def __init__(self, tokens: List[Hashable] = None) -> None:
def __init__(self, tokens: List[Hashable] | None = None) -> None:
if tokens is None:
tokens = []
self.tokens = tuple(tokens)
Expand All @@ -33,7 +34,7 @@ def __str__(self) -> str:
return "/" + "/".join(escape(str(t)) for t in self.tokens)

def __repr__(self) -> str:
return f"Pointer({repr(list(self.tokens))})"
return f"Pointer({list(self.tokens)!r})"

def __hash__(self) -> int:
return hash(self.tokens)
Expand Down Expand Up @@ -62,4 +63,4 @@ def evaluate(self, obj: Diffable) -> Tuple[Diffable, Hashable, Any]:

def append(self, token: Hashable) -> "Pointer":
"""append, creating new Pointer"""
return Pointer(self.tokens + (token,))
return Pointer((*self.tokens, token))
Loading