Skip to content

Commit

Permalink
feat!: hatchling, version-pioneer
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Dec 25, 2024
1 parent 2c00c0e commit 5cb3c66
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 759 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@

We use all good stuffs like:

ruff, uv, basedpyright, pytest, doctest, MkDocs, versioneer, GitHub Actions, conventional commit, changelog, typer CLI, rich logging, ...
ruff,
uv,
basedpyright,
pytest, doctest, MkDocs,
[version-pioneer](https://github.com/kiyoon/version-pioneer),
GitHub Actions, conventional commit, changelog, typer CLI, rich logging,,
hatchling build backend,
...

This template is designed to make it easy to install in various ways as follows.

```sh
# For developers
pip install -e .
pip install -e '.[dev]'

# If you want to use both API and CLI
pip install .
Expand Down Expand Up @@ -75,7 +82,7 @@ uv tool install 'git+https://github.com/deargen/python-project-template-2024'
📂 src/
└ 📂 ml_project/ # `import ml_project` to define functions, classes, etc.
│ 🐍 __init__.py
│ 🐍 _version.py # versioneer file to read version information from git tag (DO NOT modify)
│ 🐍 _version.py # versione-pioneer file to read version information from git tag (DO NOT modify)
│ 📜 template.env # Environment settings file copied to `.env` when `ml-project config` is executed
└ 🐍 ...

Expand Down Expand Up @@ -139,13 +146,21 @@ Other useful things to know:

# 한국어 README

ruff, uv, basedpyright, pytest, doctest, MkDocs, versioneer, GitHub Actions, conventional commit, changelog, typer CLI, rich logging 등 좋은 것 다 쓰는 파이썬 프로젝트 템플릿입니다.
ruff,
uv,
basedpyright,
pytest, doctest, MkDocs,
[version-pioneer](https://github.com/kiyoon/version-pioneer),
GitHub Actions, conventional commit, changelog, typer CLI, rich logging,,
hatchling build backend,

... 등 좋은 것 다 쓰는 파이썬 프로젝트 템플릿입니다.

본 템플릿으로 만든 패키지는 다음과 같이 쉽게 설치할 수 있도록 고안되었습니다.

```sh
# 개발자는
pip install -e .
pip install -e '.[dev]'

# API, CLI 둘 다 사용하고 싶다면
pip install .
Expand Down Expand Up @@ -204,7 +219,7 @@ uv tool install 'git+https://github.com/deargen/python-project-template-2024'
📂 src/
└ 📂 ml_project/ # `import ml_project`해서 사용하는 함수나 클래스 등 정의하는 곳
│ 🐍 __init__.py
│ 🐍 _version.py # git tag로 버전 정보를 읽는 versioneer 파일 (수정X)
│ 🐍 _version.py # git tag로 버전 정보를 읽는 version-pioneer 파일 (수정X)
│ 📜 template.env # `ml-project config` 실행시 `.env`로 복사되는 환경설정 파일
└ 🐍 ...

Expand Down
3 changes: 2 additions & 1 deletion deps/requirements_dev.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r requirements.in
-r requirements_docs.in
ruff==0.8.0
ruff==0.8.4
version-pioneer
pytest>=8.0.1
pytest-cov>=4.1.0
types-tqdm==4.66.0.20240106
Expand Down
8 changes: 4 additions & 4 deletions docs/python/versioneer.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Versioneer로 동적 버전 관리
# Versione-Pioneer로 동적 버전 관리

**Why?**

Expand All @@ -8,7 +8,7 @@

**Solution**

- [**Versioneer**](https://github.com/python-versioneer/python-versioneer): 버전 정보를 git tag에서 읽어와 python project versioning
- [**Version-Pioneer**](https://github.com/kiyoon/version-pioneer): 버전 정보를 git tag에서 읽어와 python project versioning

```python hl_lines="3"
import ml_project
Expand All @@ -28,8 +28,8 @@ print(ml_project.__version__)
## 설치

1. `src/ml_project/__init__.py`, `src/ml_project/_version.py` 가져다 쓰기
2. `pyproject.toml`versioneer 관련 섹션 가져다 쓰기
2. `pyproject.toml`version-pioneer 관련 섹션 가져다 쓰기

## 비슷한 툴

- `setuptools-scm`: 비슷하긴 하나 한번 pip로 설치할때 버전이 평생 버전이고, 다시 설치를 해야 버전 업데이트됨. versioneer는 동적으로 바뀜. 연구코드는 versioneer가 편할듯.
- `setuptools-scm`: 비슷하긴 하나 한번 pip로 설치할때 버전이 평생 버전이고, 다시 설치를 해야 버전 업데이트됨. version-pioneer는 동적으로 바뀜. 연구코드는 version-pioneer가 편할듯.
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ nav:
- 기타 플러그인: python_tools/other_vscode_extensions.md
- Python:
- logging: python/logging.md
- Version from Git Tag: python/versioneer.md
- Version from Git Tag: python/versione_pioneer.md
- Configuration: python/configuration.md
- PyPI 등록: python/publish_to_pypi.md
# defer to gen-files + literate-nav
Expand Down
44 changes: 18 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
[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/ml_project/_version.py" # CHANGE
versionfile_build = "ml_project/_version.py" # CHANGE
tag_prefix = "v"
parentdir_prefix = "ml-project-" # 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/ml_project/_version.py"
versionfile-sdist = "src/ml_project/_version.py"
versionfile-wheel = "ml_project/_version.py"

[project]
name = "ml-project" # CHANGE
Expand Down Expand Up @@ -38,18 +46,6 @@ keywords = ["development", "template"]
[project.scripts]
ml-project = "ml_project.cli:main" # CHANGE

[tool.setuptools]
license-files = []

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

[tool.setuptools.package-data]
ml_project = ["template.env"] # CHANGE (name of the importing module name)

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

[tool.projector.pip-compile]
# https://github.com/deargen/workflows/blob/master/python-projector
requirements-in-dir = "deps"
Expand Down Expand Up @@ -85,9 +81,6 @@ reportDuplicateImport = true
# Ignore INP001 on these directories
# The directories that do not contain s, r, and c are already ignored.
namespace-packages = ["scripts"]
extend-exclude = [
"src/ml_project/_version.py", # CHANGE
]

[tool.ruff.lint]
# OPTIONALLY ADD MORE LATER
Expand Down Expand Up @@ -121,8 +114,7 @@ select = [
"ASYNC",
"FBT", # boolean trap
"A", # Shadowing python builtins
"EXE", # executable (shebang)
"FA", # future annotations
"EXE", # executable (shebang) "FA", # future annotations
"ISC", # Implicit string concatenation
"ICN", # Import convention
"INP", # Implicit namespace package (no __init__.py)
Expand Down
7 changes: 0 additions & 7 deletions setup.py

This file was deleted.

8 changes: 5 additions & 3 deletions src/ml_project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
import rich
from dotenv import load_dotenv

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 @@ -59,7 +59,9 @@
@cache
def pkg_is_editable():
direct_url = Distribution.from_name(PACKAGE_NAME).read_text("direct_url.json")
assert direct_url is not None
if direct_url is None:
# package is not installed at all
return False
return json.loads(direct_url).get("dir_info", {}).get("editable", False)


Expand Down
Loading

0 comments on commit 5cb3c66

Please sign in to comment.