flit icon indicating copy to clipboard operation
flit copied to clipboard

Obscure error message "Invalid value for provides"

Open Conchylicultor opened this issue 2 years ago • 5 comments

Flit fail when trying to upload a minimal package:

[project]
name = "epot-test"
description = "aaa"
readme = "README.md"
requires-python = ">=3.7"
authors = [{name = "Conchylicultor", email="[email protected]"}]
dynamic = ["version"]

[build-system]
requires = ["flit_core >=3.5,<4"]
build-backend = "flit_core.buildapi"

Commands:

flit build
flit publish

flit publish fails with:

epot-macbookpro2:epot-test epot$ flit publish
Found 8 files tracked in git                                                                                   I-flit.sdist
Built sdist: dist/epot-test-1.1.0.tar.gz                                                                  I-flit_core.sdist
Copying package file(s) from /var/folders/67/mbgvk_q96wd9hmdgm8z9ts4r00fsh4/T/tmpgkxoru5_/epot-test-1.1.0/epot-test  I-flit_core.wheel
Writing metadata files                                                                                    I-flit_core.wheel
Writing the record of files                                                                               I-flit_core.wheel
Built wheel: dist/epot_test-1.1.0-py3-none-any.whl                                                        I-flit_core.wheel
Using repository at https://upload.pypi.org/legacy/                                                           I-flit.upload
Uploading dist/epot_test-1.1.0-py3-none-any.whl...                                                            I-flit.upload
Traceback (most recent call last):
  File "/Users/epot/.pyenv/versions/3.10.0/bin/flit", line 8, in <module>
    sys.exit(main())
  File "/Users/epot/.pyenv/versions/3.10.0/lib/python3.10/site-packages/flit/__init__.py", line 185, in main
    main(args.ini_file, repository, args.pypirc, formats=set(args.format or []),
  File "/Users/epot/.pyenv/versions/3.10.0/lib/python3.10/site-packages/flit/upload.py", line 268, in main
    do_upload(built.wheel.file, built.wheel.builder.metadata, pypirc_path, repo_name)
  File "/Users/epot/.pyenv/versions/3.10.0/lib/python3.10/site-packages/flit/upload.py", line 246, in do_upload
    upload_file(file, metadata, repo)
  File "/Users/epot/.pyenv/versions/3.10.0/lib/python3.10/site-packages/flit/upload.py", line 239, in upload_file
    resp.raise_for_status()
  File "/Users/epot/.pyenv/versions/3.10.0/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Invalid value for provides. Error: Use a valid Python identifier. for url: https://upload.pypi.org/legacy/

flit --version is Flit 3.7.1

It's very non obvious from the error message what is the issue with my toml file. It would be nice to have more explicit error messages.

Conchylicultor avatar May 15 '22 21:05 Conchylicultor

Looks like that error message is coming directly from pypi.org as part of the 400 error, not flit

bpabel avatar May 16 '22 02:05 bpabel

Renaming "epot-test" -> "epot_test" fixed the issue, but it's very non-obvious to guess from the error message. It would be nice if flit was checking this (maybe during flit build rather than this error in flit publish).

Conchylicultor avatar May 16 '22 11:05 Conchylicultor

Yes, Flit should check that. It's a quirk because in the old style metadata ([tool.flit.metadata]), you specified the import name first, which has to be a valid Python identifier, and you only entered the PyPI name if you wanted that to be different. The new style metadata ([project]) works the other way - you specify the PyPI name first, and only specify the import name if that's different.

takluyver avatar May 16 '22 13:05 takluyver

We should normalise the name generated for the sdist, using the same rules as wheels. That'll avoid the weird error message?

pradyunsg avatar May 16 '22 14:05 pradyunsg

I think the error is because Flit fills out the old Provides metadata field. It's officially deprecated since PEP 345, and doesn't even appear in the core metadata spec page, but it's still accepted, and when I started Flit I thought it was a good idea for package metadata to say which top level modules it contained.

takluyver avatar May 16 '22 16:05 takluyver