Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to hatchling build backend #822

Merged
merged 1 commit into from
Mar 20, 2023
Merged
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ repos:
rev: 6.0.0
hooks:
- id: flake8
exclude: scm_hack_build_backend.py
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
Expand Down
40 changes: 5 additions & 35 deletions scm_hack_build_backend.py → _own_version_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,16 @@
"""
from __future__ import annotations

import os
import sys
from pathlib import Path

root = Path(__file__).parent
sys.path.insert(0, os.fspath(root / "src"))

from setuptools.build_meta import ( # type: ignore[attr-defined]
get_requires_for_build_wheel,
get_requires_for_build_sdist,
prepare_metadata_for_build_wheel,
build_wheel,
build_sdist,
get_requires_for_build_editable,
prepare_metadata_for_build_editable,
build_editable,
)


from setuptools_scm import Configuration
from setuptools_scm import get_version
from setuptools_scm.hacks import parse_pkginfo
from setuptools_scm import git
from setuptools_scm import hg
from setuptools_scm.version import guess_next_dev_version, get_local_node_and_date
from setuptools_scm import Configuration

from setuptools_scm.hacks import parse_pkginfo
from setuptools_scm.version import get_local_node_and_date
from setuptools_scm.version import guess_next_dev_version
from setuptools_scm.version import ScmVersion


dynamic_version: str


def parse(root: str, config: Configuration) -> ScmVersion | None:
try:
return parse_pkginfo(root, config)
Expand All @@ -45,16 +23,8 @@ def parse(root: str, config: Configuration) -> ScmVersion | None:

def scm_version() -> str:
return get_version(
root=str(root),
relative_to=__file__,
parse=parse,
version_scheme=guess_next_dev_version,
local_scheme=get_local_node_and_date,
)


def __getattr__(name: str) -> str:
if name == "dynamic_version":
global dynamic_version
dynamic_version = scm_version()
return dynamic_version
raise AttributeError(name)
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@


[build-system]
build-backend = "scm_hack_build_backend"
build-backend = "hatchling.build"
requires = [
"hatchling>=1.10",
"packaging>=20",
"setuptools>=55",
'tomli; python_version < "3.11"',
"typing_extensions",
]
backend-path = [
".",
]

[project]
name = "setuptools-scm"
Expand Down Expand Up @@ -90,8 +90,8 @@ pip-egg-info = "setuptools_scm.hacks:parse_pip_egg_info"
"python-simplified-semver" = "setuptools_scm.version:simplified_semver_version"
"release-branch-semver" = "setuptools_scm.version:release_branch_semver_version"

[tool.setuptools.dynamic]
version = {attr = "scm_hack_build_backend.dynamic_version"}

[tool.setuptools.packages.find]
where = ["src"]
[tool.hatch.version]
source = "code"
path = "_own_version_helper.py"
search-paths = ["src"]
expression = "scm_version()"