Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# force LF for pyproject to make hashFiles in CI consistent (windows <3)
# (see https://github.com/actions/runner/issues/498)
pyproject.toml text eol=lf
pyproject.toml text eol=lf export-subst
2 changes: 2 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ jobs:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
fetch-depth: '0'

- name: Set up environment
id: setup-env
Expand Down Expand Up @@ -244,6 +245,7 @@ jobs:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
fetch-depth: '0'

- name: Set up environment
id: setup
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: '0'
persist-credentials: false

- name: Set up environment
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ venvs/
.coverage*
coverage.xml
__pypackages__/
disnake/_version.py
.python-version
uv.lock
2 changes: 2 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ build:
tools:
python: "3.9"
jobs:
post_checkout:
- git fetch --tags || true
create_environment:
- asdf plugin add uv
- asdf install uv latest
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions changelog/1323.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use hatchling and versioningit for building disnake rather than using setuptools.
20 changes: 5 additions & 15 deletions disnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
__author__ = "Rapptz, EQUENOS"
__license__ = "MIT"
__copyright__ = "Copyright 2015-present Rapptz, 2021-present EQUENOS"
__version__ = "2.12.0a"

__path__ = __import__("pkgutil").extend_path(__path__, __name__)

import logging
from typing import Literal, NamedTuple

from . import abc as abc, opus as opus, ui as ui, utils as utils # explicitly re-export modules
from ._version import (
VersionInfo, # pyright: ignore[reportUnusedImport] # noqa: F401
__version__, # noqa: F401
version_info, # pyright: ignore[reportUnusedImport] # noqa: F401
)
from .activity import *
from .app_commands import *
from .appinfo import *
Expand Down Expand Up @@ -77,17 +80,4 @@
from .welcome_screen import *
from .widget import *


class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: Literal["alpha", "beta", "candidate", "final"]
serial: int


# fmt: off
version_info: VersionInfo = VersionInfo(major=2, minor=12, micro=0, releaselevel="alpha", serial=0)
# fmt: on

logging.getLogger(__name__).addHandler(logging.NullHandler())
14 changes: 14 additions & 0 deletions disnake/_version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: MIT

from typing import Literal, NamedTuple

__version__: str

class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: Literal["alpha", "beta", "candidate", "final"]
serial: int

version_info: VersionInfo
15 changes: 9 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import importlib.metadata
import importlib.util
import inspect
import os
Expand All @@ -20,6 +21,7 @@
import sys
from typing import Any, Dict, Optional

import versioningit
from sphinx.application import Sphinx

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -106,15 +108,16 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The full version, including alpha/beta/rc tags.
release = importlib.metadata.version("disnake")
# The short X.Y version.
version = ".".join(release.split(".")[:2])

version = ""
with open("../disnake/__init__.py") as f:
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) # type: ignore

# The full version, including alpha/beta/rc tags.
release = version
next_version = versioningit.get_next_version(os.path.abspath(".."))

rst_prolog += f"""
.. |next_version| replace:: {next_version}
"""

_IS_READTHEDOCS = bool(os.getenv("READTHEDOCS"))

Expand Down
2 changes: 1 addition & 1 deletion docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Changelog
This page keeps a detailed human friendly rendering of what's new and changed
in specific versions. Please see :ref:`version_guarantees` for more information.

.. towncrier-draft-entries:: |release| [UNRELEASED]
.. towncrier-draft-entries:: |next_version| [UNRELEASED]

.. towncrier release notes start

