jeff-hykin / ez_yaml

💾 📦 ✅ Read write yaml easily
MIT License
5 stars 0 forks source link

Can't import v2.0.0 #3

Closed gdubicki closed 1 year ago

gdubicki commented 1 year ago

Hi @jeff-hykin!

Sadly the latest version doesn't work if you import it f.e. in a virtualenv:

(venv_ez_yaml) gdubicki@locahost ~
$ python3
Python 3.11.2 (main, Feb 16 2023, 02:55:59) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ez_yaml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/gdubicki/venv_ez_yaml/lib/python3.11/site-packages/ez_yaml/__init__.py", line 1, in <module>
    from .__dependencies__ import ruamel
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'ez_yaml.__dependencies__'
jeff-hykin commented 1 year ago

Thanks for reporting this! Looks like the final tar file didn't include any nested folders. I rebuilt/published with 2.0.1 which should make everything work now.

gdubicki commented 1 year ago

Thanks, but 2.0.1 is not published in pypi: https://pypi.org/project/ez-yaml/

jeff-hykin commented 1 year ago

Wow, sorry I screwed this up twice. 2.0.1 is published now @gdubicki

gdubicki commented 1 year ago

Thanks, but now I have a different error:

ImportError: cannot import name 'ez_yaml' from 'ez_yaml' (/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/ez_yaml/__init__.py)

See the full stack trace here.

jeff-hykin commented 1 year ago

Man I thought I messed up again, but this is actually intended!

Just replace from ez_yaml import ez_yaml with import ez_yaml and you should be good to go. @gdubicki

jeff-hykin commented 1 year ago

Just wanted to check back in on this, I'll reopen if its still an issue

gdubicki commented 1 year ago

Hey, sorry for a late reply. Yes, that import change has helped with original issue, but after doing that we had another problem, which you can see in the failed tests here: https://github.com/gitlabform/gitlabform/actions/runs/5975165001/job/16210621488

But I don't want to bother you with this anymore, we don't really need to update ez_yaml, our current version (1.2.0) works like a charm.

Thanks and have a nice day! :)

jeff-hykin commented 1 year ago

Glad to hear the old version works for you guys 👍

I'm confused by the test failures though, is ordereddict a custom version of python's OrderedDict?

ez_yaml.__dependencies__.ruamel.yaml.representer.RepresenterError: cannot represent an object: ordereddict([('config_version', 3), ('projects_and_groups', ordereddict([('gitlabform_group_disarray/gitlabform_project_gents', ordereddict([('project', ordereddict([('archive', True)]))]))]))])

I tried to recreate with python's order dict and couldn't reproduce

>>> from collections import OrderedDict
>>> import ez_yaml
>>> a = OrderedDict([
...     (
...         'projects_and_groups', OrderedDict([
...             (
...                 'group/*', OrderedDict(
...                     [(
...                         'merge_requests_approval_rules', {'legacy': {'approvals_required': 0, 'name': 'Approvers (configured using GitLabForm)'}}
...                     )]
...                 )
...             ),
...             (
...                 'group/envs/qa', OrderedDict([
...                     (
...                         'merge_requests_approvals', OrderedDict([
...                             (
...                                 'reset_approvals_on_push', False
...                             ),
...                             (
...                                 'disable_overriding_approvers_per_merge_request', True
...                             ),
...                             (
...                                 'merge_requests_author_approval', False
...                             )
...                         ])
...                     ),
...                     (
...                         'merge_requests_approval_rules', {'legacy': {'approvals_required': 2, 'name': 'Approvers (configured using GitLabForm)', 'users': ['user1', 'user2'], 'groups': ['some-group']}}
...                     )
...                 ])
...             )
...         ])
...     )
... ])
KeyboardInterrupt
>>> print(ez_yaml.to_string(a))
!!omap
- projects_and_groups: !!omap
  - group/*: !!omap
    - merge_requests_approval_rules:
         legacy:
            approvals_required: 0
            name: Approvers (configured using GitLabForm)
  - group/envs/qa: !!omap
    - merge_requests_approvals: !!omap
      - reset_approvals_on_push: false
      - disable_overriding_approvers_per_merge_request: true
      - merge_requests_author_approval: false
    - merge_requests_approval_rules:
         legacy:
            approvals_required: 2
            name: Approvers (configured using GitLabForm)
            users:
            - user1
            - user2
            groups:
            - some-group
gdubicki commented 3 months ago

In retrospect it was a bad idea to add a link to tests output instead of a copy of the error here - the logs are not available anymore and I don't remember what the error was, exactly. :P

Anyway, I still have a problem as I retried to use v2.2.0 of ez_yaml.

The error is:

>       gitlabform = get_gitlabform(config=config_yaml, target=target)

tests/unit/test_target_all_defined.py:19: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/unit/__init__.py:22: in get_gitlabform
    gf = GitLabForm(
gitlabform/__init__.py:112: in __init__
    self.gitlab, self.configuration = self._initialize_configuration_and_gitlab()
gitlabform/__init__.py:352: in _initialize_configuration_and_gitlab
    configuration_transformers.transform(configuration)
gitlabform/configuration/transform.py:38: in transform
    config_before = ez_yaml.to_string(obj=configuration.config, options={})
venv/lib/python3.12/site-packages/ez_yaml/__init__.py:53: in to_string
    yaml.dump(obj, string_stream, **options)
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/main.py:595: in dump
    return self.dump_all([data], stream, transform=transform)
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/main.py:604: in dump_all
    self._context_manager.dump(data)
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/main.py:940: in dump
    self._yaml.representer.represent(data)
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/representer.py:80: in represent
    node = self.represent_data(data)
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/representer.py:122: in represent_data
    raise error
venv/lib/python3.12/site-packages/ez_yaml/__dependencies__/ruamel/yaml/representer.py:114: in represent_data
    node = self.yaml_representers[None](self, data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ez_yaml.__dependencies__.ruamel.yaml.representer.RoundTripRepresenter object at 0x106783200>
data = ordereddict({'config_version': 3, 'gitlab': ordereddict({'url': 'https://gitlab.com', 'token': 'foobar'}), 'projects_a...ojects/*': ordereddict({'foobar': 'barfoo'}), 'group_and_all_its_descendants/**': ordereddict({'barfoo': 'foobar'})})})

    def represent_undefined(self, data):
        # type: (Any) -> None
>       raise RepresenterError(_F('cannot represent an object: {data!s}', data=data))
E       ez_yaml.__dependencies__.ruamel.yaml.representer.RepresenterError: cannot represent an object: ordereddict({'config_version': 3, 'gitlab': ordereddict({'url': 'https://gitlab.com', 'token': 'foobar'}), 'projects_and_groups': ordereddict({'group_only': ordereddict({'foo': 'bar'}), 'subgroup/only': ordereddict({'bar': 'foo'}), 'group_and_its_projects/*': ordereddict({'foobar': 'barfoo'}), 'group_and_all_its_descendants/**': ordereddict({'barfoo': 'foobar'})})})

I'm confused by the test failures though, is ordereddict a custom version of python's OrderedDict?

It seems to be a ruamel's thing, see https://github.com/pycontribs/ruamel-yaml/blob/4c1728aab0cd5c9bfc84cf1132b228074b783907/compat.py#L38.