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

AttributeError: 'TOMLDocument' object has no attribute 'unwrap' #834

Closed
jbmcfarlin31 opened this issue Feb 8, 2024 · 1 comment · Fixed by #835
Closed

AttributeError: 'TOMLDocument' object has no attribute 'unwrap' #834

jbmcfarlin31 opened this issue Feb 8, 2024 · 1 comment · Fixed by #835
Labels
bug Something isn't working properly

Comments

@jbmcfarlin31
Copy link

jbmcfarlin31 commented Feb 8, 2024

The problem

I just upgraded to the latest version of python-semantic-release (previously was using 6.2.5, now using 9.0.3).
Before, I was using a very small setup.cfg file for semantic-release configurations. Since this new upgrade, support for a setup.cfg has been moved to pyproject.toml.

I am fairly new to using a TOML file, so after reading the documentation I discovered I could use semantic-release generate-config to create a TOML block for semantic-release. I copied this output into my local pyproject.toml and then I also added some basics for the [project] section as well.

No matter what I do, when I run semantic-release version --noop or semantic-release publish --noop I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/semantic-release", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/commands/main.py", line 142, in main
    config_text = load_raw_config_file(config_path)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/util.py", line 82, in load_raw_config_file
    return parse_toml(raw_text)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/util.py", line 53, in parse_toml
    toml_text = tomlkit.loads(raw_text).unwrap()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TOMLDocument' object has no attribute 'unwrap'

I have tried commenting out everything in my pyproject.toml file and leaving just bare minimums and I still get this error. The error goes away if I remove the file entirely and run those commands however, semantic-release is not configured to look at the branches that I need it too so I get:

branch 'develop' isn't in any release groups; no release will be made

My pyproject.toml file consists of the following currently:

[tool.semantic_release]
assets = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
major_on_zero = true
tag_format = "v{version}"

# [semantic_release.branches.main]
# match = "(main|master)"
# prerelease_token = "rc"
# prerelease = false

# [semantic_release.changelog]
# template_dir = "templates"
# changelog_file = "CHANGELOG.md"
# exclude_commit_patterns = []

# [semantic_release.changelog.environment]
# block_start_string = "{%"
# block_end_string = "%}"
# variable_start_string = "{{"
# variable_end_string = "}}"
# comment_start_string = "{#"
# comment_end_string = "#}"
# trim_blocks = false
# lstrip_blocks = false
# newline_sequence = "\n"
# keep_trailing_newline = false
# extensions = []
# autoescape = true

# [semantic_release.commit_author]
# env = "GIT_COMMIT_AUTHOR"
# default = "semantic-release <semantic-release>"

# [semantic_release.commit_parser_options]
# allowed_tags = ["build", "chore", "ci", "docs", "feat", "fix", "perf", "style", "refactor", "test"]
# minor_tags = ["feat"]
# patch_tags = ["fix", "perf"]
# default_bump_level = 0

# [semantic_release.remote]
# name = "origin"
# type = "github"
# ignore_token_for_push = false

# [semantic_release.remote.token]
# env = "GH_TOKEN"

# [semantic_release.publish]
# dist_glob_patterns = ["dist/*"]
# upload_to_vcs_release = true

Am I doing something wrong with my pyproject.toml file or is something else wrong?

Expected behavior

When running semantic-release version --noop I would expect to see the version change if there is one applicable.

Environment

Please state which OS you are using and provide the output of the following commands:

python --version
pip --version
semantic-release --version
pip freeze

Output:

Python 3.11.6
pip 23.3.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
semantic-release, version 9.0.3

