AmineTrabelsi
AmineTrabelsi

Reputation: 35

What is the correct way of specifying the license in pyproject.toml file for a new package?

I am facing an error with the license specification when trying to build and upload a python package.

I have the last version of wheel, setuptools, twine, and build.

building fails if I specify the license according to the python packaging tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/

if I do not specify the license then twine upload fails with the error:

ERROR    InvalidDistribution: Invalid distribution metadata: unrecognized or malformed field 'license-file'

the same upload error occurs if I build with the following:

[project.license]
file = "LICENSE"

or

license = {text = "MIT"}

or

license = {file = "LICENSE"}

this is my full configuration file:

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

[project]
name = "name"
version = "0.0.1"
authors = [
  { name="Your Name", email="[email protected]" },
]
description = "A python package"
readme = "README.md"
requires-python = ">=3.8"

classifiers = [
    "Programming Language :: Python :: 3",
    "Operating System :: OS Independent",
]

dependencies = [
    "requests",
    "numpy",
]

Upvotes: 0

Views: 641

Answers (2)

cloud chang
cloud chang

Reputation: 31

It seems to be a version issue as shown in this post: version issue with twine. Two main points of takeaway is to check your twine and pkginfo version. You can do this by python -m pip show <package name>. Make sure that twine version is <= 6.0.1 ad pkginfo is the latest version 1.12.0.

Upvotes: 3

Markus Hirsim&#228;ki
Markus Hirsim&#228;ki

Reputation: 753

You can do this for example if you are using a commonly known license

[project]
license = {text = "The Unlicense"}

or

[project]
license = {file = "licenses/license.txt"}

if you are having trouble with the path you can use this to set the package root

[tool.setuptools]
package-dir = { "" = "src" }

Upvotes: 0

Related Questions