简介
pyproject.toml
是在 PEP 518 中提出并在 PEP 621 中扩展的新配置文件 。目的是管理构建依赖,同时也可以存储 Python 项目的任何工具配置。
使用pyproject的目的:
- 在一个 Python 项目中,我们需要管理
requirements.txt
.flake8
等等的配置文件,当一个项目中使用的工具越多,根目录就越杂乱,管理成本越高,对新人也就越不友好 - 将诸多工具的配置集中到 pyproject.toml 统一管理,将小而零散的开发工具配置提取并放到同一个地方,便于了解项目构建、开发流程等信息
示例
配置示例:
代码语言:javascript复制[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "opentelemetry-instrumentation-django"
dynamic = ["version"]
description = "OpenTelemetry Instrumentation for Django"
readme = "README.rst"
license = "Apache-2.0"
requires-python = ">=3.7"
authors = [
{ name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.37b0.dev",
"opentelemetry-instrumentation-wsgi == 0.37b0.dev",
"opentelemetry-semantic-conventions == 0.37b0.dev",
"opentelemetry-util-http == 0.37b0.dev",
]
[project.optional-dependencies]
asgi = [
"opentelemetry-instrumentation-asgi == 0.37b0.dev",
]
instruments = [
"django >= 1.10",
]
test = [
"opentelemetry-instrumentation-django[instruments]",
"opentelemetry-test-utils == 0.37b0.dev",
]
[project.entry-points.opentelemetry_instrumentor]
django = "opentelemetry.instrumentation.django:DjangoInstrumentor"
[project.urls]
Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-django"
[tool.hatch.version]
path = "src/opentelemetry/instrumentation/django/version.py"
[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]
[tool.hatch.build.targets.wheel]
packages = ["src/opentelemetry"]