Skip to content

Commit ae416d0

Browse files
authored
Drop Python 2.7, 3.5 support, add 3.6-3.9 for fluent.runtime, fluent.pygments (#163)
* Declare compat with current python versions, drop 2.7, 3.5 Also adjust testing matrix to that. * Drop six, but keep it installed in tests * Use pyupgrade --py36-plus to modernize syntax. * Update version number and CHANGELOG * Add six to install dependencies, because fluent.syntax didn't. * Also dropping dependencies on mock, which I didn't spot in the updates via pyupgrade.
1 parent 7e1c4be commit ae416d0

34 files changed

+90
-135
lines changed

.github/workflows/fluent.integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
python -m pip install wheel
3939
python -m pip install --upgrade pip
40-
python -m pip install . mock
40+
python -m pip install .
4141
- name: Install latest fluent.syntax
4242
working-directory: ./fluent.syntax
4343
run: |

.github/workflows/fluent.runtime.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ jobs:
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
27-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]
28-
fluent-syntax: [0.17.0]
27+
python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
28+
fluent-syntax: [0.18.1]
29+
include:
30+
- python-version: 3.9
31+
fluent-syntax: 0.17.0
2932
steps:
3033
- uses: actions/checkout@v2
3134
- uses: actions/setup-python@v2
@@ -37,7 +40,7 @@ jobs:
3740
python -m pip install wheel
3841
python -m pip install --upgrade pip
3942
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }}
40-
python -m pip install . mock
43+
python -m pip install .
4144
- name: Test
4245
working-directory: ./fluent.runtime
4346
run: |
@@ -49,7 +52,7 @@ jobs:
4952
- uses: actions/checkout@v2
5053
- uses: actions/setup-python@v2
5154
with:
52-
python-version: 3.7
55+
python-version: 3.9
5356
- name: Install dependencies
5457
run: |
5558
python -m pip install wheel

fluent.pygments/CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
fluent.runtime 2.0 (TBD)
5+
-----------------------------------
6+
7+
* Drop support for Python 2.7 and 3.5
8+
* Add support for Python 3.6 through 3.9
9+
410
fluent.pygments 1.0 (May 20, 2020)
511
----------------------------------
612

fluent.pygments/fluent/pygments/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, print_function, unicode_literals
2-
31
import argparse
42
import sys
53

fluent.pygments/fluent/pygments/lexer.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, print_function, unicode_literals
2-
31
from fluent.syntax import ast as FTL
42
from fluent.syntax import parse
53

@@ -38,7 +36,7 @@ def get_tokens_unprocessed(self, text):
3836
}
3937

4038

41-
class Tokenizer(object):
39+
class Tokenizer:
4240
def __init__(self, text):
4341
self.text = text
4442
self.ast = parse(text)
@@ -49,21 +47,18 @@ def tokenize(self, node=None):
4947
if isinstance(node, (FTL.Annotation, FTL.Span)):
5048
return
5149
if isinstance(node, FTL.SyntaxNode):
52-
for token in self.tokenize_node(node):
53-
yield token
50+
yield from self.tokenize_node(node)
5451
elif isinstance(node, list):
5552
for child in node:
56-
for token in self.tokenize(child):
57-
yield token
53+
yield from self.tokenize(child)
5854

5955
def tokenize_node(self, node):
6056
nodename = type(node).__name__
6157
if nodename in ATOMIC:
6258
yield self._token(node, ATOMIC[nodename])
6359
else:
64-
tokenize = getattr(self, 'tokenize_{}'.format(nodename), self.generic_tokenize)
65-
for token in tokenize(node):
66-
yield token
60+
tokenize = getattr(self, f'tokenize_{nodename}', self.generic_tokenize)
61+
yield from tokenize(node)
6762

6863
def generic_tokenize(self, node):
6964
children = [
@@ -74,13 +69,11 @@ def generic_tokenize(self, node):
7469
key=lambda child: child.span.start if isinstance(child, FTL.SyntaxNode) else child[0].span.start
7570
)
7671
for child in children:
77-
for token in self.tokenize(child):
78-
yield token
72+
yield from self.tokenize(child)
7973

8074
def tokenize_Variant(self, node):
8175
yield self._token(node.key, Token.Name.Attribute)
82-
for token in self.tokenize(node.value):
83-
yield token
76+
yield from self.tokenize(node.value)
8477

