Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

cz init leads to an exception #367

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

Closed
jgosmann opened this issue Apr 4, 2021 · 4 comments
Closed

cz init leads to an exception #367

jgosmann opened this issue Apr 4, 2021 · 4 comments

Comments

@jgosmann
Copy link

jgosmann commented Apr 4, 2021

Description

After running cz init, I get an exception once I provided the tag format in a project using a pyproject.toml:

? Please choose a supported config file: (default: pyproject.toml)  pyproject.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits)  cz_conventional_commits
? Is v0.1.0 the latest tag?  Yes
? Is "v$version" the correct tag format?  Yes
Traceback (most recent call last):
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/bin/cz", line 8, in <module>
    sys.exit(main())
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/commitizen/cli.py", line 301, in main
    args.func(conf, vars(args))()
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/commitizen/commands/init.py", line 40, in __call__
    self._update_config_file(values_to_add)
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/commitizen/commands/init.py", line 157, in _update_config_file
    self.config.set_key(key, value)
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/commitizen/config/toml_config.py", line 27, in set_key
    parser = parse(f.read())
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/api.py", line 51, in parse
    return Parser(string).parse()
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/parser.py", line 160, in parse
    key, value = self._parse_table()
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/parser.py", line 1152, in _parse_table
    item = self._parse_item()
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/parser.py", line 306, in _parse_item
    return self._parse_key_value(True)
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/parser.py", line 397, in _parse_key_value
    val = self._parse_value()
  File "/Users/jgosmann/Library/Caches/pypoetry/virtualenvs/plato-XLRNDDrc-py3.8/lib/python3.8/site-packages/tomlkit/parser.py", line 667, in _parse_value
    raise self.parse_error(InvalidNumberError)
tomlkit.exceptions.InvalidNumberError: Invalid number at line 46 col 32

Running any other commitizen command after this seems to fail with the same exception. Also, it appends [tool.commitizen] to the last line (not below the last line) of the pyproject.toml, e.g.:

line_length = 88[tool.commitizen]

Steps to reproduce

Run cz init in a project with pyproject.toml. In case it only happens for specific pyproject.toml files, use the one from the v0.1.0 tag of py-plato/plato.

Current behavior

It throws the exception above. Also, it appends [tool.commitizen] to the last line (not below the last line) of the pyproject.toml, e.g.:

line_length = 88[tool.commitizen]

Desired behavior

No exception, and the pyproject.toml is correctly modified.

Environment

  • commitizen version: 2.17.0
  • python version: 3.8.7
  • operating system: macOS Big Sur
@Lee-W
Copy link
Member

Lee-W commented Apr 6, 2021

Just confirm it. Will send a PR these days

@Lee-W
Copy link
Member

Lee-W commented Apr 8, 2021

@jgosmann We just fixed it. Please check whether it solves your problem on the latest version. Gonna close this issue.

@Lee-W Lee-W closed this as completed Apr 8, 2021
@jgosmann
Copy link
Author

jgosmann commented Apr 8, 2021

Yes, that seems to fix it. The placement of the config in the pyproject.toml is a bit weird because there are two empty lines separating it from the previous section, and no empty line separating it from the next session. But that's only cosmetic.

btw: It seems that the publish step of the build pipeline failed. So 2.17.1 isn't available on PyPI yet.

@Lee-W
Copy link
Member

Lee-W commented Apr 9, 2021

Another PR #370 for this fix has been sent.

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

No branches or pull requests

2 participants