본문 바로가기
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 도구 대부분이 [tool.<name>] 에서 설정을 읽어. Poetry, Hatch, PDM, ruff, black, mypy, pytest, pytest-asyncio, coverage 다 그래. 파일 하나가 setup.pysetup.cfg, requirements.txt, tox.ini, .flake8 을 통째로 대신하는 거야.

Cargo.toml — Rust 의 매니페스트

Rust crate 라면 하나도 빠짐없이 갖고 있어. 안에는 [package], [dependencies], [dev-dependencies], [features], [[bin]], [[bench]] 가 들어가고. Cargo 가 하는 일 전부가 (build, test, publish, doc) 이 파일 하나를 보고 움직여. 여러 crate 를 묶는 workspace 는 여기에 [workspace] 를 더해서 루트에서 조율해.

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

Hugo 는 config 로 TOML 을 밀어 (YAML 과 JSON 도 받긴 해). 사이트 전체 설정, 메뉴 정의 (lesson 7 에서 본 array of table 이야), taxonomy 설정, 출력 포맷까지 전부 프로젝트 루트의 TOML 파일 한 장에 들어가.

원칙: 새 도구의 config 포맷을 고를 땐 그걸 쓸 사람이 이미 뭘 만지고 있는지를 봐. Python 개발자는 매일 pyproject.toml 을 열고, Rust 개발자는 매일 Cargo.toml 을 열어. 손이 이미 기억하는 형식을 쓰면 마찰이 줄어. 이 생태계들에서 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 같은 거) 문서를 읽고 쓸 만한 [tool.<name>] block 을 직접 써. '설정을 파일 하나에 다 모은다' 는 방식은 TOML 이 있어서 가능한 거야.

Progress

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

댓글 0

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

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