Skip to content

Commit

Permalink
Switch to hatchling (#472)
Browse files Browse the repository at this point in the history
* Switch to hatchling

* Add news fragment

* Duplicate exclude pattern from MANIFEST.in

Also rename .readthedocs.yml to its un-deprecated name

* Ignore a few more common patterns

* Style

* Fix build (no need for check-manifest anymore)

* Stop checking manifest in ci too

* Style

* Update src/towncrier/_version.py

Co-authored-by: Adi Roiban <adi.roiban@chevah.com>

* Deprecate towncrier.__version__

* Fix type

---------

Co-authored-by: Adi Roiban <adi.roiban@chevah.com>
  • Loading branch information
hynek and adiroiban committed Jan 29, 2023
1 parent ffe38a1 commit 65d25e0
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 128 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ jobs:
- name: Check Newsfragment
nox: check_newsfragment
run-if: ${{ github.head_ref != 'pre-commit-ci-update-config' }}
- name: Check package manifest
nox: check_manifest
run-if: true
- name: Check mypy
nox: typecheck
run-if: true
Expand Down
37 changes: 20 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
*.egg-info/
*.lock
*.o
*.py[co]
*.pyproj
*.so
_trial_temp*/
build/
dropin.cache
doc/
docs/_build/
dist/
venv/
htmlcov/
.coverage
*~
*.lock
apidocs/
.vs/
*.pyproj
.DS_Store
.eggs
.nox/
.coverage
.coverage.*
.vscode
.direnv
.envrc
.idea
.mypy_cache
.nox/
.pytest_cache
.python-version
.vs/
.vscode
Justfile
_trial_temp*/
apidocs/
dist/
doc/
docs/_build/
dropin.cache
htmlcov/
tmp/
venv/
File renamed without changes.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The following list contains some ways how to run the test suite:
* To run some quality checks before you create the pull request,
we recommend using this call::

$ nox -e pre_commit check_manifest check_newsfragment
$ nox -e pre_commit check_newsfragment

* Or enable `pre-commit` as a git hook::

Expand Down
20 changes: 0 additions & 20 deletions MANIFEST.in

This file was deleted.

11 changes: 2 additions & 9 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ def check_newsfragment(session: nox.Session) -> None:
session.run("python", "-m", "towncrier.check", "--compare-with", "origin/trunk")


@nox.session
def check_manifest(session: nox.Session) -> None:
session.install("check-manifest")
session.run("check-manifest")


@nox.session
def typecheck(session: nox.Session) -> None:
session.install(".", "mypy", "types-setuptools")
Expand All @@ -87,11 +81,10 @@ def docs(session: nox.Session) -> None:

@nox.session
def build(session: nox.Session) -> None:
session.install("build", "check-manifest>=0.44", "twine")
session.install("build", "twine")

session.run("check-manifest", "--verbose")
# If no argument is passed, build builds an sdist and then a wheel from
# that sdist.
session.run("python", "-m", "build")

session.run("twine", "check", "dist/*")
session.run("twine", "check", "--strict", "dist/*")
85 changes: 77 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
[build-system]
requires = [
"hatchling ~= 1.12.2",
"wheel ~= 0.38.4",

This comment has been minimized.

Copy link
@mgorny

mgorny Jun 8, 2023

Are you sure that wheel is actually needed? I don't grep it being used anywhere.

This comment has been minimized.

Copy link
@hynek

hynek Jun 8, 2023

Author Member

I personally doubt it; it's only taken over from the old requires.

This comment has been minimized.

Copy link
@adiroiban

adiroiban Jun 8, 2023

Author Member

I am not an expert in python packaging or hatching.

With setuptools, I know that if you don't have wheel installed, pip install -e . will fail.

But maybe with hatching this can be done without wheel

This comment has been minimized.

Copy link
@hynek

hynek Jun 8, 2023

Author Member

let's try and see: #520

"incremental == 22.10.0",
]
build-backend = "hatchling.build"


[project]
dynamic = ["version"]
name = "towncrier"
description = "Building newsfiles for your project."
readme = "README.rst"
license = "MIT"
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
requires-python = ">=3.7"
dependencies = [
"click",
"click-default-group",
"incremental",
"jinja2",
"setuptools",
"tomli; python_version<'3.11'",
]

[project.optional-dependencies]
dev = [
"packaging",
"sphinx >= 5",
"furo",
"twisted",
]

[project.scripts]
towncrier = "towncrier._shell:cli"

[project.urls]
Documentation = "https://towncrier.readthedocs.io/"
Chat = "https://web.libera.chat/?channels=%23twisted"
"Mailing list" = "https://mail.python.org/mailman3/lists/twisted.python.org/"
Issues = "https://github.com/twisted/towncrier/issues"
Repository = "https://github.com/twisted/towncrier"
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",
"bin",
"docs",
".readthedocs.yaml",
"src/towncrier/newsfragments",
]


[tool.towncrier]
package = "towncrier"
package_dir = "src"
Expand Down Expand Up @@ -77,14 +154,6 @@ module = 'incremental'
ignore_missing_imports = true


[build-system]
requires = [
"setuptools ~= 44.1.1",
"wheel ~= 0.36.2",
"incremental == 22.10.0",
]
build-backend = "setuptools.build_meta"

[tool.coverage.run]
parallel = true
branch = true
Expand Down
66 changes: 0 additions & 66 deletions setup.py

This file was deleted.

22 changes: 21 additions & 1 deletion src/towncrier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@

from __future__ import annotations

from ._version import __version__
from incremental import Version


__all__ = ["__version__"]


def __getattr__(name: str) -> Version:

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: 5 additions & 1 deletion src/towncrier/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@


__version__ = Version("towncrier", 22, 12, 1, dev=0)
__all__ = ["__version__"]
# The version is exposed in string format to be
# available for the hatching build tools.
_hatchling_version = __version__.short()

__all__ = ["__version__", "_hatchling_version"]
Empty file.
22 changes: 22 additions & 0 deletions src/towncrier/test/test_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Amber Brown, 2015
# See LICENSE for details.

from incremental import Version
from twisted.trial.unittest import TestCase

from towncrier._version import _hatchling_version


class TestPackaging(TestCase):
def test_version_warning(self):
"""
Import __version__ from towncrier returns an Incremental version object
and raises a warning.
"""
with self.assertWarnsRegex(
DeprecationWarning, "Accessing towncrier.__version__ is deprecated.*"
):
from towncrier import __version__

self.assertIsInstance(__version__, Version)
self.assertEqual(_hatchling_version, __version__.short())
14 changes: 12 additions & 2 deletions src/towncrier/test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ def test_incremental(self):
"""
pkg = "../src"

self.assertEqual(metadata_version("towncrier"), get_version(pkg, "towncrier"))
self.assertEqual("towncrier", get_project_name(pkg, "towncrier"))
with self.assertWarnsRegex(
DeprecationWarning, "Accessing towncrier.__version__ is deprecated.*"
):
version = get_version(pkg, "towncrier")

with self.assertWarnsRegex(
DeprecationWarning, "Accessing towncrier.__version__ is deprecated.*"
):
name = get_project_name(pkg, "towncrier")

self.assertEqual(metadata_version("towncrier"), version)
self.assertEqual("towncrier", name)

def _setup_missing(self):
"""
Expand Down

0 comments on commit 65d25e0

Please sign in to comment.