summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2015-10-08 13:24:36 +0200
committerAnthon van der Neut <anthon@mnt.org>2015-10-08 13:24:36 +0200
commitd444338e4438323535476461414e1652bdd75cb3 (patch)
tree5d89094b84255ca652966457403fcb50d618ba4e
parent5bccee8a4c79f291e54b73f8f2bc0b711994f81f (diff)
downloadruamel.yaml-d444338e4438323535476461414e1652bdd75cb3.tar.gz
Jython compatibility
-rw-r--r--Makefile1
-rw-r--r--__init__.py11
-rw-r--r--comments.py8
-rw-r--r--composer.py14
-rw-r--r--constructor.py20
-rw-r--r--cyaml.py16
-rw-r--r--dumper.py15
-rw-r--r--emitter.py12
-rw-r--r--error.py6
-rw-r--r--loader.py21
-rw-r--r--parser_.py18
-rw-r--r--reader.py9
-rw-r--r--representer.py25
-rw-r--r--resolver.py12
-rw-r--r--scalarstring.py6
-rw-r--r--scanner.py12
-rw-r--r--serializer.py16
-rw-r--r--setup.py15
-rw-r--r--test/test_anchor.py3
-rw-r--r--test/test_cyaml.py4
-rw-r--r--test/test_string.py9
-rw-r--r--test/test_yaml.py7
-rw-r--r--tox.ini2
23 files changed, 196 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index e598faa..7111db8 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ gen_win_whl:
@python make_win_whl.py dist/$(PKGNAME)-$(VERSION)-*-none-any.whl
clean: clean_common
+ find . -name "*py.class" -exec rm {} +
cython: ext/_yaml.c
diff --git a/__init__.py b/__init__.py
index 37653cb..be2bf4b 100644
--- a/__init__.py
+++ b/__init__.py
@@ -9,7 +9,7 @@ from __future__ import absolute_import
_package_data = dict(
full_package_name="ruamel.yaml",
- version_info=[0, 10, 11],
+ version_info=(0, 10, 12),
author="Anthon van der Neut",
author_email="a.van.der.neut@ruamel.eu",
description="ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order", # NOQA
@@ -33,8 +33,10 @@ _package_data = dict(
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
+ "Programming Language :: Python :: 3.5",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
+ "Programming Language :: Python :: Implementation :: Jython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup"
]
@@ -69,12 +71,15 @@ del _convert_version
try:
from .cyaml import *
__with_libyaml__ = True
-except ImportError:
+except (ImportError, ValueError): # for Jython
__with_libyaml__ = False
import sys
# body extracted to main.py
-from .main import *
+try:
+ from .main import *
+except ImportError:
+ from ruamel.yaml.main import *
diff --git a/comments.py b/comments.py
index d869419..5db056f 100644
--- a/comments.py
+++ b/comments.py
@@ -14,7 +14,10 @@ a separate base
from collections import MutableSet
-from .compat import ordereddict
+try:
+ from .compat import ordereddict
+except ImportError:
+ from ruamel.yaml.compat import ordereddict
comment_attrib = '_yaml_comment'
format_attrib = '_yaml_format'
@@ -182,6 +185,9 @@ class CommentedBase(object):
@property
def fa(self):
+ """format attribute
+
+ set_flow_style()/set_block_style()"""
if not hasattr(self, Format.attrib):
setattr(self, Format.attrib, Format())
return getattr(self, Format.attrib)
diff --git a/composer.py b/composer.py
index 13436c8..a6bf24f 100644
--- a/composer.py
+++ b/composer.py
@@ -3,10 +3,16 @@ from __future__ import print_function
__all__ = ['Composer', 'ComposerError']
-from .error import MarkedYAMLError
-from .events import *
-from .nodes import *
-from .compat import utf8
+try:
+ from .error import MarkedYAMLError
+ from .events import *
+ from .nodes import *
+ from .compat import utf8
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import MarkedYAMLError
+ from ruamel.yaml.events import *
+ from ruamel.yaml.nodes import *
+ from ruamel.yaml.compat import utf8
class ComposerError(MarkedYAMLError):
diff --git a/constructor.py b/constructor.py
index c6ab23b..58a4689 100644
--- a/constructor.py
+++ b/constructor.py
@@ -12,12 +12,20 @@ import re
import sys
import types
-from .error import *
-from .nodes import *
-from .compat import (utf8, builtins_module, to_str, PY2, PY3, ordereddict,
- text_type)
-from .comments import *
-from .scalarstring import *
+try:
+ from .error import *
+ from .nodes import *
+ from .compat import (utf8, builtins_module, to_str, PY2, PY3, ordereddict,
+ text_type)
+ from .comments import *
+ from .scalarstring import *
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import *
+ from ruamel.yaml.nodes import *
+ from ruamel.yaml.compat import (utf8, builtins_module, to_str, PY2, PY3,
+ ordereddict, text_type)
+ from ruamel.yaml.comments import *
+ from ruamel.yaml.scalarstring import *
class ConstructorError(MarkedYAMLError):
diff --git a/cyaml.py b/cyaml.py
index 276e029..bf4e639 100644
--- a/cyaml.py
+++ b/cyaml.py
@@ -5,12 +5,16 @@ __all__ = ['CBaseLoader', 'CSafeLoader', 'CLoader',
from _ruamel_yaml import CParser, CEmitter
-from .constructor import *
-
-from .serializer import *
-from .representer import *
-
-from .resolver import *
+try:
+ from .constructor import *
+ from .serializer import *
+ from .representer import *
+ from .resolver import *
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.constructor import *
+ from ruamel.yaml.serializer import *
+ from ruamel.yaml.representer import *
+ from ruamel.yaml.resolver import *
class CBaseLoader(CParser, BaseConstructor, BaseResolver):
diff --git a/dumper.py b/dumper.py
index f83228a..82334a2 100644
--- a/dumper.py
+++ b/dumper.py
@@ -2,10 +2,17 @@ from __future__ import absolute_import
__all__ = ['BaseDumper', 'SafeDumper', 'Dumper', 'RoundTripDumper']
-from .emitter import *
-from .serializer import *
-from .representer import *
-from .resolver import *
+try:
+ from .emitter import *
+ from .serializer import *
+ from .representer import *
+ from .resolver import *
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.emitter import *
+ from ruamel.yaml.serializer import *
+ from ruamel.yaml.representer import *
+ from ruamel.yaml.resolver import *
+
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
diff --git a/emitter.py b/emitter.py
index 2e5ebdc..07d85ba 100644
--- a/emitter.py
+++ b/emitter.py
@@ -10,9 +10,15 @@ from __future__ import print_function
__all__ = ['Emitter', 'EmitterError']
-from .error import YAMLError
-from .events import *
-from .compat import utf8, text_type, PY2, nprint, dbg, DBG_EVENT
+try:
+ from .error import YAMLError
+ from .events import *
+ from .compat import utf8, text_type, PY2, nprint, dbg, DBG_EVENT
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import YAMLError
+ from ruamel.yaml.events import *
+ from ruamel.yaml.compat import utf8, text_type, PY2, nprint, dbg, DBG_EVENT
+
class EmitterError(YAMLError):
diff --git a/error.py b/error.py
index 2b76904..e6e7585 100644
--- a/error.py
+++ b/error.py
@@ -2,7 +2,11 @@ from __future__ import absolute_import
__all__ = ['Mark', 'YAMLError', 'MarkedYAMLError']
-from .compat import utf8
+try:
+ from .compat import utf8
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.compat import utf8
+
class Mark(object):
diff --git a/loader.py b/loader.py
index 16f01b6..d25a75e 100644
--- a/loader.py
+++ b/loader.py
@@ -2,12 +2,21 @@ from __future__ import absolute_import
__all__ = ['BaseLoader', 'SafeLoader', 'Loader', 'RoundTripLoader']
-from .reader import *
-from .scanner import *
-from .parser_ import *
-from .composer import *
-from .constructor import *
-from .resolver import *
+try:
+ from .reader import *
+ from .scanner import *
+ from .parser_ import *
+ from .composer import *
+ from .constructor import *
+ from .resolver import *
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.reader import *
+ from ruamel.yaml.scanner import *
+ from ruamel.yaml.parser_ import *
+ from ruamel.yaml.composer import *
+ from ruamel.yaml.constructor import *
+ from ruamel.yaml.resolver import *
+
class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor,
diff --git a/parser_.py b/parser_.py
index 0afb596..84ac35a 100644
--- a/parser_.py
+++ b/parser_.py
@@ -71,11 +71,19 @@ from __future__ import absolute_import
__all__ = ['Parser', 'ParserError']
-from .error import MarkedYAMLError
-from .tokens import *
-from .events import *
-from .scanner import *
-from .compat import utf8
+try:
+ from .error import MarkedYAMLError
+ from .tokens import *
+ from .events import *
+ from .scanner import *
+ from .compat import utf8
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import MarkedYAMLError
+ from ruamel.yaml.tokens import *
+ from ruamel.yaml.events import *
+ from ruamel.yaml.scanner import *
+ from ruamel.yaml.compat import utf8
+
class ParserError(MarkedYAMLError):
diff --git a/reader.py b/reader.py
index 7bbec42..5248380 100644
--- a/reader.py
+++ b/reader.py
@@ -23,8 +23,13 @@ __all__ = ['Reader', 'ReaderError']
import codecs
import re
-from .error import YAMLError, Mark
-from .compat import text_type, binary_type, PY3
+try:
+ from .error import YAMLError, Mark
+ from .compat import text_type, binary_type, PY3
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import YAMLError, Mark
+ from ruamel.yaml.compat import text_type, binary_type, PY3
+
class ReaderError(YAMLError):
diff --git a/representer.py b/representer.py
index c1bbb8b..2016471 100644
--- a/representer.py
+++ b/representer.py
@@ -4,11 +4,19 @@ from __future__ import print_function
__all__ = ['BaseRepresenter', 'SafeRepresenter', 'Representer',
'RepresenterError', 'RoundTripRepresenter']
-from .error import *
-from .nodes import *
-from .compat import text_type, binary_type, to_unicode, PY2, PY3, \
- ordereddict, nprint
-from .scalarstring import *
+try:
+ from .error import *
+ from .nodes import *
+ from .compat import text_type, binary_type, to_unicode, PY2, PY3, \
+ ordereddict, nprint
+ from .scalarstring import *
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import *
+ from ruamel.yaml.nodes import *
+ from ruamel.yaml.compat import text_type, binary_type, to_unicode, PY2, \
+ PY3, ordereddict, nprint
+ from ruamel.yaml.scalarstring import *
+
import datetime
import sys
@@ -566,8 +574,13 @@ Representer.add_multi_representer(object,
Representer.represent_object)
-from .comments import CommentedMap, CommentedOrderedMap, CommentedSeq, \
+try:
+ from .comments import CommentedMap, CommentedOrderedMap, CommentedSeq, \
CommentedSet, comment_attrib, merge_attrib
+except ImportError: # for Jython
+ from ruamel.yaml.comments import CommentedMap, CommentedOrderedMap, \
+ CommentedSeq, CommentedSet, comment_attrib, merge_attrib
+
class RoundTripRepresenter(SafeRepresenter):
diff --git a/resolver.py b/resolver.py
index d385b0e..bae0caa 100644
--- a/resolver.py
+++ b/resolver.py
@@ -2,9 +2,15 @@ from __future__ import absolute_import
__all__ = ['BaseResolver', 'Resolver']
-from .error import *
-from .nodes import *
-from .compat import string_types
+try:
+ from .error import *
+ from .nodes import *
+ from .compat import string_types
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import *
+ from ruamel.yaml.nodes import *
+ from ruamel.yaml.compat import string_types
+
import re
diff --git a/scalarstring.py b/scalarstring.py
index a628396..59951c9 100644
--- a/scalarstring.py
+++ b/scalarstring.py
@@ -3,7 +3,11 @@ from __future__ import print_function
__all__ = ["ScalarString", "PreservedScalarString"]
-from .compat import text_type
+try:
+ from .compat import text_type
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.compat import text_type
+
class ScalarString(text_type):
diff --git a/scanner.py b/scanner.py
index 24a13a8..97eb59f 100644
--- a/scanner.py
+++ b/scanner.py
@@ -31,9 +31,15 @@ from __future__ import print_function
__all__ = ['Scanner', 'RoundTripScanner', 'ScannerError']
-from .error import MarkedYAMLError
-from .tokens import *
-from .compat import utf8, unichr, PY3
+try:
+ from .error import MarkedYAMLError
+ from .tokens import *
+ from .compat import utf8, unichr, PY3
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import MarkedYAMLError
+ from ruamel.yaml.tokens import *
+ from ruamel.yaml.compat import utf8, unichr, PY3
+
class ScannerError(MarkedYAMLError):
diff --git a/serializer.py b/serializer.py
index 0bdc558..125729e 100644
--- a/serializer.py
+++ b/serializer.py
@@ -4,11 +4,17 @@ __all__ = ['Serializer', 'SerializerError']
import re
-from .error import YAMLError
-from .events import *
-from .nodes import *
+try:
+ from .error import YAMLError
+ from .events import *
+ from .nodes import *
+ from .compat import nprint, DBG_NODE, dbg
+except (ImportError, ValueError): # for Jython
+ from ruamel.yaml.error import YAMLError
+ from ruamel.yaml.events import *
+ from ruamel.yaml.nodes import *
+ from ruamel.yaml.compat import nprint, DBG_NODE, dbg
-from .compat import nprint, DBG_NODE, dbg
class SerializerError(YAMLError):
@@ -163,4 +169,4 @@ class Serializer(object):
self.ascend_resolver()
def templated_id(s):
- return Serializer.ANCHOR_RE.match(s) \ No newline at end of file
+ return Serializer.ANCHOR_RE.match(s)
diff --git a/setup.py b/setup.py
index 933e5e6..4e9407b 100644
--- a/setup.py
+++ b/setup.py
@@ -13,6 +13,7 @@ full_package_name = None
# # __init__.py parser
import sys
+import platform
from _ast import * # NOQA
from ast import parse
@@ -30,7 +31,7 @@ if sys.version_info < (3, 4):
class NameConstant:
pass
-if sys.version_info < (2, 7):
+if sys.version_info < (2, 7) or platform.python_implementation() == 'Jython':
class Set():
pass
@@ -160,8 +161,6 @@ exclude_files = [
# # imports
import os
-import sys
-import platform
from setuptools import setup, Extension, Distribution # NOQA
from setuptools.command import install_lib
@@ -231,7 +230,7 @@ class NameSpacePackager(object):
self._pkg = [None, None] # required and pre-installable packages
if sys.argv[0] == 'setup.py' and sys.argv[1] == 'install' and \
'--single-version-externally-managed' not in sys.argv:
- print('error: have to install with "pip install ."')
+ print('error: you have to install with "pip install ."')
sys.exit(1)
# If you only support an extension module on Linux, Windows thinks it
# is pure. That way you would get pure python .whl files that take
@@ -471,6 +470,8 @@ class NameSpacePackager(object):
pyver = 'py{0}{1}'.format(*sys.version_info)
elif implementation == 'PyPy':
pyver = 'pypy' if sys.version_info < (3, ) else 'pypy3'
+ elif implementation == 'Jython':
+ pyver = 'jython'
packages.extend(ir.get(pyver, []))
for p in packages:
# package name starting with * means use local source tree, non-published
@@ -510,8 +511,10 @@ class NameSpacePackager(object):
return self._ext_modules
if '--version' in sys.argv:
return None
- # if sys.platform == "win32":
- # return None
+ if platform.python_implementation() == 'Jython':
+ return None
+ if sys.platform == "win32":
+ return None
import tempfile
import shutil
from textwrap import dedent
diff --git a/test/test_anchor.py b/test/test_anchor.py
index ae2ac59..b0ce521 100644
--- a/test/test_anchor.py
+++ b/test/test_anchor.py
@@ -6,6 +6,7 @@ testing of anchors and the aliases referring to them
import pytest
from textwrap import dedent
+import platform
import ruamel.yaml
from roundtrip import round_trip, dedent, round_trip_load, round_trip_dump
@@ -95,6 +96,8 @@ class TestAnchorsAliases:
f: *etemplate
""")
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_alias_before_anchor(self):
from ruamel.yaml.composer import ComposerError
with pytest.raises(ComposerError):
diff --git a/test/test_cyaml.py b/test/test_cyaml.py
index 9ef6447..26f2683 100644
--- a/test/test_cyaml.py
+++ b/test/test_cyaml.py
@@ -1,5 +1,9 @@
+import platform
+import pytest
+@pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_load_cyaml():
import ruamel.yaml
assert ruamel.yaml.__with_libyaml__
diff --git a/test/test_string.py b/test/test_string.py
index 8c08e7d..8e85cdf 100644
--- a/test/test_string.py
+++ b/test/test_string.py
@@ -15,6 +15,7 @@ and the chomping modifiers:
"""
import pytest
+import platform
import ruamel.yaml
from ruamel.yaml.compat import ordereddict
@@ -32,6 +33,8 @@ class TestYAML:
a: '12345'
""")
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_preserve_string(self):
round_trip("""
a: |
@@ -39,6 +42,8 @@ class TestYAML:
def
""", intermediate=dict(a='abc\ndef\n'))
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_preserve_string_strip(self):
s = """
a: |-
@@ -48,6 +53,8 @@ class TestYAML:
"""
round_trip(s, intermediate=dict(a='abc\ndef'))
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_preserve_string_keep(self):
# with pytest.raises(AssertionError) as excinfo:
round_trip("""
@@ -59,6 +66,8 @@ class TestYAML:
b: x
""", intermediate=dict(a='ghi\njkl\n\n\n', b='x'))
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_preserve_string_keep_at_end(self):
# at EOF you have to specify the ... to get proper "closure"
# of the multiline scalar
diff --git a/test/test_yaml.py b/test/test_yaml.py
index 75f2479..50c9fa1 100644
--- a/test/test_yaml.py
+++ b/test/test_yaml.py
@@ -6,6 +6,7 @@ various test cases for YAML files
"""
import pytest
+import platform
import ruamel.yaml
from ruamel.yaml.compat import ordereddict
@@ -90,6 +91,8 @@ class TestYAML:
- baz
""")
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_blank_line_after_literal_chip(self):
s = """
c:
@@ -111,6 +114,8 @@ class TestYAML:
assert d['c'][0].split('it.')[1] == '\n'
assert d['c'][1].split('line.')[1] == '\n'
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_blank_line_after_literal_keep(self):
""" have to insert an eof marker in YAML to test this"""
s = """
@@ -134,6 +139,8 @@ class TestYAML:
assert d['c'][0].split('it.')[1] == '\n\n'
assert d['c'][1].split('line.')[1] == '\n\n\n'
+ @pytest.mark.skipif(platform.python_implementation() == 'Jython',
+ reason="Jython throws RepresenterError")
def test_blank_line_after_literal_strip(self):
s = """
c:
diff --git a/tox.ini b/tox.ini
index 3ecca0e..7481b8c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py27,py35,py34,py33,py26,pypy
+envlist = py27,py35,py34,py33,py26,pypy,jython
[testenv]
commands =