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

Import from Poetry fails #1384

Closed
1 task done
vovkd opened this issue Sep 14, 2022 · 6 comments
Closed
1 task done

Import from Poetry fails #1384

vovkd opened this issue Sep 14, 2022 · 6 comments
Labels
🐛 bug Something isn't working

Comments

@vovkd
Copy link

vovkd commented Sep 14, 2022

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

pdm -V
PDM, version 2.1.3

You need a poetry formatted pyproject.toml with dependency described like this:
"uvloop = {version = "^0.16", optional=true, platform="linux"}"

then run:
>>> pdm import -f poetry pyproject.toml -v

Actual behavior

But instead of success receive an error: TypeError: init() got an unexpected keyword argument 'platform'
if key "platform" removed from from pyproject.tom then pdm imports poetry file without errors.

Traceback (most recent call last):
File "/Users/user/.pyenv/versions/prj/bin/pdm", line 8, in
sys.exit(main())
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/core.py", line 254, in main
return Core().main(args)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/core.py", line 187, in main
raise cast(Exception, err).with_traceback(traceback)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/core.py", line 182, in main
f(options.project, options)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/cli/commands/import_cmd.py", line 35, in handle
do_import(project, options.filename, options.format, options)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/cli/actions.py", line 734, in do_import
project_data, settings = FORMATS[key].convert(project, filename, options)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/formats/poetry.py", line 210, in convert
return converter.convert()
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/formats/base.py", line 59, in convert
self._data[key] = func(self, value)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/formats/poetry.py", line 137, in dependencies
req = _convert_req(key, req_dict)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/formats/poetry.py", line 91, in _convert_req
return Requirement.from_req_dict(name, req_dict).as_line()
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/models/requirements.py", line 188, in from_req_dict
return NamedRequirement.create(name=name, **req_dict)
File "/Users/user/.pyenv/versions/3.9.13/envs/prj/lib/python3.9/site-packages/pdm/models/requirements.py", line 151, in create
return cls(**kwargs)
TypeError: init() got an unexpected keyword argument 'platform'

Expected behavior

image

## Environment Information
# Paste the output of `pdm info && pdm info --env` below:

Inside an active virtualenv, reuse it.
{
  "implementation_name": "cpython",
  "implementation_version": "3.9.13",
  "os_name": "posix",
  "platform_machine": "arm64",
  "platform_release": "21.6.0",
  "platform_system": "Darwin",
  "platform_version": "Darwin Kernel Version 21.6.0: Sat Jun 18 17:05:47 PDT 2022; root:xnu-8020.140.41~1/RELEASE_ARM64_T8101",
  "python_full_version": "3.9.13",
  "platform_python_implementation": "CPython",
  "python_version": "3.9",
  "sys_platform": "darwin"
}
@vovkd vovkd added the 🐛 bug Something isn't working label Sep 14, 2022
@frostming
Copy link
Collaborator

frostming commented Sep 15, 2022

Where is the key platform documented? I can't find it at https://python-poetry.org/docs/dependency-specification/. Where can I find the full list of dependency keys?

It is unfair to blame PDM if the field isn't documented at all.

@vovkd
Copy link
Author

vovkd commented Sep 15, 2022

Well, of course it's unfair so i'm just letting community know that there is a problem, no blame at all.
I think it's originates from this PEP: https://peps.python.org/pep-0508/#environment-markers
And as i can see this keyword comes forward here and there in poetry issues python-poetry/poetry#1616

@frostming
Copy link
Collaborator

frostming commented Sep 15, 2022

Well, but platform isn't a standard environment marker key per PEP 508. It seems randomly picked by the Poetry maintainers without mentioning it in the docs. 😢

@vovkd
Copy link
Author

vovkd commented Sep 16, 2022

Would it be acceptable:

  1. add to PDM import command argument --strict to strictly follow PEP 508 and stop import job if pyproject.toml invalid. Not just crash, but raise an human readable exception with explanation.
  2. If this arg is not specified give a warning if pyproject.toml is not comply with spec in PEP 508 and just ignore undocumented options.

@zanieb
Copy link

zanieb commented Sep 22, 2022

I've opened an issue on Poetry to document the schema for dependencies: python-poetry/poetry#6600

I agree, I'm sure how you were supposed to know. platform has been an option for a long time — it was added in Poetry 0.10.0. Seems worth adding support for without the complicating the CLI.

Edit: They've provided this helpful link! https://github.com/python-poetry/poetry-core/blob/main/src/poetry/core/json/schemas/poetry-schema.json

@frostming
Copy link
Collaborator

The unrecognized arguments will be ignored now, close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants