Skip to content

Commit

Permalink
build: hatchling
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Dec 27, 2024
1 parent 75923f9 commit 2b7f7d2
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 743 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ac3fdd902054a1108a5a604bf5770727c147a73542f52a85f6d838d12ef21226 requirements_dev.in
50d144951924e4a0b684e88565a95bff8903768b3e8d80f8f7a1f0d24ec728ba requirements_dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ typing-extensions==4.12.2
# via typer
urllib3==2.2.2
# via requests
version-pioneer==0.0.9
# via -r requirements_dev.in
versioneer==0.29
# via -r requirements.in
verspec==0.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ac3fdd902054a1108a5a604bf5770727c147a73542f52a85f6d838d12ef21226 requirements_dev.in
50d144951924e4a0b684e88565a95bff8903768b3e8d80f8f7a1f0d24ec728ba requirements_dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ typing-extensions==4.12.2
# via typer
urllib3==2.2.2
# via requests
version-pioneer==0.0.9
# via -r requirements_dev.in
versioneer==0.29
# via -r requirements.in
verspec==0.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ac3fdd902054a1108a5a604bf5770727c147a73542f52a85f6d838d12ef21226 requirements_dev.in
50d144951924e4a0b684e88565a95bff8903768b3e8d80f8f7a1f0d24ec728ba requirements_dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ typing-extensions==4.12.2
# via typer
urllib3==2.2.2
# via requests
version-pioneer==0.0.9
# via -r requirements_dev.in
versioneer==0.29
# via -r requirements.in
verspec==0.1.0
Expand Down
1 change: 1 addition & 0 deletions python-projector/deps/requirements_dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-r requirements.in
-r requirements_docs.in
version-pioneer
ruff==0.8.0
pytest>=8.0.1
pytest-cov>=4.1.0
Expand Down
48 changes: 27 additions & 21 deletions python-projector/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
[build-system]
requires = ["setuptools>=60", "versioneer[toml]==0.29"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-requirements-txt", "version-pioneer"]
build-backend = "hatchling.build"

[tool.versioneer]
VCS = "git"
style = "pep440"
versionfile_source = "src/python_projector/_version.py" # CHANGE
versionfile_build = "python_projector/_version.py" # CHANGE
tag_prefix = "v"
parentdir_prefix = "python-projector-" # CHANGE
[tool.hatch.metadata.hooks.requirements_txt]
files = ["deps/requirements.in"]

[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
dev = ["deps/requirements_dev.in"]

[tool.hatch.version]
source = "version-pioneer"

[tool.hatch.build.hooks.version-pioneer]

[tool.version-pioneer]
versionscript = "src/python_projector/_version.py"
versionfile-sdist = "src/python_projector/_version.py"
versionfile-wheel = "python_projector/_version.py"

[tool.hatch.build.targets.sdist]
include = [
"src",
"tests",
"deps",
]

[tool.hatch.build.targets.wheel]
sources = ["src"]

[project]
name = "python-projector" # CHANGE
Expand Down Expand Up @@ -37,18 +55,6 @@ keywords = ["development", "template"]
[project.scripts]
projector = "python_projector.cli:main" # CHANGE

[tool.setuptools]
license-files = []

[tool.setuptools.dynamic]
dependencies = {file = ["deps/requirements.in"]}

[tool.setuptools.package-data]
python_projector = ["scripts/**/*.sh", "scripts/**/*.py"] # CHANGE (name of the importing module name)

[tool.setuptools.packages.find]
where = ["src"]

[tool.projector.pip-compile]
requirements-in-dir = "deps"
requirements-out-dir = "deps/lock"
Expand Down
7 changes: 0 additions & 7 deletions python-projector/setup.py

This file was deleted.

29 changes: 25 additions & 4 deletions python-projector/src/python_projector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
""" # fmt: skip

# ruff: noqa: PLW0603
import json
import os
from functools import cache
from importlib.metadata import Distribution, PackageNotFoundError
from os import PathLike
from pathlib import Path

from . import _version
from ._version import get_version_dict
from .utils.deferred_logger import DeferredLogger

__version__ = _version.get_versions()["version"]
__version__ = get_version_dict()["version"]


APP_NAME = __name__
APP_NAME_UPPER = APP_NAME.upper()
PACKAGE_NAME = APP_NAME.replace("_", "-")
Expand All @@ -48,10 +53,26 @@
# │ directory definitions and environment variables / dotenv │
# └──────────────────────────────────────────────────────────────────────────────────┘


@cache
def pkg_is_editable():
try:
direct_url = Distribution.from_name(PACKAGE_NAME).read_text("direct_url.json")
except PackageNotFoundError:
# Not installed?
return False

if direct_url is None:
# package is not installed at all
return False
return json.loads(direct_url).get("dir_info", {}).get("editable", False)


# NOTE: The value is None if you haven't installed with `pip install -e .` (development mode).
# We make it None to discourage the use of this path. Only use for development.
PROJECT_DIR: Path | None = Path(__file__).parent.parent.parent
if PROJECT_DIR.name.startswith("python3."):
if pkg_is_editable():
PROJECT_DIR = Path(__file__).parent.parent.parent
else:
PROJECT_DIR = None

SCRIPTS_DIR = Path(__file__).parent / "scripts"
Expand Down
Loading

0 comments on commit 2b7f7d2

Please sign in to comment.