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

"pdm add" generates invalid toml #487

Closed
blueyed opened this issue May 31, 2021 · 3 comments
Closed

"pdm add" generates invalid toml #487

blueyed opened this issue May 31, 2021 · 3 comments
Labels
πŸ› bug Something isn't working ⬆️ upstream bug Caused by a bug from the upstream dependencies

Comments

@blueyed
Copy link
Contributor

blueyed commented May 31, 2021

pdm add sentry-sdk generated this diff for pyproject.toml:

 dependencies = [
     "django~=3.1",
-]
+, "sentry-sdk~=1.1"]
 requires-python = ">=3.9"

This then fails at the end, or with pdm lock -v:

…
πŸ”’ Lock successful
Changes are written to pdm.lock.
Changes are written to pyproject.toml.
Traceback (most recent call last):
  File "…/project/.venv/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "…/project/.venv/lib/python3.9/site-packages/pdm/core.py", line 184, in main
    return Core().main(args)
  File "…/project/.venv/lib/python3.9/site-packages/pdm/core.py", line 145, in main
    raise cast(Exception, err).with_traceback(traceback)
  File "…/project/.venv/lib/python3.9/site-packages/pdm/core.py", line 140, in main
    f(options.project, options)
  File "…/project/.venv/lib/python3.9/site-packages/pdm/cli/commands/add.py", line 44, in handle
    actions.do_add(
  File "…/project/.venv/lib/python3.9/site-packages/pdm/cli/actions.py", line 208, in do_add
    project.write_lockfile(lockfile, False)
  File "…/project/.venv/lib/python3.9/site-packages/pdm/project/core.py", line 395, in write_lockfile
    toml_data["metadata"].update(self.get_lock_metadata())
  File "…/project/.venv/lib/python3.9/site-packages/pdm/project/core.py", line 388, in get_lock_metadata
    content_hash = atoml.string("sha256:" + self.get_content_hash("sha256"))
  File "…/project/.venv/lib/python3.9/site-packages/pdm/project/core.py", line 417, in get_content_hash
    "sources": self.tool_settings.get("source", []),
  File "…/project/.venv/lib/python3.9/site-packages/pdm/project/core.py", line 103, in tool_settings
    data = self.pyproject
  File "…/project/.venv/lib/python3.9/site-packages/pdm/project/core.py", line 93, in pyproject
    data = atoml.parse(self.pyproject_file.read_text("utf-8"))
  File "…/project/.venv/lib/python3.9/site-packages/atoml/api.py", line 61, in parse
    return Parser(string).parse()
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 152, in parse
    key, value = self._parse_table()
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 1146, in _parse_table
    item = self._parse_item()
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 298, in _parse_item
    return self._parse_key_value(True)
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 389, in _parse_key_value
    val = self._parse_value()
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 561, in _parse_value
    return self._parse_array()
  File "…/project/.venv/lib/python3.9/site-packages/atoml/parser.py", line 729, in _parse_array
    raise self.parse_error(UnexpectedCharError, self._current)
atoml.exceptions.UnexpectedCharError: Unexpected character: ',' at line 10 col 0

version 1.6.2
Related/similar issue: #462

@blueyed blueyed added the πŸ› bug Something isn't working label May 31, 2021
@frostming
Copy link
Collaborator

An issue with tomlkit/atoml, let me check

@frostming
Copy link
Collaborator

Note that you can get this fixed immediately by upgrading the atoml version to 1.0.2

90b22d2 just makes the array format more beautiful

@blueyed
Copy link
Contributor Author

blueyed commented Jun 3, 2021

Thanks, the fix/upgrade works well.

I've wondered if there is a way to trigger a regeneration of the dependencies (format-only) automatically / through pdm?
I've noticed that pdm update --unconstrained will trigger it, although the deps/versions are not changed, but that a) might not be intentional, and/or b) there is a better way for this maybe?
(Anyway, I am just curious - it is easy enough to adjust/re-format it manually)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ› bug Something isn't working ⬆️ upstream bug Caused by a bug from the upstream dependencies
Projects
None yet
Development

No branches or pull requests

2 participants