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

Escaped Backslash in .meta.toml throw an error decoder.TomlDecodeError: Reserved escape sequence used #229

Open
1letter opened this issue May 15, 2024 · 5 comments

Comments

@1letter
Copy link

1letter commented May 15, 2024

Not sure, but it looks that regex expressions not right parsed/evaluated by meta package.

python -m venv ./venv
. venv/bin/activate
pip install -r requirements.txt
python -V
3.12.3
python config-package.py --no-commit ~/Development/Projects/projects/my.addon

in the .meta.toml of my.addon file exists the following section:

[gitlab]
jobs = [
    "lint",
    "release-ready",
    "dependencies",
    "circular-dependencies",
    ]

extra_lines = """
Test Coverage:
  stage: coverage
  tags:
    - docker
  script:
    - tox -e init
    - tox -e coverage
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml    
  coverage: /TOTAL.* \*\*(\d+)\%\*\*/
  except:
    - schedules
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "push"
      when: never
"""

if i escape the backslashes in the coverage rule, no effect, same error happens

coverage: /TOTAL.* \\*\\*(\\d+)\\%\*\\*/

Looks like the same error in #223

Perhaps a multiline literal string with three single quotes help? See https://toml.io/en/v1.0.0#string

@1letter
Copy link
Author

1letter commented May 15, 2024

@gforcada i can't create a PR in this repro. i have tested the multiline single quotes locally. the error is gone. but i didn't investigate site effects of my change. on the first view, only the relevant changes in then configfiles happen.

I changed in toml_encoder.py only the dump_string function.

import toml


def dump_string(value):
    if "\n" in value:
        # Return a multi line string as a multi line string,
        # instead of on one line with literal '\n' in it.
        return f"'''\n{value}'''"
    return toml.encoder._dump_str(value)


class TomlArraySeparatorEncoderWithNewline(toml.TomlArraySeparatorEncoder):
    """Special version indenting the first element of and array.

    In https://github.com/zopefoundation/meta/issues/118 we suggest to switch
    to Python 3.11 and its built-in toml support. We'll see if this path is
    still needed then.
    """

    def __init__(self, _dict=dict, preserve=False, separator=",",
                 indent_first_line=False):
        super(TomlArraySeparatorEncoderWithNewline, self).__init__(
            _dict=_dict, preserve=preserve, separator=separator)
        self.indent_first_line = indent_first_line
        self.dump_funcs[str] = dump_string

    def dump_list(self, v):
        t = []
        retval = "["
        if self.indent_first_line:
            retval += self.separator.strip(',')
        for u in v:
            t.append(self.dump_value(u))
        while t != []:
            s = []
            for u in t:
                if isinstance(u, list):
                    for r in u:
                        s.append(r)
                else:
                    retval += " " + u + self.separator
            t = s
        retval += " ]"
        return retval

@1letter
Copy link
Author

1letter commented Jun 25, 2024

@gforcada why can't i create an PR in this repro? i filled out the plone contributor agreement or is this a special package?

@gforcada
Copy link
Member

gforcada commented Jul 1, 2024

@1letter hey, sorry for the long delay, I'm a bit over my capacity as of late 😵‍💫

As for not being able to create PRs here... let me have a look, I certainly did not make plone/meta special (at least that I remember).

@gforcada
Copy link
Member

gforcada commented Jul 1, 2024

Turns out that only the @plone/ci-team is able to create PRs here, not sure who decided that 🤷🏾

You can still fork the project and make the changes there, and point here to the branch, then I(?) can create the PR on your behalf? Would that be reasonable? at least for this one to not get blocked...

@gforcada
Copy link
Member

gforcada commented Jul 1, 2024

More on the subject of the issue: I kind of remember that on zopefoundation/meta they were arguing about updating the toml library being used, maybe they have some other goodies/updates there that might be worth porting over here? 🤔

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

2 participants