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

Unable to parse the pyproject.toml file. #156

Closed
vipcxj opened this issue Jan 12, 2023 · 3 comments
Closed

Unable to parse the pyproject.toml file. #156

vipcxj opened this issue Jan 12, 2023 · 3 comments

Comments

@vipcxj
Copy link
Contributor

vipcxj commented Jan 12, 2023

here is the exception stack:

  File "d:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\__main__.py", line 3, in <module>
    main()
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\cli.py", line 245, in main
    run(args)
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\cli.py", line 129, in run
    config_file = get_config_file(
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\config.py", line 222, in get_config_file
    res.get_config()
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\config.py", line 69, in get_config
    res = from_parsed_config(parsed)
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\config.py", line 258, in from_parsed_config
    validate_basic_schema(parsed)
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\tbump\config.py", line 180, in validate_basic_schema
    tbump_schema.validate(config)
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\schema.py", line 405, in validate
    nvalue = Schema(svalue, error=e, ignore_extra_keys=i).validate(value, **kwargs)
  File "D:\develop\mamba\envs\ipywebcam-dev\lib\site-packages\schema.py", line 366, in validate
    return type(data)(o.validate(d, **kwargs) for d in data)
TypeError: Array.__init__() missing 1 required positional argument: 'trivia'

I typed the command: tbump current-version
This is my pyproject.toml:

[tool.tbump]
field = [
    { name = "channel", default = "" },
    { name = "release", default = "" },
]
file = [
    { src = "pyproject.toml", version_template = "version = \"{major}.{minor}.{patch}{channel}{release}\"" },
    { src = "ipywebcam/_version.py" },
]

I have debug the command, And found the problem.
return type(data)(o.validate(d, **kwargs) for d in data)
This line cause the exception. It's in schema.py line 366.
I found data here is not a native python list, but tomlkit.items.Array.

class Array(Item, _CustomList):
    """
    An array literal
    """

    def __init__(self, value: list, trivia: Trivia, multiline: bool = False) -> None:
        super().__init__(trivia)
        ...

You can see to construct a Array instance, you must provide a trivia as argument.

But why data is not a list? I found when you call ConfigFile.get_parsed, it return a value with toml special type instance, which caused the issue.

So I think to fix this issue, the config returned by ConfigFile.get_parsed should be clean to a pure python instance with list and dict.

Here is a quick fix:

class PyprojectConfig(ConfigFile):
    """Represent a config inside a pyproject.toml file,
    under the [tool.tbump] key
    """

    def __init__(self, path: Path, doc: TOMLDocument):
        super().__init__(path, doc)

    def get_parsed(self) -> dict:
        try:
            # tool_section = self.doc["tool"]["tbump"].value
            # use unwrap here. then we will get a plain python object
            tool_section = self.doc.unwrap()["tool"]["tbump"]
        except KeyError as e:
            raise InvalidConfig(parse_error=e)

        return tool_section.value  # type: ignore
vipcxj added a commit to vipcxj/tbump that referenced this issue Jan 12, 2023
@hugetim
Copy link

hugetim commented Jan 25, 2023

I'm seeing the same issue.

@vipcxj
Copy link
Contributor Author

vipcxj commented May 4, 2023

@dmerejkowsky When will the new version be released? Even though pr was merged, it was still the old version on pip for months

@dmerejkowsky
Copy link
Collaborator

tbump 6.10.0 has been released and contains this fix. Enjoy :)

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

3 participants