requirementslib
requirementslib copied to clipboard
Support pyproject.toml
Use Case
I want to use pipenv with a pyproject.toml file configured for use with flit
Problem
Currently trying to run pipenv install . in a folder with only a pyproject.toml (no setup.cfg or setup.py), you get the following exception
Traceback (most recent call last):
File "/Users/lconway/.pyenv/versions/3.8.7/bin/pipenv", line 8, in <module>
sys.exit(cli())
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/cli/command.py", line 233, in install
retcode = do_install(
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/core.py", line 2182, in do_install
project.add_package_to_pipfile(pkg_requirement, dev)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/project.py", line 1004, in add_package_to_pipfile
name = self.get_package_name_in_pipfile(req_name, dev)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/project.py", line 960, in get_package_name_in_pipfile
package_name = pep423_name(package_name)
File "/Users/lconway/.pyenv/versions/3.8.7/lib/python3.8/site-packages/pipenv/utils.py", line 1586, in pep423_name
name = name.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
I believe the root cause of the above exception is this block
https://github.com/sarugaku/requirementslib/blob/644198471362e5e7be7a32d2a9fdadd538391aef/src/requirementslib/models/requirements.py#L990-L1009
which looks for the name in setup.cfg and setup.py but not pyproject.toml
Proposed Solution
It seems like the obvious solution is to add a case to that block that looks inside of pyproject.toml, like so
parsed_pyproject_toml = self.parsed_pyproject_toml
if parsed_pyproject_toml:
name = parsed_pyproject_toml.get("project", {}).get("name", "")
if name:
return name
but there may be complexities with that that I'm not aware of? For example, should this invoke the build-backend in some way to retrieve the name?
Either way, this seems like a relatively simple change so I'm happy to make it myself
Various CCs
cc'ing people I think might be able to help here ... @techalchemy / @uranusjr / @frostming / @takluyver / @pfmoore / @pradyunsg / @brainwane
For example, should this invoke the build-backend in some way to retrieve the name?
The relevant PEP is 621. If backends implement this, the spec says the name field must be static, so there shouldn't be any need to call a backend to retrieve it.
PEP 621 is quite new, and obviously tools aren't forced to implement it, nor projects to use it, but hopefully most will eventually.