8578
def _token(self, node, token):
8679
return (

fluent.pygments/setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[metadata]
2-
version=1.0
2+
version=2.0
33

44
[bdist_wheel]
55
universal=1
@@ -17,7 +17,6 @@ not_skip=__init__.py
1717
install_requires =
1818
pygments
1919
fluent.syntax
20-
six
2120

2221
[options.entry_points]
2322
pygments.lexers =

fluent.pygments/setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
'Development Status :: 3 - Alpha',
2020
'Intended Audience :: Developers',
2121
'License :: OSI Approved :: Apache Software License',
22-
'Programming Language :: Python :: 2.7',
23-
'Programming Language :: Python :: 3.5',
22+
'Programming Language :: Python :: 3.6',
23+
'Programming Language :: Python :: 3.7',
24+
'Programming Language :: Python :: 3.8',
25+
'Programming Language :: Python :: 3.9',
26+
'Programming Language :: Python :: 3 :: Only',
2427
],
2528
packages=['fluent', 'fluent.pygments'],
26-
tests_require=['six'],
2729
test_suite='tests.pygments'
2830
)

fluent.pygments/tests/pygments/test_lexer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, print_function, unicode_literals
2-
31
import unittest
42
from pygments.token import Token
53

fluent.runtime/CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
fluent.runtime 0.4 (TBD)
5+
-----------------------------------
6+
7+
* Drop support for Python 2.7 and 3.5
8+
* Add support for Python 3.6 through 3.9
9+
410
fluent.runtime 0.3.1 (May 20, 2020)
511
-----------------------------------
612

fluent.runtime/fluent/runtime/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, unicode_literals
2-
31
import babel
42
import babel.numbers
53
import babel.plural
@@ -28,7 +26,7 @@ def FluentResource(source):
2826
return parser.parse(source)
2927

3028

31-
class FluentBundle(object):
29+
class FluentBundle:
3230
"""
3331
Bundles are single-language stores of translations. They are
3432
aggregate parsed Fluent resources in the Fluent syntax and can

fluent.runtime/fluent/runtime/errors.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import, unicode_literals
2-
3-
41
class FluentFormatError(ValueError):
52
def __eq__(self, other):
63
return ((other.__class__ == self.__class__) and

fluent.runtime/fluent/runtime/fallback.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# -*- coding: utf-8 -*-
2-
31
import codecs
42
import os
5-
import six
63

74

8-
class FluentLocalization(object):
5+
class FluentLocalization:
96
"""
107
Generic API for Fluent applications.
118
@@ -67,7 +64,7 @@ def _iterate_bundles(self):
6764
yield bundle
6865

6966

70-
class AbstractResourceLoader(object):
67+
class AbstractResourceLoader:
7168
"""
7269
Interface to implement for resource loaders.
7370
"""
@@ -97,7 +94,7 @@ def __init__(self, roots):
9794
Create a resource loader. The roots may be a string for a single
9895
location on disk, or a list of strings.
9996
"""
100-
self.roots = [roots] if isinstance(roots, six.text_type) else roots
97+
self.roots = [roots] if isinstance(roots, str) else roots
10198
from fluent.runtime import FluentResource
10299
self.Resource = FluentResource
103100

fluent.runtime/fluent/runtime/prepare.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from __future__ import absolute_import, unicode_literals
21
from fluent.syntax import ast as FTL
32
from . import resolver
43

54

6-
class Compiler(object):
5+
class Compiler:
76
def __call__(self, item):
87
if isinstance(item, FTL.BaseNode):
98
return self.compile(item)

fluent.runtime/fluent/runtime/resolver.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from __future__ import absolute_import, unicode_literals
2-
31
import contextlib
42

53
import attr
6-
import six
74

85
from fluent.syntax import ast as FTL
96
from .errors import FluentCyclicReferenceError, FluentFormatError, FluentReferenceError
@@ -31,7 +28,7 @@
3128

3229

3330
@attr.s
34-
class CurrentEnvironment(object):
31+
class CurrentEnvironment:
3532
# The parts of ResolverEnvironment that we want to mutate (and restore)
3633
# temporarily for some parts of a call chain.
3734

@@ -48,7 +45,7 @@ class CurrentEnvironment(object):
4845

4946

5047
@attr.s
51-
class ResolverEnvironment(object):
48+
class ResolverEnvironment:
5249
context = attr.ib()
5350
errors = attr.ib()
5451
part_count = attr.ib(default=0, init=False)
@@ -73,7 +70,7 @@ def modified_for_term_reference(self, args=None):
7370
error_for_missing_arg=False)
7471

7572

76-
class BaseResolver(object):
73+
class BaseResolver:
7774
"""
7875
Abstract base class of all partially evaluated resolvers.
7976
@@ -104,13 +101,13 @@ def _fix_attributes(self):
104101