Expand Down
21 changes: 8 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def __post_init__(self) -> None:
ExecutionGroup(
sessions=("pyright",),
python=python,
pyright_paths=("disnake", "tests", "examples", "noxfile.py", "setup.py"),
pyright_paths=("disnake", "tests", "examples", "noxfile.py"),
project=True,
# FIXME: orjson doesn't yet support python 3.14, remove once we migrate to uv and have version-specific locks
extras=("speed", "voice") if python not in EXPERIMENTAL_PYTHON_VERSIONS else ("voice",),
groups=("test", "nox"),
dependencies=("setuptools", "pytz", "requests"), # needed for type checking
dependencies=("pytz", "requests"), # needed for type checking
)
for python in ALL_PYTHONS
),
Expand All @@ -95,18 +95,20 @@ def __post_init__(self) -> None:
# codemodding and pyright
ExecutionGroup(
sessions=("codemod", "autotyping", "pyright"),
pyright_paths=("scripts",),
pyright_paths=("scripts/codemods", "scripts/ci"),
groups=("codemod",),
),
# the other sessions, they don't need pyright, but they need to run
ExecutionGroup(
sessions=("lint", "slotscheck", "check-manifest"),
sessions=("lint", "slotscheck"),
groups=("tools",),
),
# build
ExecutionGroup(
sessions=("build",),
sessions=("build", "pyright"),
pyright_paths=("scripts/versioning.py",),
groups=("build",),
dependencies=(PYPROJECT["build-system"]["requires"]),
),
## testing
*(
Expand Down Expand Up @@ -254,21 +256,14 @@ def lint(session: nox.Session) -> None:
session.run("prek", "run", "--all-files", *session.posargs)


@nox.session(name="check-manifest")
def check_manifest(session: nox.Session) -> None:
"""Run check-manifest."""
install_deps(session)
session.run("check-manifest", "-v")


@nox.session(python=get_version_for_session("slotscheck"))
def slotscheck(session: nox.Session) -> None:
"""Run slotscheck."""
install_deps(session)
session.run("python", "-m", "slotscheck", "--verbose", "-m", "disnake")


@nox.session(requires=["check-manifest"])
@nox.session()
def build(session: nox.Session) -> None:
"""Build a dist."""
install_deps(session)
Expand Down
79 changes: 52 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: MIT

[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "versioningit>=3.3.0,<4.0", "packaging"]
build-backend = "hatchling.build"

[project]
name = "disnake"
Expand Down Expand Up @@ -64,6 +64,7 @@ docs = [
"towncrier==23.6.0",
"sphinx-notfound-page==0.8.3",
"sphinxext-opengraph==0.9.1",
"versioningit>=3.3.0",
]

[dependency-groups]
Expand All @@ -86,7 +87,6 @@ ruff = [
tools = [
"prek>=0.2.0",
"slotscheck~=0.16.4",
"check-manifest==0.49",
{ include-group = "ruff" },
]
changelog = [
Expand Down Expand Up @@ -116,13 +116,58 @@ build = [
"twine>=6.1.0",
]

[tool.setuptools.packages.find]
where = ["."]
include = ["disnake*"]

[tool.uv]
required-version = ">=0.8.4"

[tool.hatch.build]
include = [
"disnake/",
]
artifacts = ["disnake/_version.py"]

[tool.hatch.build.targets.sdist]
include = [
"scripts/versioning.py"
]

[tool.hatch.version]
source = "versioningit"

[tool.versioningit]
default-version = "0.0.0"

[tool.versioningit.vcs]
method = "git-archive"
describe-subst = "$Format:%(describe:tags,match=v*)$"

[tool.versioningit.format]
distance = "{base_version}+{distance}.{vcs}{rev}"
dirty = "{base_version}+d{build_date:%Y%m%d}"
distance-dirty = "{base_version}.a{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"

[tool.versioningit.template-fields]
method = { module = "scripts.versioning", value = "template_fields"}

[tool.versioningit.write]
file = "disnake/_version.py"
template = """
# SPDX-License-Identifier: MIT

from typing import Literal, NamedTuple

__version__ = "{version}"


class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: Literal["alpha", "beta", "candidate", "final"]
serial: int

version_info: VersionInfo = VersionInfo{version_tuple}
"""

[tool.ruff]
line-length = 100

Expand Down Expand Up @@ -415,23 +460,3 @@ exclude_lines = [
"^\\s*raise NotImplementedError$",
"^\\s*\\.\\.\\.$",
]


[tool.check-manifest]
ignore = [
# CI
".pre-commit-config.yaml",
".readthedocs.yml",
".libcst.codemod.yaml",
"noxfile.py",
# docs
"CONTRIBUTING.md",
"RELEASE.md",
"assets/**",
"changelog/**",
"docs/**",
"examples/**",
# tests
"tests/**",
"scripts/**",
]
54 changes: 54 additions & 0 deletions scripts/versioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-License-Identifier: MIT

import copy
from typing import Any, Dict, Optional

import packaging.version
import versioningit


def template_fields(
*,
version: str,
description: Optional[versioningit.VCSDescription],
base_version: Optional[str],
next_version: Optional[str],
params: Dict[str, Any],
) -> Dict[str, Any]:
"""Implements the ``"basic"`` ``template-fields`` method"""
params = copy.deepcopy(params)
parsed_version = packaging.version.parse(version)
fields: Dict[str, Any] = {}
if description is not None:
fields.update(description.fields)
fields["branch"] = description.branch
if base_version is not None:
fields["base_version"] = base_version
if next_version is not None:
fields["next_version"] = next_version
fields["version"] = version

releaselevels = {
"a": "alpha",
"b": "beta",
"rc": "candidate",
"": "final",
}

if parsed_version.pre:
releaselevel = releaselevels.get(parsed_version.pre[0], "final")
else:
releaselevel = "final"

fields["version_tuple"] = (
parsed_version.major,
parsed_version.minor,
parsed_version.micro,
releaselevel,
parsed_version.dev or 0,
)
try:
fields["normalized_version"] = str(packaging.version.Version(version))
except ValueError:
fields["normalized_version"] = version
return fields
Loading
Loading