annotated-types==0.6.0
api-client==1.3.1
astroid==2.8.5
attrs==21.2.0
bandit==1.7.5
black==22.3.0
build==1.0.3
certifi==2021.10.8
cffi==1.15.0
cfgv==3.4.0
charset-normalizer==2.0.7
click==8.1.7
click-log==0.4.0
colorama==0.4.6
coverage==7.3.2
cryptography==35.0.0
dill==0.3.7
distlib==0.3.7
docutils==0.20.1
dotty-dict==1.3.1
dparse==0.6.3
exceptiongroup==1.1.3
Faker==19.8.0
filelock==3.12.4
flake8==6.1.0
Flask==2.1.0
gitdb==4.0.10
GitPython==3.1.36
gprof2dot==2021.2.21
greenlet==2.0.2
h11==0.14.0
identify==2.5.29
idna==3.3
importlib-metadata==6.8.0
importlib-resources==5.7.0
iniconfig==1.1.1
invoke==1.7.3
isort==5.10.1
itsdangerous==2.1.2
jaraco.classes==3.3.0
Jinja2==3.1.2
json-log-decorator==2.0.0
keyring==24.2.0
lazy-object-proxy==1.9.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mccabe==0.6.1
mdurl==0.1.2
more-itertools==10.1.0
mypy==0.910
mypy-extensions==0.4.3
mysql-connector-python==8.0.27
nh3==0.2.14
nodeenv==1.8.0
outcome==1.2.0
packaging==21.2
pathspec==0.11.2
pbr==5.11.1
pip-tools==7.3.0
pipdeptree==2.13.0
pkginfo==1.9.6
platformdirs==2.4.0
playwright==1.38.0
pluggy==1.4.0
pre-commit==3.4.0
protobuf==3.19.1
psutil==5.9.0
py==1.11.0
pycodestyle==2.11.0
pycparser==2.21
pydantic==2.6.0
pydantic_core==2.16.1
pyee==9.0.4
pyflakes==3.1.0
Pygments==2.16.1
PyJWT==2.3.0
pylint==2.11.1
pyparsing==2.4.7
pyperclip==1.8.2
pyproject_hooks==1.0.0
PySocks==1.7.1
pytest==8.0.0
pytest-cov==3.0.0
pytest-profiling==1.7.0
python-dateutil==2.8.2
python-frontmatter==1.0.0
python-gitlab==3.15.0
python-json-logger==2.0.1
python-logging-loki==0.3.1
python-semantic-release==9.0.3
pytz==2023.3.post1
PyYAML==6.0.1
readme-renderer==42.0
repoze.lru==0.7
requests==2.26.0
requests-toolbelt==1.0.0
rfc3339==6.2
rfc3986==2.0.0
rich==13.5.3
Routes==2.5.1
ruamel.yaml==0.17.32
ruamel.yaml.clib==0.2.7
safety==2.3.4
selenium==4.9.1
semver==2.13.0
shellingham==1.5.3
six==1.16.0
slack-sdk==3.22.0
slackblocks==0.9.11
smmap==5.0.1
sniffio==1.3.0
sortedcontainers==2.4.0
SQLAlchemy==1.4.48
sqlalchemy-querybuilder==0.1.5
stevedore==5.1.0
tabulate==0.9.0
tenacity==8.0.1
toml==0.10.2
tomli==2.0.1
tomlkit==0.10.2
tqdm==4.66.1
trio==0.22.2
trio-websocket==0.10.4
twine==3.8.0
typing_extensions==4.9.0
urllib3==1.26.2
virtualenv==20.24.5
Werkzeug==2.3.7
wrapt==1.13.3
wsproto==1.2.0
zipp==3.17.0

Please also indicate which Python build tool(s) you are using (e.g. pip, build,
poetry, etc.), including the version number too.

No build tools are currently in place.

Logging

Using semantic-release -vv version --noop:

[12:13:56] DEBUG    [semantic_release.cli.commands.main] DEBUG main.main: logging level set to: DEBUG                                                                                      main.py:105
           DEBUG    [git.util] DEBUG util.is_cygwin_git: Failed checking if running in CYGWIN due to: FileNotFoundError(2, 'No such file or directory')                                    util.py:420
           DEBUG    [semantic_release.cli.commands.main] DEBUG main.main: global cli options: GlobalCommandLineOptions(noop=False, verbosity=2, config_file='pyproject.toml',              main.py:123
                    strict=False)                                                                                                                                                                     
           INFO     [semantic_release.cli.util] INFO util.load_raw_config_file: Loading configuration from pyproject.toml                                                                   util.py:78
           DEBUG    [semantic_release.cli.util] DEBUG util.load_raw_config_file: Trying to parse configuration pyproject.toml in TOML format                                                util.py:81
Traceback (most recent call last):
  File "/usr/local/bin/semantic-release", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/commands/main.py", line 142, in main
    config_text = load_raw_config_file(config_path)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/util.py", line 82, in load_raw_config_file
    return parse_toml(raw_text)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/semantic_release/cli/util.py", line 53, in parse_toml
    toml_text = tomlkit.loads(raw_text).unwrap()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TOMLDocument' object has no attribute 'unwrap'
@jbmcfarlin31 jbmcfarlin31 added the bug Something isn't working properly label Feb 8, 2024
@codejedi365
Copy link
Contributor

This is a tomlkit version conflict. Thank you for finding this, it was unknown there was a compatibility issue with our minimum tomlkit version dependency. Your version 0.10.2 does not have the unpack() function on the TOMLContainer. Please upgrade tomlkit>=0.11.0.

Also your configuration is partially correct. When inside the pyproject.toml file, each TOML Table heading should be [tool.semantic_release.*]. Tables are basically converted into dictionaries or namespaces so you can think of the syntax that way. All your commented out TOML is missing the tool. prefix which is required when it is in the pyproject.toml file to be in accordance with PEP 517/518.

This info is in the help text of generate-config but I'll say it here anyway--PSR prints out configurations in 2 formats: JSON or TOML. There is an additional option --pyproject which will make sure to add the tool. prefix to the tables headers when printing the TOML.

codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Feb 9, 2024
TOMLDocument is missing the `unwrap()` function in `v0.10.2` which
causes an AttributeError to occur when attempting to read a the text
in `pyproject.toml` as discovered with python-semantic-release#834

Resolves: python-semantic-release#834
relekang pushed a commit that referenced this issue Feb 9, 2024
TOMLDocument is missing the `unwrap()` function in `v0.10.2` which
causes an AttributeError to occur when attempting to read a the text
in `pyproject.toml` as discovered with #834

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

Successfully merging a pull request may close this issue.

2 participants