Skip to content

Build systems

Florian Blanchet edited this page May 2, 2021 · 20 revisions

Build systems

Workflow for packaging and installing

python -m venv .env
source .env/bin/activate
python -m pip install --upgrade pip build
python -m build
python -m pip install --force-reinstall dist/${PACKAGE_NAME}-${PACKAGE_VERSION}-py3-none-any.whl

Flit

pyproject.toml

[build-system]
requires = ["flit_core"]
build-backend = "flit_core.buildapi"

[project]
name = "${PACKAGE_NAME}"
version = "${PACKAGE_VERSION}"
description = "${SUMMARY_DESCRIPTION}"
readme = "README.md"
# Do NOT support multiple authors/maintainers
# Only the FIRST one is used
authors = [
  {name = "${AUTHOR_NAME}", email = "${AUTHOR_EMAIL}"}
]
maintainers = [
  {name = "${AUTHOR_NAME}", email = "${AUTHOR_EMAIL}"}
]
dependencies = [
  "httpx"
]
requires-python = ">=3.6"
classifiers = [
  "Development Status :: 1 - Planning",
  "${CLASSIFIER_LICENSE}",
  "Programming Language :: Python",
  "Programming Language :: Python :: 3",
  "Programming Language :: Python :: 3.6",
  "Programming Language :: Python :: 3.7",
  "Programming Language :: Python :: 3.8",
  "Programming Language :: Python :: 3.9",
  "Programming Language :: Python :: 3.10"
]

[project.urls]
homepage = "${HOMEPAGE_URL}"
documentation = "${DOCUMENTATION_URL}"
repository = "${REPOSITORY_URL}"

[project.optional-dependencies]
dev = [
  "pytest"
]

Resulting ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/METADATA

Metadata-Version: 2.1
Name: ${PACKAGE_NAME}
Version: ${PACKAGE_VERSION}
Summary: ${SUMMARY_DESCRIPTION}
Author-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
Maintainer-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Classifier: Development Status :: 1 - Planning
${CLASSIFIER_LICENSE}
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Dist: httpx
Requires-Dist: pytest ; extra == "dev"
Project-URL: documentation, ${DOCUMENTATION_URL}
Project-URL: homepage, ${HOMEPAGE_URL}
Project-URL: repository, ${REPOSITORY_URL}
Provides-Extra: dev

cat ${PROJECT_ROOT}/README.md
cp ${PROJECT_ROOT}/LICENSE ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/LICENSE

Developer mode

pip install flit
python -m flit install --pth-file

Setuptools

pyproject.toml

[build-system]
requires = [
  "setuptools",
  "wheel",
]
build-backend = "setuptools.build_meta"

setup.cfg

[metadata]
name = ${PROJECT_NAME}
version = ${PACKAGE_VERSION}
description = ${SUMMARY_DESCRIPTION}
long_description = file: README.md
long_description_content_type = text/markdown
# SUPPORT multiple authors/maintainers
author_email = ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
maintainer_email = ${AUTHOR_NAME} <${AUTHOR_EMAIL}> 
url = ${HOMEPAGE_URL}
project_urls =
    Documentation = ${DOCUMENTATION_URL}
    Repository = ${REPOSITORY_URL}
classifiers =
    Development Status :: 1 - Planning
    ${CLASSIFIER_LICENSE}
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
    Programming Language :: Python :: 3.10

[options]
packages = ${PACKAGE_NAME}
python_requires = >=3.6
install_requires =
    httpx

