How to indicate use_scm_version in setup.cfg?

Question:

I’m switching from using setup.py to setup.cfg.
How can I indicate in setup.cfg that I want use_scm_version= True?

Asked By: shalva_t

||

Answers:

Did you try the following:

from setuptools import setup
from setuptools.config import read_configuration

conf_dict = read_configuration("setup.cfg")
PKG_NAME = conf_dict['metadata']['name']

setup(
    use_scm_version={"write_to": f"{PKG_NAME}/_version.py"},
)

Source: https://github.com/pypa/setuptools_scm/issues/582

Answered By: Isma

I have resolved this by adding pyproject.toml file with following code, forcing building to be implemented with setuptools_scm:

# pyproject.toml
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_scheme = "post-release"
Answered By: shalva_t

See the recommended usage in project.toml:

# project.toml

[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]

[project]
dynamic = ["version"]  # remove any existing version parameter

[tool.setuptools_scm]

According to the setuptools-scm docs, this is equivalent to supplying use_scm_version=True in setup.py.

Answered By: larenite
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.