105102
class Message(FTL.Message, EntryResolver):
106103
def __init__(self, id, **kwargs):
107-
super(Message, self).__init__(id, **kwargs)
104+
super().__init__(id, **kwargs)
108105
self._fix_attributes()
109106

110107

111108
class Term(FTL.Term, EntryResolver):
112109
def __init__(self, id, value, **kwargs):
113-
super(Term, self).__init__(id, value, **kwargs)
110+
super().__init__(id, value, **kwargs)
114111
self._fix_attributes()
115112

116113

@@ -119,7 +116,7 @@ class Pattern(FTL.Pattern, BaseResolver):
119116
MAX_PARTS = 1000
120117

121118
def __init__(self, *args, **kwargs):
122-
super(Pattern, self).__init__(*args, **kwargs)
119+
super().__init__(*args, **kwargs)
123120

124121
def __call__(self, env):
125122
if self in env.active_patterns:
@@ -130,7 +127,7 @@ def __call__(self, env):
130127
remaining_parts = self.MAX_PARTS - env.part_count
131128
if len(self.elements) > remaining_parts:
132129
env.active_patterns.remove(self)
133-
raise ValueError("Too many parts in message (> {0}), "
130+
raise ValueError("Too many parts in message (> {}), "
134131
"aborting.".format(self.MAX_PARTS))
135132
retval = ''.join(
136133
resolve(element(env), env) for element in elements
@@ -143,7 +140,7 @@ def __call__(self, env):
143140
def resolve(fluentish, env):
144141
if isinstance(fluentish, FluentType):
145142
return fluentish.format(env.context._babel_locale)
146-
if isinstance(fluentish, six.string_types):
143+
if isinstance(fluentish, str):
147144
if len(fluentish) > MAX_PART_LENGTH:
148145
raise ValueError(
149146
"Too many characters in placeable "
@@ -178,7 +175,7 @@ def __call__(self, env):
178175

179176
class NumberLiteral(FTL.NumberLiteral, BaseResolver):
180177
def __init__(self, value, **kwargs):
181-
super(NumberLiteral, self).__init__(value, **kwargs)
178+
super().__init__(value, **kwargs)
182179
if '.' in self.value:
183180
self.value = FluentFloat(self.value)
184181
else:
@@ -200,7 +197,7 @@ def __call__(self, env):
200197
except LookupError:
201198
ref_id = reference_to_id(self)
202199
env.errors.append(unknown_reference_error_obj(ref_id))
203-
return FluentNone('{{{}}}'.format(ref_id))
200+
return FluentNone(f'{{{ref_id}}}')
204201

205202

206203
class MessageReference(FTL.MessageReference, EntryReference):
@@ -211,13 +208,13 @@ class TermReference(FTL.TermReference, EntryReference):
211208
def __call__(self, env):
212209
if self.arguments:
213210
if self.arguments.positional:
214-
env.errors.append(FluentFormatError("Ignored positional arguments passed to term '{0}'"
211+
env.errors.append(FluentFormatError("Ignored positional arguments passed to term '{}'"
215212
.format(reference_to_id(self))))
216213
kwargs = {kwarg.name.name: kwarg.value(env) for kwarg in self.arguments.named}
217214
else:
218215
kwargs = None
219216
with env.modified_for_term_reference(args=kwargs):
220-
return super(TermReference, self).__call__(env)
217+
return super().__call__(env)
221218

222219

223220
class VariableReference(FTL.VariableReference, BaseResolver):
@@ -228,12 +225,12 @@ def __call__(self, env):
228225
except LookupError:
229226
if env.current.error_for_missing_arg:
230227
env.errors.append(
231-
FluentReferenceError("Unknown external: {0}".format(name)))
228+
FluentReferenceError(f"Unknown external: {name}"))
232229
return FluentNone(name)
233230

234-
if isinstance(arg_val, (FluentType, six.text_type)):
231+
if isinstance(arg_val, (FluentType, str)):
235232
return arg_val
236-
env.errors.append(TypeError("Unsupported external type: {0}, {1}"
233+
env.errors.append(TypeError("Unsupported external type: {}, {}"
237234
.format(name, type(arg_val))))
238235
return FluentNone(name)
239236

@@ -303,7 +300,7 @@ def __call__(self, env):
303300
try:
304301
function = env.context._functions[function_name]
305302
except LookupError:
306-
env.errors.append(FluentReferenceError("Unknown function: {0}"
303+
env.errors.append(FluentReferenceError("Unknown function: {}"
307304
.format(function_name)))
308305
return FluentNone(function_name + "()")
309306

0 commit comments

Comments
 (0)