Skip to content

Commit

Permalink
move version into pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Aug 1, 2024
1 parent bc9fb41 commit 8dc2e63
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 77 deletions.
12 changes: 6 additions & 6 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ The same branch is used for the release candidate and the final release.
In the end, the release branch is merged into the main branch.

Update the version to the release candidate with the first being ``rc1`` (as opposed to 0).
In ``src/towncrier/_version.py`` the version is set using a PEP440 compliant string:
In ``pyproject.toml`` the version is set using a PEP440 compliant string:

__version__ = "19.9.0rc1"
version = "19.9.0rc1"

Run ``venv/bin/towncrier build --yes`` to generate the news release NEWS file.
Commit and push to the primary repository, not a fork.
Expand Down Expand Up @@ -84,9 +84,9 @@ Final release
Once the PR is approved, you can trigger the final release.

Update the version to the final version.
In ``src/towncrier/_version.py`` the version is set using a PEP440 compliant string:
In ``pyproject.toml`` the version is set using a PEP440 compliant string:

__version__ = "19.9.0"
version = "19.9.0"

Manually update the `NEWS.rst` file to include the final release version and date.
Usually it will look like this.
Expand Down Expand Up @@ -115,9 +115,9 @@ Similar to the release candidate, with the difference:
No need for another review request.

Update the version to the development version.
In ``src/towncrier/_version.py`` the version is set using a PEP440 compliant string:
In ``pyproject.toml`` the version is set using a PEP440 compliant string:

__version__ = "19.9.0.dev0"
version = "19.9.0.dev0"

Commit and push the changes.

Expand Down
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ build-backend = "hatchling.build"


[project]
dynamic = ["version"]
name = "towncrier"
# For dev - 23.11.0.dev0
# For RC - 23.11.0rc1 (release candidate starts at 1)
# For final - 23.11.0
# make sure to follow PEP440
version = "24.7.2.dev0"
description = "Building newsfiles for your project."
readme = "README.rst"
license = "MIT"
Expand Down Expand Up @@ -55,12 +59,6 @@ Tests = "https://github.com/twisted/towncrier/actions?query=branch%3Atrunk"
Coverage = "https://codecov.io/gh/twisted/towncrier"
Distribution = "https://pypi.org/project/towncrier"


[tool.hatch.version]
source = "code"
path = "src/towncrier/_version.py"
expression = "_hatchling_version"

[tool.hatch.build]
exclude = [
"admin",
Expand Down
24 changes: 0 additions & 24 deletions src/towncrier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,3 @@
"""
towncrier, a builder for your news files.
"""

from __future__ import annotations


__all__ = ["__version__"]


def __getattr__(name: str) -> str:
if name != "__version__":
raise AttributeError(f"module {__name__} has no attribute {name}")

import warnings

from ._version import __version__

warnings.warn(
"Accessing towncrier.__version__ is deprecated and will be "
"removed in a future release. Use importlib.metadata directly "
"to query for towncrier's packaging metadata.",
DeprecationWarning,
stacklevel=2,
)

return __version__
6 changes: 6 additions & 0 deletions src/towncrier/_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from __future__ import annotations

import contextlib
import importlib
import sys

from importlib import import_module
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as metadata_version
from types import ModuleType

Expand Down Expand Up @@ -67,6 +69,10 @@ def get_version(package_dir: str, package: str) -> str:
if version := _get_metadata_version(package):
return version

with contextlib.suppress(PackageNotFoundError):
if version := importlib.metadata.version(package):
return version

# When no version if found, fall back to looking for the package in `package_dir`.
module = _get_package(package_dir, package)
version = getattr(module, "__version__", None)
Expand Down
3 changes: 1 addition & 2 deletions src/towncrier/_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

import click

from ._version import __version__
from .build import _main as _build_cmd
from .check import _main as _check_cmd
from .click_default_group import DefaultGroup
from .create import _main as _create_cmd


@click.group(cls=DefaultGroup, default="build", default_if_no_args=True)
@click.version_option(__version__)
@click.version_option()
def cli() -> None:
"""
Towncrier is a utility to produce useful, summarised news files for your project.
Expand Down
12 changes: 0 additions & 12 deletions src/towncrier/_version.py

This file was deleted.

26 changes: 0 additions & 26 deletions src/towncrier/test/test_packaging.py

This file was deleted.

0 comments on commit 8dc2e63

Please sign in to comment.