15
0

Accepting request 1030107 from devel:languages:python

- Add drop-python2-support.patch gh#bkabrda/anymarkup-core#7
- Remove python-six dependency
- Use a more specific python_sitelib expression in %files
- Use autosetup instead of setup and patch

OBS-URL: https://build.opensuse.org/request/show/1030107
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-anymarkup-core?expand=0&rev=3
This commit is contained in:
2022-10-20 09:11:42 +00:00
committed by Git OBS Bridge
3 changed files with 199 additions and 5 deletions

186
drop-python2-support.patch Normal file
View File

@@ -0,0 +1,186 @@
From 1d0c5673c15116625c02316b2605648b92cf18a4 Mon Sep 17 00:00:00 2001
From: Daniel Garcia Moreno <daniel.garcia@suse.com>
Date: Thu, 20 Oct 2022 08:45:53 +0200
Subject: [PATCH] Drop python2 support
Python2 is very old and not maintained anymore, this patch removes the
python-six dependency and drop python2 support.
---
anymarkup_core/__init__.py | 36 +++++++++++++-----------------------
requirements.txt | 1 -
setup.py | 7 +++----
test/test_parse.py | 5 ++---
test/test_serialize.py | 3 +--
5 files changed, 19 insertions(+), 33 deletions(-)
diff --git a/anymarkup_core/__init__.py b/anymarkup_core/__init__.py
index 91f4133..21ccc78 100644
--- a/anymarkup_core/__init__.py
+++ b/anymarkup_core/__init__.py
@@ -7,7 +7,6 @@ import os
import re
import traceback
-import six
try:
import configobj
except ImportError:
@@ -95,7 +94,7 @@ def parse(inp, format=None, encoding='utf-8', force_types=True, interpolate=True
if hasattr(inp, 'read'):
proper_inp = inp.read()
# if proper_inp is unicode, encode it
- if isinstance(proper_inp, six.text_type):
+ if isinstance(proper_inp, str):
proper_inp = proper_inp.encode(encoding)
# try to guess markup type
@@ -105,7 +104,7 @@ def parse(inp, format=None, encoding='utf-8', force_types=True, interpolate=True
fmt = _get_format(format, fname, proper_inp)
# make it look like file-like bytes-yielding object
- proper_inp = six.BytesIO(proper_inp)
+ proper_inp = io.BytesIO(proper_inp)
try:
res = _do_parse(proper_inp, fmt, encoding, force_types, interpolate)
@@ -232,22 +231,17 @@ def _do_parse(inp, fmt, encoding, force_types, interpolate):
cfg = configobj.ConfigObj(inp, encoding=encoding, interpolation=interpolate)
res = cfg.dict()
elif fmt == 'json':
- if six.PY3:
- # python 3 json only reads from unicode objects
- inp = io.TextIOWrapper(inp, encoding=encoding)
- res = json.load(inp)
- else:
- res = json.load(inp, encoding=encoding)
+ # python 3 json only reads from unicode objects
+ inp = io.TextIOWrapper(inp, encoding=encoding)
+ res = json.load(inp)
elif fmt == 'json5':
- if six.PY3:
- inp = io.TextIOWrapper(inp, encoding=encoding)
+ inp = io.TextIOWrapper(inp, encoding=encoding)
res = json5.load(inp, encoding=encoding)
elif fmt == 'toml':
if not _is_utf8(encoding):
raise AnyMarkupError('toml is always utf-8 encoded according to specification')
- if six.PY3:
- # python 3 toml prefers unicode objects
- inp = io.TextIOWrapper(inp, encoding=encoding)
+ # python 3 toml prefers unicode objects
+ inp = io.TextIOWrapper(inp, encoding=encoding)
res = toml.load(inp)
elif fmt == 'xml':
res = xmltodict.parse(inp, encoding=encoding)
@@ -336,9 +330,9 @@ def _ensure_proper_types(struct, encoding, force_types):
res = []
for i in struct:
res.append(_ensure_proper_types(i, encoding, force_types))
- elif isinstance(struct, six.binary_type):
+ elif isinstance(struct, bytes):
res = struct.decode(encoding)
- elif isinstance(struct, (six.text_type, type(None), type(True), six.integer_types, float)):
+ elif isinstance(struct, (str, type(None), type(True), int, float)):
res = struct
elif isinstance(struct, datetime.datetime):
# toml can parse datetime natively
@@ -347,11 +341,11 @@ def _ensure_proper_types(struct, encoding, force_types):
raise AnyMarkupError('internal error - unexpected type {0} in parsed markup'.
format(type(struct)))
- if force_types and isinstance(res, six.text_type):
+ if force_types and isinstance(res, str):
res = _recognize_basic_types(res)
elif not (force_types or
- isinstance(res, (dict, collections.OrderedDict, list, six.text_type))):
- res = six.text_type(res)
+ isinstance(res, (dict, collections.OrderedDict, list, str))):
+ res = str(res)
return res
@@ -361,8 +355,6 @@ def _recognize_basic_types(s):
to a proper type and return it.
"""
tps = [int, float]
- if not six.PY3: # compat for older versions of six that don't have PY2
- tps.append(long)
for tp in tps:
try:
return tp(s)
@@ -498,5 +490,3 @@ if yaml is not None:
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:omap', construct_ordereddict)
yaml.SafeDumper.add_representer(collections.OrderedDict, represent_ordereddict)
yaml.SafeDumper.add_representer(str, represent_str)
- if six.PY2:
- yaml.SafeDumper.add_representer(unicode, represent_str)
diff --git a/requirements.txt b/requirements.txt
index ffe2fce..e69de29 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +0,0 @@
-six
diff --git a/setup.py b/setup.py
index e5b0be2..5391427 100644
--- a/setup.py
+++ b/setup.py
@@ -21,9 +21,8 @@ setup(
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
- 'Programming Language :: Python :: 2.7',
- 'Programming Language :: Python :: 3.3',
- 'Programming Language :: Python :: 3.4',
- 'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.8',
+ 'Programming Language :: Python :: 3.9',
+ 'Programming Language :: Python :: 3.10',
]
)
diff --git a/test/test_parse.py b/test/test_parse.py
index 3c0bf86..cddd872 100644
--- a/test/test_parse.py
+++ b/test/test_parse.py
@@ -4,7 +4,6 @@ import io
import os
import pytest
-import six
import toml
from anymarkup_core import *
@@ -23,8 +22,8 @@ class TestParse(object):
elif isinstance(struct, list):
for i in struct:
self.assert_unicode(i)
- elif isinstance(struct, (six.string_types, type(None), type(True), \
- six.integer_types, float, datetime)):
+ elif isinstance(struct, (str, type(None), type(True), \
+ int, float, datetime)):
pass
else:
raise AssertionError('Unexpected type {0} in parsed structure'.format(type(struct)))
diff --git a/test/test_serialize.py b/test/test_serialize.py
index 8191561..9ffbeab 100644
--- a/test/test_serialize.py
+++ b/test/test_serialize.py
@@ -3,7 +3,6 @@ import io
import os
import pytest
-import six
from anymarkup_core import *
@@ -21,7 +20,7 @@ class TestSerialize(object):
fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
def _read_decode(self, file):
- if isinstance(file, six.string_types):
+ if isinstance(file, str):
file = open(file, 'rb')
else:
file.seek(0)
--
2.38.0

View File

@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Oct 20 06:52:24 UTC 2022 - Daniel Garcia <daniel.garcia@suse.com>
- Add drop-python2-support.patch gh#bkabrda/anymarkup-core#7
- Remove python-six dependency
- Use a more specific python_sitelib expression in %files
- Use autosetup instead of setup and patch
-------------------------------------------------------------------
Thu Jun 30 07:43:44 UTC 2022 - Daniel García Moreno <dani@danigm.net>

View File

@@ -27,10 +27,11 @@ Group: Development/Languages/Python
URL: https://github.com/bkabrda/anymarkup-core
Source0: https://github.com/bkabrda/anymarkup-core/archive/v%{version}/anymarkup-core-%{version}.tar.gz
Patch0: xml-to-dict-0.13.patch
# PATCH-FIX-UPSTREAM drop-python2-support.patch gh#bkabrda/anymarkup-core#7
Patch1: drop-python2-support.patch
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-six
Suggests: python-PyYAML
Suggests: python-configobj
Suggests: python-json5
@@ -43,7 +44,6 @@ BuildRequires: %{python_module configobj}
BuildRequires: %{python_module flexmock}
BuildRequires: %{python_module json5}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module six}
BuildRequires: %{python_module toml}
BuildRequires: %{python_module xmltodict}
# /SECTION
@@ -54,8 +54,7 @@ This is the core library that implements functionality of
python-anymarkup.
%prep
%setup -q -n anymarkup-core-%{version}
%autopatch -p1
%autosetup -p1 -n anymarkup-core-%{version}
%build
%python_build
@@ -70,6 +69,7 @@ python-anymarkup.
%files %{python_files}
%doc README.rst
%license LICENSE
%{python_sitelib}/*
%{python_sitelib}/anymarkup_core
%{python_sitelib}/anymarkup_core-%{version}*-info
%changelog