Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

How to override the base resolver in pyyaml

$
0
0

I have found several comments and a similar question on how to override the resolver.https://github.com/yaml/pyyaml/issues/376#issuecomment-576821252

@StrayDragon Actually you can change this behavior if you want by overriding the bool tag regex in the base resolver (https://github.com/yaml/pyyaml/blob/master/lib/yaml/resolver.py#L170-L175), then wire up your resolver instead of the default on a new loader instance (which gets passed to yaml.load().

In theory I get it, but when trying to implement isn't working.

This is my python code

 import yamlimport reclass CustomLoader(yaml.FullLoader):    pass# Override the boolean tag regexyaml.resolver.BaseResolver.add_implicit_resolver('tag:yaml.org,2002:bool',    re.compile(        r'''^(?:yes|Yes|YES|no|No|NO            |true|True|TRUE|false|False|FALSE            |off|Off|OFF)$''',        re.X    ),    list('yYnNtTfFoO'))# Read the workflow YAML file using the custom loaderwith open(file_path, 'r') as file:    yaml_content = yaml.load(file, Loader=CustomLoader)

And I thought it will work, but my original YML file

name: cloudon:  push:  workflow_dispatch:concurrency:  group: "${{ github.ref }}"

Is still being replaced

name: cloud-cicd-ghc-test/diego-test-migrate-to-github-ciTrue:  push: null  workflow_dispatch: nullconcurrency:  group: "${{ github.ref }}"

So not sure how to do this process


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>