[options.package_data]
* = data/*

[options.extras_require]
dev = pytest

Developer mode

pip install --editable .

REQUIRE setup.py

import setuptools

setuptools.setup()

Resulting ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/METADATA

Metadata-Version: 2.1
Name: ${PROJECT_NAME}
Version: ${PACKAGE_VERSION}
Summary: ${SUMMARY_DESCRIPTION}
Home-page: ${HOMEPAGE_URL}
Author-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
Maintainer-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
License: UNKNOWN
Project-URL: Documentation, ${DOCUMENTATION_URL}
Project-URL: Repository, ${REPOSITORY_URL}
Platform: UNKNOWN
Classifier: Development Status :: 1 - Planning
${CLASSIFIER_LICENSE}
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: httpx
Provides-Extra: dev
Requires-Dist: pytest ; extra == 'dev'

cat ${PROJECT_ROOT}/README.md
cp ${PROJECT_ROOT}/LICENSE ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/LICENSE

PDM

pyproject.toml

[build-system]
requires = ["pdm-pep517"]
build-backend = "pdm.pep517.api"

[project]
name = "${PACKAGE_NAME}"
version = "${PACKAGE_VERSION}"
description = "${SUMMARY_DESCRIPTION}"
readme = "README.md"
# SUPPORT multiple authors/maintainers
authors = [
  {name = "${AUTHOR_NAME}", email = "${AUTHOR_EMAIL}"},
]
maintainers = [
  {name = "${AUTHOR_NAME}", email = "${AUTHOR_EMAIL}"}
]
dependencies = [
  "httpx"
]
requires-python = ">=3.6"
classifiers = [
  "Development Status :: 1 - Planning",
  "${CLASSIFIER_LICENSE}",
  "Programming Language :: Python",
  "Programming Language :: Python :: 3.6",
  "Programming Language :: Python :: 3.7",
  "Programming Language :: Python :: 3.8",
  "Programming Language :: Python :: 3.9",
  "Programming Language :: Python :: 3.10"
]

[project.urls]
homepage = "${HOMEPAGE_URL}"
documentation = "${DOCUMENTATION_URL}"
repository = "${REPOSITORY_URL}"

[project.optional-dependencies]
dev = [
  "pytest"
]

Resulting ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/METADATA

Metadata-Version: 2.1
Name: ${PROJECT_NAME}
Version: ${PACKAGE_VERSION}
Summary: ${SUMMARY_DESCRIPTION}
License: UNKNOWN
Author-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
Maintainer-email: ${AUTHOR_NAME} <${AUTHOR_EMAIL}>
Requires-Python: >=3.6
${CLASSIFIER_LICENSE}
Classifier: Development Status :: 1 - Planning
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Dist: httpx
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Project-URL: documentation, ${DOCUMENTATION_URL}
Project-URL: homepage, ${HOMEPAGE_URL}
Project-URL: repository, ${REPOSITORY_URL}
Description-Content-Type: text/markdown

cat ${PROJECT_ROOT}/README.md
cp ${PROJECT_ROOT}/LICENSE ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/LICENSE

Developer mode (with flit)

pip install flit
flit install --pth-file

Poetry

pyproject.toml

[build-system]
requires = ["poetry_core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "${PACKAGE_NAME}"
version = "${PACKAGE_VERSION}"
description = "${SUMMARY_DESCRIPTION}"
readme = "README.md"
# Do NOT support multiple authors/maintainers
# Only the FIRST one is used
authors = [
  "${AUTHOR_NAME} <${AUTHOR_EMAIL}>"
]
maintainers = [
  "${AUTHOR_NAME} <${AUTHOR_EMAIL}>"
]
homepage = "${HOMEPAGE_URL}"
documentation = "${DOCUMENTATION_URL}"
repository = "${REPOSITORY_URL}"
classifiers = [
  "Development Status :: 1 - Planning",
  "${CLASSIFIER_LICENSE}",
  "Programming Language :: Python",
  "Programming Language :: Python :: 3.10"
]

[tool.poetry.dependencies]
python = ">=3.6"
httpx = "*"

[tool.poetry.extras]
dev = [
  "pytest"
]

Resulting ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/METADATA

Metadata-Version: 2.1
Name: ${PROJECT_NAME}
Version: ${PACKAGE_VERSION}
Summary: ${SUMMARY_DESCRIPTION}
Home-page: ${HOMEPAGE_URL}
License: UNKNOWN
Author: ${AUTHOR_NAME}
Author-email: ${AUTHOR_EMAIL}
Maintainer: ${AUTHOR_NAME}
Maintainer-email: ${AUTHOR_EMAIL}
Requires-Python: >=3.6
Classifier: Development Status :: 1 - Planning
${CLASSIFIER_LICENSE}
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Provides-Extra: dev
Requires-Dist: httpx
# MISSING! Requires-Dist: pytest ; extra == "dev"
Project-URL: Documentation, ${DOCUMENTATION_URL}
Project-URL: Repository, ${REPOSITORY_URL}
Description-Content-Type: text/markdown

cat ${PROJECT_ROOT}/README.md
cp ${PROJECT_ROOT}/LICENSE ${PACKAGE_NAME}-${PACKAGE_VERSION}.dist-info/LICENSE

Developer mode

poetry env use ${version}
poetry install