GithubHelp home page GithubHelp logo

aspy.yaml's People

Contributors

asottile avatar mxr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aspy.yaml's Issues

Cannot load merge `<<: *y`

>>> aspy.yaml.ordered_load('x: &y\n  a: b\nz:\n  <<: *y\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/tmp/test/venv/lib/python3.6/site-packages/aspy/yaml/__init__.py", line 39, in ordered_load
    return yaml.load(stream, Loader=OrderedLoader)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 37, in get_single_data
    return self.construct_document(node)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 41, in construct_document
    data = self.construct_object(node)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/aspy/yaml/__init__.py", line 17, in <lambda>
    lambda loader, node: OrderedDict(loader.construct_pairs(node)),
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 141, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/aspy/yaml/__init__.py", line 17, in <lambda>
    lambda loader, node: OrderedDict(loader.construct_pairs(node)),
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 140, in construct_pairs
    key = self.construct_object(key_node, deep=deep)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/private/tmp/test/venv/lib/python3.6/site-packages/yaml/constructor.py", line 414, in construct_undefined
    node.start_mark)
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:merge'
  in "<unicode string>", line 4, column 3

dumping list of strings

Hi anthony,

I'm trying to read, modify and write pre-commit yaml files and the lists keep getting messed up. Do you know what I'm doing wrong?

import io
from aspy.yaml import ordered_dump
from aspy.yaml import ordered_load
PRE_COMMIT_YAML = '.pre-commit-config.yaml'

config_data = ordered_load(io.open(PRE_COMMIT_YAML).read())
YAML_DUMP_KWARGS = {
    'default_flow_style': False,
    # Use unicode
    'encoding': None,
    'indent': 4,
}
with io.open(PRE_COMMIT_YAML, 'w', encoding='UTF-8') as pre_commit_file:
    pre_commit_file.write(ordered_dump(config_data, **YAML_DUMP_KWARGS))
     sha: v0.3.5
     hooks:
     -   id: reorder-python-imports
-        args: [
-            '--remove-import', 'from __future__ import absolute_import',
-            '--remove-import', 'from __future__ import unicode_literals',
-        ]
+        args:
+        - --remove-import
+        - from __future__ import absolute_import
+        - --remove-import
+        - from __future__ import unicode_literals

test_ordered_dump_plain_dict_py36_plus fails on openSUSE Leap 15.1 running Python 3.6 and pytest 3

[   46s] ============================= test session starts ==============================
[   46s] platform linux -- Python 3.6.5, pytest-3.10.1, py-1.5.2, pluggy-0.8.0
[   46s] rootdir: /home/abuild/rpmbuild/BUILD/aspy.yaml-1.3.0, inifile:
[   46s] collected 4 items
[   46s] 
[   46s] tests/yaml_test.py ...F                                                  [100%]
[   46s] 
[   46s] =================================== FAILURES ===================================
[   46s] ____________________ test_ordered_dump_plain_dict_py36_plus ____________________
[   46s] 
[   46s]     @pytest.mark.xfail(sys.version_info < (3, 6), reason='py36+')
[   46s]     def test_ordered_dump_plain_dict_py36_plus():
[   46s]         ret = aspy.yaml.ordered_dump({'z': 1, 'a': 2, 'c': 3, 'b': 4, 'd': -1})
[   46s] >       assert ret == (
[   46s]             'z: 1\n'
[   46s]             'a: 2\n'
[   46s]             'c: 3\n'
[   46s]             'b: 4\n'
[   46s]             'd: -1\n'
[   46s]         )
[   46s] E       AssertionError: assert '{z: 1, a: 2,...: 4, d: -1}\n' == 'z: 1\na: 2\nc...b: 4\nd: -1\n'
[   46s] E         - {z: 1, a: 2, c: 3, b: 4, d: -1}
[   46s] E         + z: 1
[   46s] E         + a: 2
[   46s] E         + c: 3
[   46s] E         + b: 4
[   46s] E         + d: -1

Order only retained in OrderedDict

As of Python 3.7, dicts are ordered in Python ๐ŸŽ‰ but it seems like aspy.yaml only retains order for OrderedDicts? Any chance of fixing this for 3.7 and later?

sdist for 0.2.2?

Is it deliberate that there's no sdist tarball for version 0.2.2 on PyPi? There appears to be an sdist for 0.2.1, but only a whl for 0.2.2

Name clash with pypi package aspy

Just fyi, https://pypi.org/project/aspy/ has been registered by another project.

c93f2de here is 2014, while their first commit was September 2018.

I'm currently packaging aspy.yaml for openSUSE and the other dependencies of https://build.opensuse.org/package/show/home:jayvdb:tox/python-pre-commit, and was just checking because it isnt the first time a namespace caused problems. https://github.com/asottile/aspy.refactor_imports also looks quite useful, so that would mean we need to create an 'extra' package for the namespace dir and its __init__ , or make one package dependent on the other even if not strictly true. e.g. the fictitious jaraco.base package.

As another aside, I noticed most of your packages sdist on PyPI do not include tests. That means I need to use the GitHub archive instead of the PyPI sdist for packaging, which is a bit annoying because the packaging tools (py2pack) dont automatically fetch new releases from GitHub. Not an immediate concern for the initial packaging, but definitely helpful to include them as new releases are cut.

ordered_load does not error on duplicate keys (can impact pre-commit usage)

After reading this lib to see if what I'm looking for is reasonable, I think it is, but admit to not being certain. I don't have enough background with pyyaml to be sure.

ordered_load would ideally have an option to error when loading a duplicate key. This lets calling libraries (most notably pre-commit) treat these as errors or at least warnings.

Consider the following malformed .pre-commit-config.yaml file:

repos:
- repo: https://github.com/python/black
  rev: 19.3b0
  hooks:
  - id: black
    language_version: python3
repos:  # DUPLICATE KEY!
- repo: https://gitlab.com/pycqa/flake8
  rev: 3.7.8
  hooks:
  - id: flake8
    language_version: python3
    additional_dependencies: ['flake8-bugbear==19.3.0']

when loaded by pre-commit via ordered_load, it would be nice if this either failed, or at least produced a warning of some kind.

The current behavior is "last one wins" so you would see the flake8 hook above, but not the black one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.