Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dependency on six #318

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ jobs:
- name: Run MyPy
if: matrix.python-version != 'pypy-3.7'
run: |
pip install enum34 mypy types-six
pip install mypy typed-ast
./mypy-run.sh
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Alternative
-----------

If you choose not to install ``stone`` using the method above, you will need
to ensure that you have the Python packages ``ply`` and ``six``, which can be
to ensure that you have the Python package ``ply``, which can be
installed through ``pip``::

$ pip install "ply>=3.4" "six>=1.3.0" "typing>=3.5.2"
$ pip install "ply>=3.4" "typing>=3.5.2"

If the ``stone`` package is in your PYTHONPATH, you can replace ``stone``
with ``python -m stone.cli`` as follows::
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ply>= 3.4
six>= 1.12.0
packaging>=21.0
Jinja2>= 3.0.3
4 changes: 1 addition & 3 deletions stone/backends/obj_c_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
import shutil

import six

from stone.backends.obj_c import (
base_file_comment,
comment_prefix,
Expand Down Expand Up @@ -915,7 +913,7 @@ def _determine_validator_type(self, data_type, value, has_default):
if data_type.min_length else 'nil'),
('maxLength', '@({})'.format(data_type.max_length)
if data_type.max_length else 'nil'),
('pattern', '@"{}"'.format(six.ensure_str(pattern))
('pattern', '@"{}"'.format(str(pattern))
if pattern else 'nil'),
]))

Expand Down
46 changes: 3 additions & 43 deletions stone/backends/python_rsrc/stone_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import re
import time

import six

from stone.backends.python_rsrc import (
stone_base as bb,
stone_validators as bv,
Expand Down Expand Up @@ -658,7 +656,7 @@ def decode_union(self, data_type, obj):
else:
raise bv.ValidationError("expected string or object, got %s" %
bv.generic_type_name(obj))
return data_type.definition(six.ensure_str(tag), val)
return data_type.definition(str(tag), val)

def decode_union_dict(self, data_type, obj):
if '.tag' not in obj:
Expand Down Expand Up @@ -785,7 +783,7 @@ def decode_union_old(self, data_type, obj):
else:
raise bv.ValidationError("expected string or object, got %s" %
bv.generic_type_name(obj))
return data_type.definition(six.ensure_str(tag), val)
return data_type.definition(str(tag), val)

def decode_struct_tree(self, data_type, obj):
"""
Expand Down Expand Up @@ -1003,45 +1001,7 @@ def _findall(text, substr):
# Every 28 years the calendar repeats, except through century leap years
# where it's 6 years. But only if you're using the Gregorian calendar. ;)
def _strftime(dt, fmt):
try:
return dt.strftime(fmt)
except ValueError:
if not six.PY2 or dt.year > 1900:
raise

if _ILLEGAL_S.search(fmt):
raise TypeError("This strftime implementation does not handle %s")

year = dt.year

# For every non-leap year century, advance by 6 years to get into the
# 28-year repeat cycle
delta = 2000 - year
off = 6 * (delta // 100 + delta // 400)
year = year + off

# Move to around the year 2000
year = year + ((2000 - year) // 28) * 28
timetuple = dt.timetuple()
s1 = time.strftime(fmt, (year,) + timetuple[1:])
sites1 = _findall(s1, str(year))

s2 = time.strftime(fmt, (year + 28,) + timetuple[1:])
sites2 = _findall(s2, str(year + 28))

sites = []

for site in sites1:
if site in sites2:
sites.append(site)

s = s1
syear = '%4d' % (dt.year,)

for site in sites:
s = s[:site] + syear + s[site + 4:]

return s
return dt.strftime(fmt)


try:
Expand Down
9 changes: 0 additions & 9 deletions stone/backends/python_rsrc/stone_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import re
from abc import ABCMeta, abstractmethod

import six

_MYPY = False
if _MYPY:
import typing # noqa: F401 # pylint: disable=import-error,unused-import,useless-suppression
Expand Down Expand Up @@ -328,17 +326,10 @@ def __init__(self, min_length=None, max_length=None, pattern=None):
def validate(self, val):
"""
A unicode string of the correct length and pattern will pass validation.
In PY2, we enforce that a str type must be valid utf-8, and a unicode
string will be returned.
"""
if not isinstance(val, str):
raise ValidationError("'%s' expected to be a string, got %s"
% (get_value_string(val), generic_type_name(val)))
if not six.PY3 and isinstance(val, str):
try:
val = val.decode('utf-8')
except UnicodeDecodeError:
raise ValidationError("'%s' was not valid utf-8")

if self.max_length is not None and len(val) > self.max_length:
raise ValidationError("'%s' must be at most %d characters, got %d"
Expand Down
3 changes: 1 addition & 2 deletions stone/backends/swift_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import shutil

import six
import jinja2
import textwrap

Expand Down Expand Up @@ -304,7 +303,7 @@ def _determine_validator_type(self, data_type, value):
self._func_args([
("minLength", data_type.min_length),
("maxLength", data_type.max_length),
("pattern", '"{}"'.format(six.ensure_str(pat)) if pat else None),
("pattern", '"{}"'.format(str(pat)) if pat else None),
])
)
else:
Expand Down
4 changes: 1 addition & 3 deletions test/test_python_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import sys
import unittest

import six

import stone.backends.python_rsrc.stone_base as bb
import stone.backends.python_rsrc.stone_serializers as ss
import stone.backends.python_rsrc.stone_validators as bv
Expand Down Expand Up @@ -655,7 +653,7 @@ def __init__(self):
pass

assert bv.type_name_with_module(Foo) == "test.test_python_gen.Foo"
assert bv.type_name_with_module(int) == "builtins.int" if six.PY3 else "__builtin__.int"
assert bv.type_name_with_module(int) == "builtins.int"


test_spec = """\
Expand Down