Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pyproject.toml #294

Open
coilysiren opened this issue Jul 9, 2021 · 1 comment
Open

Support pyproject.toml #294

coilysiren opened this issue Jul 9, 2021 · 1 comment

Comments

@coilysiren
Copy link

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

def _parse_name_from_path(self):
# type: () -> Optional[S]
if self.path and self.is_local and is_installable_dir(self.path):
metadata = get_metadata(self.path)
if metadata:
name = metadata.get("name", "")
if name and name != "wheel":
return name
parsed_setup_cfg = self.parsed_setup_cfg
if parsed_setup_cfg:
name = parsed_setup_cfg.get("name", "")
if name:
return name
parsed_setup_py = self.parsed_setup_py
if parsed_setup_py:
name = parsed_setup_py.get("name", "")
if name and isinstance(name, six.string_types):
return name
return None

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

@takluyver
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants