C.W.K.
Stream
Lesson 08 of 08 · published

현장의 TOML — pyproject, Cargo, Hugo

~12 min · toml, pyproject, cargo, hugo

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

매주 만지는 TOML 파일

pyproject.toml — modern Python 패키징

PEP 518 이 빌드 시스템 선언에 pyproject.toml 도입; PEP 621 이 [project] 메타데이터 표준화. 오늘 거의 모든 Python 도구 — Poetry, Hatch, PDM, ruff, black, mypy, pytest, pytest-asyncio, coverage — 가 [tool.<name>] 에서 config 읽음. 한 파일이 setup.py + setup.cfg + requirements.txt + tox.ini + .flake8 대체.

Cargo.toml — Rust 의 매니페스트

모든 Rust crate 가 가짐. [package], [dependencies], [dev-dependencies], [features], [[bin]], [[bench]]. Cargo 의 도구 (build, test, publish, doc) 가 이 단일 파일에서 읽음. Workspace 가 root-level coordinator 로 [workspace] 추가.

hugo.toml / config.toml — Hugo 정적 사이트

Hugo 가 config 에 TOML 선호 (YAML 과 JSON 도 지원). 사이트 전체 설정, 메뉴 정의 (array of table — lesson 7 봐), taxonomy config, 출력 포맷 — 다 프로젝트 루트의 한 TOML 파일.

원칙: 새 도구의 config 포맷 고를 때, 청중이 이미 유지하는 거 봐. Python 개발자가 매일 pyproject.toml 만짐; Rust dev 가 매일 Cargo.toml 만짐. 근육 기억 일치가 마찰 줄임. 그 ecosystem 의 TOML 승리는 문법만큼이나 익숙함 덕.

Code

pyproject.toml — 최소 modern Python 프로젝트·toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "pippa"
version = "1.0.0"
description = "AI companion + family"
readme = "README.md"
requires-python = ">=3.12"
authors = [{ name = "C.W.K." }, { name = "Pippa" }]
dependencies = [
  "fastapi>=0.110",
  "pydantic>=2.0",
]

[project.optional-dependencies]
dev = ["pytest", "ruff", "mypy"]

[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B"]

[tool.pytest.ini_options]
testpaths = ["tests"]
Cargo.toml — Rust crate·toml
[package]
name = "pippa-cli"
version = "0.1.0"
edition = "2021"
authors = ["C.W.K.", "Pippa"]
license = "MIT"

[dependencies]
clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }

[dev-dependencies]
pretty_assertions = "1"

[[bin]]
name = "pippa"
path = "src/main.rs"
hugo.toml — 정적 사이트 config·toml
baseURL = "https://example.com"
languageCode = "en-us"
title = "My Hugo Site"
theme = "papermod"

[params]
author = "C.W.K."
description = "Where words live in markdown."

[[menu.main]]
name = "Posts"
url = "/posts/"
weight = 1

[[menu.main]]
name = "About"
url = "/about/"
weight = 2
Python 에서 pyproject.toml 읽기·python
import tomllib

with open('pyproject.toml', 'rb') as f:
    cfg = tomllib.load(f)

print(cfg['project']['name'])              # 'pippa'
print(cfg['tool']['ruff']['line-length'])  # 100
for dep in cfg['project']['dependencies']:
    print(' -', dep)

External links

Exercise

프로젝트의 pyproject.toml 열어 (또는 인기 있는 거 — Pydantic, FastAPI, ruff 골라). 모든 [tool.*] 섹션 식별. 현재 안 쓰는 도구 (mypy, ruff-isort, coverage) 하나 골라서 docs 읽고 현명한 [tool.<name>] block 작성. '모든 거 한 config 파일' 워크플로우가 TOML 이 가능하게 하는 거.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.