Skip to content

Commit

Permalink
Update to modern packaging
Browse files Browse the repository at this point in the history
Use pyproject.toml, uv, and hatchling.

This produces the following layout using

  uv pip install --no-deps --prefix=/tmp/test-prefix .`

  /tmp/test-prefix/.lock
  /tmp/test-prefix/bin/git-revise
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/merge.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/odb.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/__init__.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/utils.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/tui.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/todo.py
  /tmp/test-prefix/lib/python3.12/site-packages/gitrevise/__main__.py
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/INSTALLER
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/REQUESTED
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/licenses/LICENSE
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/direct_url.json
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/RECORD
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/entry_points.txt
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/WHEEL
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/METADATA
  /tmp/test-prefix/lib/python3.12/site-packages/git_revise-0.7.0.dist-info/uv_cache.json
  /tmp/test-prefix/share/man/man1/git-revise.1
  • Loading branch information
tamird committed Feb 11, 2025
1 parent 189c9fe commit 1913654
Show file tree
Hide file tree
Showing 13 changed files with 1,903 additions and 132 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox

- run: uv sync --all-extras --dev

- run: uv pip install tox tox-gh-actions

- run: uv run tox
env:
PLATFORM: ${{ matrix.os }}
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
uv run @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help man Makefile

# Copy generated manfile into project root for distribution.
man: Makefile
@$(SPHINXBUILD) -M man "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
uv run @$(SPHINXBUILD) -M man "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
cp "$(BUILDDIR)/man/git-revise.1" "$(SOURCEDIR)/.."

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
uv run @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@
# -- Extension configuration -------------------------------------------------


def setup(app):
def setup(app) -> None:
app.add_object_type("gitconfig", "gitconfig", objname="git config value")
24 changes: 12 additions & 12 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ for testing, and :command:`black` for code formatting.

.. code-block:: shell
$ tox # All python versions
$ tox -e py38 # Python 3.8
$ tox -e py39 # Python 3.9
$ tox -e py310 # Python 3.10
$ uv run tox # All python versions
$ uv run tox -e py38 # Python 3.8
$ uv run tox -e py39 # Python 3.9
$ uv run tox -e py310 # Python 3.10
$ tox -e mypy # Mypy Typechecking
$ tox -e lint # Linting
$ tox -e format # Check Formatting
$ uv run tox -e mypy # Mypy Typechecking
$ uv run tox -e lint # Linting
$ uv run tox -e format # Check Formatting
Code Formatting
---------------
Expand All @@ -26,8 +26,8 @@ This project uses ``isort`` and ``black`` for code formatting.

.. code-block:: shell
$ isort . # sort imports
$ black . # format all python code
$ uv run isort . # sort imports
$ uv run ruff format # format all python code
Building Documentation
----------------------
Expand All @@ -44,6 +44,6 @@ Publishing

.. code-block:: shell
$ python3 setup.py sdist bdist_wheel
$ twine check dist/*
$ twine upload dist/*
$ uv build
$ uv run twine check dist/*
$ uv run twine upload dist/*
11 changes: 6 additions & 5 deletions gitrevise/odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

if TYPE_CHECKING:
from subprocess import _FILE
from typing_extensions import Self


class MissingObject(Exception):
Expand Down Expand Up @@ -57,7 +58,7 @@ class Oid(bytes):
def __new__(cls, b: bytes) -> Oid:
if len(b) != 20:
raise ValueError("Expected 160-bit SHA1 hash")
return super().__new__(cls, b) # type: ignore
return super().__new__(cls, b)

@classmethod
def fromhex(cls, instr: str) -> Oid:
Expand Down Expand Up @@ -165,8 +166,8 @@ class Repository:
"""path to GnuPG binary"""

_objects: Dict[int, Dict[Oid, GitObj]]
_catfile: Popen
_tempdir: Optional[TemporaryDirectory]
_catfile: Popen[bytes]
_tempdir: Optional[TemporaryDirectory[str]]

__slots__ = [
"workdir",
Expand Down Expand Up @@ -480,7 +481,7 @@ class GitObj:

__slots__ = ("repo", "body", "oid", "persisted")

def __new__(cls: Type[GitObjT], repo: Repository, body: bytes) -> GitObjT:
def __new__(cls, repo: Repository, body: bytes) -> "Self":
oid = Oid.for_object(cls._git_type(), body)
cache = repo._objects[oid[0]] # pylint: disable=protected-access
if oid in cache:
Expand All @@ -495,7 +496,7 @@ def __new__(cls: Type[GitObjT], repo: Repository, body: bytes) -> GitObjT:
self.persisted = False
cache[oid] = self
self._parse_body() # pylint: disable=protected-access
return cast(GitObjT, self)
return self

@classmethod
def _git_type(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion gitrevise/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def noninteractive(

# Update the commit message on the target commit if requested.
if args.message:
message = b"\n".join(l.encode("utf-8") + b"\n" for l in args.message)
message = b"\n".join(line.encode("utf-8") + b"\n" for line in args.message)
current = current.update(message=message)

# Prompt the user to edit the commit message if requested.
Expand Down
65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "git-revise"
dynamic = ["version"]
requires-python = ">=3.8"
authors = [
{ name = "Nika Layzell", email = "[email protected]" },
]
description = "Efficiently update, split, and rearrange git commits"
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["git", "revise", "rebase", "amend", "fixup"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Environment :: Console",
"Topic :: Software Development :: Version Control",
"Topic :: Software Development :: Version Control :: Git",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]

[project.scripts]
git-revise = "gitrevise.tui:main"

[dependency-groups]
dev = [
"isort>=5.13.2",
"mypy>=1.14.1",
"pylint>=3.2.7",
"pytest-xdist>=3.6.1",
"pytest>=8.3.4",
"ruff>=0.9.6",
"sphinx>=7.1.2",
"tox-uv>=1.13.1",
"tox>=4.24.1",
"twine>=6.1.0",
"typing-extensions>=4.12.2",
]

[project.urls]
Homepage = "https://github.com/mystor/git-revise/"
Issues = "https://github.com/mystor/git-revise/issues/"
Repository = "https://github.com/mystor/git-revise/"
Documentation = "https://git-revise.readthedocs.io/en/latest/"

[tool.hatch.version]
path = "gitrevise/__init__.py"

[tool.hatch.build.targets.wheel]
packages = ["/gitrevise"]

[tool.hatch.build.targets.wheel.shared-data]
"git-revise.1" = "share/man/man1/git-revise.1"

[tool.hatch.build.targets.sdist]
include = [
"/gitrevise",
]
41 changes: 0 additions & 41 deletions setup.py

This file was deleted.

18 changes: 9 additions & 9 deletions tests/test_gpgsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ def test_gpgsign(

bash("git config commit.gpgSign true")
main(["HEAD"])
assert (
repo.get_commit("HEAD").gpgsig is not None
), "git config commit.gpgSign activates GPG signing"
assert repo.get_commit("HEAD").gpgsig is not None, (
"git config commit.gpgSign activates GPG signing"
)

bash("git config revise.gpgSign false")
main(["HEAD"])
assert (
repo.get_commit("HEAD").gpgsig is None
), "git config revise.gpgSign overrides commit.gpgSign"
assert repo.get_commit("HEAD").gpgsig is None, (
"git config revise.gpgSign overrides commit.gpgSign"
)

main(["HEAD", "--gpg-sign"])
assert (
repo.get_commit("HEAD").gpgsig is not None
), "commandline option overrides configuration"
assert repo.get_commit("HEAD").gpgsig is not None, (
"commandline option overrides configuration"
)

main(["HEAD", "--no-gpg-sign"])
assert repo.get_commit("HEAD").gpgsig is None, "long option"
Expand Down
Loading

0 comments on commit 1913654

Please sign in to comment.