plone / meta

Meta issues concerning many/all of the plone repositories.
4 stars 4 forks source link

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

Open 1letter opened 5 months ago

1letter commented 5 months ago

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 commented 5 months ago

@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 commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

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? 🤔