Skip to content

Commit

Permalink
Merge pull request #766 from twisted/fix-for-release
Browse files Browse the repository at this point in the history
fix the release script up a little bit before releasing
  • Loading branch information
glyph authored Aug 12, 2024
2 parents 861a2d0 + 89fada0 commit 28d1b83
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 22 deletions.
22 changes: 18 additions & 4 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from subprocess import CalledProcessError, run
from sys import exit, stderr
from tempfile import mkdtemp
from typing import Any, Dict, NoReturn, Optional, Sequence, cast
from typing import Any, Dict, NoReturn, Optional, Sequence

from click import group as commandGroup
from click import option as commandOption
Expand Down Expand Up @@ -59,7 +59,8 @@ def currentVersion() -> Version:
versionInfo: Dict[str, Any] = {}
versonFile = Path(__file__).parent / "src" / "klein" / "_version.py"
exec(versonFile.read_text(), versionInfo)
return versionInfo["__version__"]
version: Version = versionInfo["__version__"]
return version


def fadeToBlack() -> None:
Expand Down Expand Up @@ -109,7 +110,7 @@ def releaseTagName(version: Version) -> str:
"""
Compute the name of the release tag for the given version.
"""
return cast(str, version.public())
return version.public()


def createReleaseBranch(repository: Repository, version: Version) -> Head:
Expand Down Expand Up @@ -286,22 +287,32 @@ def publishRelease(final: bool, test: bool = False) -> None:

print("Pushing tag to origin:", tag)
repository.remotes.origin.push(refspec=tag.path)
print("Pushing branch to origin:", branch)
repository.remotes.origin.push()

distribute(repository, tag, test=test)


@commandGroup()
def main() -> None:
pass
"""
Software release tool for Klein.
"""


@main.command()
def start() -> None:
"""
Begin a new release process.
"""
startRelease()


@main.command()
def bump() -> None:
"""
Increase the version number for an in-progress release candidate.
"""
bumpRelease()


Expand All @@ -317,6 +328,9 @@ def bump() -> None:
default=False,
)
def publish(final: bool, test: bool) -> None:
"""
Publish the current version of the software to PyPI.
"""
publishRelease(final=final, test=test)


Expand Down
3 changes: 2 additions & 1 deletion requirements/tox-pin-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Automat==22.10.0
characteristic==14.3.0
constantly==15.1.0
hyperlink==21.0.0
incremental==21.3.0
incremental==22.10.0; python_version <= '3.7'
incremental==24.7.2; python_version > '3.7'
PyHamcrest==2.1.0
six==1.16.0
Tubes==0.2.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
),
url="https://github.com/twisted/klein",
maintainer="Twisted Matrix Laboratories",
maintainer_email="twisted-python@twistedmatrix.com",
maintainer_email="twisted@python.org",
zip_safe=False,
)
4 changes: 2 additions & 2 deletions src/klein/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def url_for(
registerAdapter(KleinRequest, Request, IKleinRequest)


ErrorHandlers = List[Tuple[List[Type[Exception]], KleinErrorHandler]]
ErrorMethods = List[Tuple[List[Type[Exception]], KleinErrorMethod]]


# begin argument-processing hack to copy all args from current installed
Expand Down Expand Up @@ -271,7 +271,7 @@ class Klein:
def __init__(self) -> None:
self._url_map = Map()
self._endpoints: Dict[str, KleinRouteHandler] = {}
self._error_handlers: ErrorHandlers = []
self._error_handlers: ErrorMethods = []
self._instance: Optional[Klein] = None
self._boundAs: Optional[str] = None

Expand Down
7 changes: 4 additions & 3 deletions src/klein/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if TYPE_CHECKING:
# NB: circular import, must not be imported at runtime.
from ._app import (
ErrorHandlers,
ErrorMethods,
Klein,
KleinRenderable,
KleinRouteHandler,
Expand Down Expand Up @@ -250,7 +250,7 @@ def process(r: object) -> Any:
d.addCallback(process)

def processing_failed(
failure: Failure, error_handlers: ErrorHandlers
failure: Failure, error_handlers: ErrorMethods
) -> Optional[Deferred]:
# The failure processor writes to the request. If the
# request is already finished we should suppress failure
Expand Down Expand Up @@ -288,9 +288,10 @@ def processing_failed(
# Each error handler is a tuple of
# (list_of_exception_types, handler_fn)
if failure.check(*error_handler[0]):
handler_func = error_handler[1]
d = maybeDeferred(
self._app.execute_error_handler,
error_handler[1], # type: ignore[arg-type]
handler_func,
request,
failure,
)
Expand Down
22 changes: 12 additions & 10 deletions src/klein/test/test_resource.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
from io import BytesIO
from types import MappingProxyType
Expand Down Expand Up @@ -153,16 +155,16 @@ def __init__(self, name: str) -> None:
self._name = name

@renderer
def name(self, request: IRequest, tag: Tag) -> Tag:
def name(self, request: IRequest, tag: Tag) -> Tag | Deferred[None]:
return tag(self._name)


class DeferredElement(SimpleElement):
deferred: "Deferred[None]"
deferred: Deferred[None]

@renderer
def name(self, request: IRequest, tag: Tag) -> "Deferred[None]":
self.deferred: "Deferred[None]" = Deferred()
def name(self, request: IRequest, tag: Tag) -> Deferred[None]:
self.deferred: Deferred[None] = Deferred()
self.deferred.addCallback(lambda ignored: tag(self._name))
return self.deferred

Expand Down Expand Up @@ -387,7 +389,7 @@ def wooo(request: IRequest) -> KleinRenderable:
def test_deferredRendering(self) -> None:
app = self.app

deferredResponse: "Deferred[bytes]" = Deferred()
deferredResponse: Deferred[bytes] = Deferred()

@app.route("/deferred")
def deferred(request: IRequest) -> KleinRenderable:
Expand Down Expand Up @@ -1011,7 +1013,7 @@ def test_requestFinishAfterConnectionLost(self) -> None:
app = self.app
request = MockRequest(b"/")

finished: "Deferred[bytes]" = Deferred()
finished: Deferred[bytes] = Deferred()

@app.route("/")
def root(request: IRequest) -> KleinRenderable:
Expand Down Expand Up @@ -1050,7 +1052,7 @@ def test_routeHandlesRequestFinished(self) -> None:
@app.route("/")
def root(request: IRequest) -> KleinRenderable:
assert isinstance(request, Request)
_d: "Deferred[bytes]" = Deferred()
_d: Deferred[bytes] = Deferred()
_d.addErrback(cancelled.append)
request.notifyFinish().addCallback(lambda _: _d.cancel())
return _d
Expand Down Expand Up @@ -1090,7 +1092,7 @@ def test_cancelledDeferred(self) -> None:
app = self.app
request = MockRequest(b"/")

inner_d: "Deferred[bytes]" = Deferred()
inner_d: Deferred[bytes] = Deferred()

@app.route("/")
def root(request: IRequest) -> KleinRenderable:
Expand Down Expand Up @@ -1128,7 +1130,7 @@ def test_cancelledIsEatenOnConnectionLost(self) -> None:

@app.route("/")
def root(request: IRequest) -> KleinRenderable:
_d: "Deferred[bytes]" = Deferred()
_d: Deferred[bytes] = Deferred()
assert isinstance(request, Request)
request.notifyFinish().addErrback(lambda _: _d.cancel())
return _d
Expand All @@ -1154,7 +1156,7 @@ def test_cancelsOnConnectionLost(self) -> None:
app = self.app
request = MockRequest(b"/")

handler_d: "Deferred[bytes]" = Deferred()
handler_d: Deferred[bytes] = Deferred()

@app.route("/")
def root(request: IRequest) -> KleinRenderable:
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

envlist =
lint, mypy
coverage-py{37,38,39,310,311,312,py3}-tw{212,221,238,trunk}
coverage-py{38,39,310,311,312,py3}-tw{212,221,238,trunk}
coverage-py37-tw{212,221,238}
coverage_report
docs, docs-linkcheck
packaging
Expand Down

0 comments on commit 28d1b83

Please sign in to comment.