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

Drop Python 2.7, 3.5 support, add 3.6-3.9 for fluent.runtime, fluent.pygments #163

Merged
merged 6 commits into from
Mar 8, 2021
Merged
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/fluent.integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
python -m pip install wheel
python -m pip install --upgrade pip
python -m pip install . mock
python -m pip install .
- name: Install latest fluent.syntax
working-directory: ./fluent.syntax
run: |
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/fluent.runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]
fluent-syntax: [0.17.0]
python-version: [3.6, 3.7, 3.8, 3.9, pypy3]
fluent-syntax: [0.18.1]
include:
- python-version: 3.9
fluent-syntax: 0.17.0
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -37,7 +40,7 @@ jobs:
python -m pip install wheel
python -m pip install --upgrade pip
python -m pip install fluent.syntax==${{ matrix.fluent-syntax }}
python -m pip install . mock
python -m pip install .
- name: Test
working-directory: ./fluent.runtime
run: |
Expand All @@ -49,7 +52,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install wheel
Expand Down
6 changes: 6 additions & 0 deletions fluent.pygments/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

fluent.runtime 2.0 (TBD)
-----------------------------------

* Drop support for Python 2.7 and 3.5
* Add support for Python 3.6 through 3.9

fluent.pygments 1.0 (May 20, 2020)
----------------------------------

Expand Down
2 changes: 0 additions & 2 deletions fluent.pygments/fluent/pygments/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, unicode_literals

import argparse
import sys

Expand Down
21 changes: 7 additions & 14 deletions fluent.pygments/fluent/pygments/lexer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, unicode_literals

from fluent.syntax import ast as FTL
from fluent.syntax import parse

Expand Down Expand Up @@ -38,7 +36,7 @@ def get_tokens_unprocessed(self, text):
}


class Tokenizer(object):
class Tokenizer:
def __init__(self, text):
self.text = text
self.ast = parse(text)
Expand All @@ -49,21 +47,18 @@ def tokenize(self, node=None):
if isinstance(node, (FTL.Annotation, FTL.Span)):
return
if isinstance(node, FTL.SyntaxNode):
for token in self.tokenize_node(node):
yield token
yield from self.tokenize_node(node)
elif isinstance(node, list):
for child in node:
for token in self.tokenize(child):
yield token
yield from self.tokenize(child)

def tokenize_node(self, node):
nodename = type(node).__name__
if nodename in ATOMIC:
yield self._token(node, ATOMIC[nodename])
else:
tokenize = getattr(self, 'tokenize_{}'.format(nodename), self.generic_tokenize)
for token in tokenize(node):
yield token
tokenize = getattr(self, f'tokenize_{nodename}', self.generic_tokenize)
yield from tokenize(node)

def generic_tokenize(self, node):
children = [
Expand All @@ -74,13 +69,11 @@ def generic_tokenize(self, node):
key=lambda child: child.span.start if isinstance(child, FTL.SyntaxNode) else child[0].span.start
)
for child in children:
for token in self.tokenize(child):
yield token
yield from self.tokenize(child)

def tokenize_Variant(self, node):
yield self._token(node.key, Token.Name.Attribute)
for token in self.tokenize(node.value):
yield token
yield from self.tokenize(node.value)

def _token(self, node, token):
return (
Expand Down
3 changes: 1 addition & 2 deletions fluent.pygments/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version=1.0
version=2.0

[bdist_wheel]
universal=1
Expand All @@ -17,7 +17,6 @@ not_skip=__init__.py
install_requires =
pygments
fluent.syntax
six

[options.entry_points]
pygments.lexers =
Expand Down
8 changes: 5 additions & 3 deletions fluent.pygments/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3 :: Only',
],
packages=['fluent', 'fluent.pygments'],
tests_require=['six'],
test_suite='tests.pygments'
)
2 changes: 0 additions & 2 deletions fluent.pygments/tests/pygments/test_lexer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, print_function, unicode_literals

import unittest
from pygments.token import Token

Expand Down
6 changes: 6 additions & 0 deletions fluent.runtime/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

fluent.runtime 0.4 (TBD)
-----------------------------------

* Drop support for Python 2.7 and 3.5
* Add support for Python 3.6 through 3.9

fluent.runtime 0.3.1 (May 20, 2020)
-----------------------------------

Expand Down
4 changes: 1 addition & 3 deletions fluent.runtime/fluent/runtime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

import babel
import babel.numbers
import babel.plural
Expand Down Expand Up @@ -28,7 +26,7 @@ def FluentResource(source):
return parser.parse(source)


class FluentBundle(object):
class FluentBundle:
"""
Bundles are single-language stores of translations. They are
aggregate parsed Fluent resources in the Fluent syntax and can
Expand Down
3 changes: 0 additions & 3 deletions fluent.runtime/fluent/runtime/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, unicode_literals


class FluentFormatError(ValueError):
def __eq__(self, other):
return ((other.__class__ == self.__class__) and
Expand Down
9 changes: 3 additions & 6 deletions fluent.runtime/fluent/runtime/fallback.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-

import codecs
import os
import six


class FluentLocalization(object):
class FluentLocalization:
"""
Generic API for Fluent applications.

Expand Down Expand Up @@ -67,7 +64,7 @@ def _iterate_bundles(self):
yield bundle


class AbstractResourceLoader(object):
class AbstractResourceLoader:
"""
Interface to implement for resource loaders.
"""
Expand Down Expand Up @@ -97,7 +94,7 @@ def __init__(self, roots):
Create a resource loader. The roots may be a string for a single
location on disk, or a list of strings.
"""
self.roots = [roots] if isinstance(roots, six.text_type) else roots
self.roots = [roots] if isinstance(roots, str) else roots
from fluent.runtime import FluentResource
self.Resource = FluentResource

Expand Down
3 changes: 1 addition & 2 deletions fluent.runtime/fluent/runtime/prepare.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import absolute_import, unicode_literals
from fluent.syntax import ast as FTL
from . import resolver


class Compiler(object):
class Compiler:
def __call__(self, item):
if isinstance(item, FTL.BaseNode):
return self.compile(item)
Expand Down
35 changes: 16 additions & 19 deletions fluent.runtime/fluent/runtime/resolver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from __future__ import absolute_import, unicode_literals

import contextlib

import attr
import six

from fluent.syntax import ast as FTL
from .errors import FluentCyclicReferenceError, FluentFormatError, FluentReferenceError
Expand Down Expand Up @@ -31,7 +28,7 @@


@attr.s
class CurrentEnvironment(object):
class CurrentEnvironment:
# The parts of ResolverEnvironment that we want to mutate (and restore)
# temporarily for some parts of a call chain.

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


@attr.s
class ResolverEnvironment(object):
class ResolverEnvironment:
context = attr.ib()
errors = attr.ib()
part_count = attr.ib(default=0, init=False)
Expand All @@ -73,7 +70,7 @@ def modified_for_term_reference(self, args=None):
error_for_missing_arg=False)


class BaseResolver(object):
class BaseResolver:
"""
Abstract base class of all partially evaluated resolvers.

Expand Down Expand Up @@ -104,13 +101,13 @@ def _fix_attributes(self):

class Message(FTL.Message, EntryResolver):
def __init__(self, id, **kwargs):
super(Message, self).__init__(id, **kwargs)
super().__init__(id, **kwargs)
self._fix_attributes()


class Term(FTL.Term, EntryResolver):
def __init__(self, id, value, **kwargs):
super(Term, self).__init__(id, value, **kwargs)
super().__init__(id, value, **kwargs)
self._fix_attributes()


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

def __init__(self, *args, **kwargs):
super(Pattern, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def __call__(self, env):
if self in env.active_patterns:
Expand All @@ -130,7 +127,7 @@ def __call__(self, env):
remaining_parts = self.MAX_PARTS - env.part_count
if len(self.elements) > remaining_parts:
env.active_patterns.remove(self)
raise ValueError("Too many parts in message (> {0}), "
raise ValueError("Too many parts in message (> {}), "
"aborting.".format(self.MAX_PARTS))
retval = ''.join(
resolve(element(env), env) for element in elements
Expand All @@ -143,7 +140,7 @@ def __call__(self, env):
def resolve(fluentish, env):
if isinstance(fluentish, FluentType):
return fluentish.format(env.context._babel_locale)
if isinstance(fluentish, six.string_types):
if isinstance(fluentish, str):
if len(fluentish) > MAX_PART_LENGTH:
raise ValueError(
"Too many characters in placeable "
Expand Down Expand Up @@ -178,7 +175,7 @@ def __call__(self, env):

class NumberLiteral(FTL.NumberLiteral, BaseResolver):
def __init__(self, value, **kwargs):
super(NumberLiteral, self).__init__(value, **kwargs)
super().__init__(value, **kwargs)
if '.' in self.value:
self.value = FluentFloat(self.value)
else:
Expand All @@ -200,7 +197,7 @@ def __call__(self, env):
except LookupError:
ref_id = reference_to_id(self)
env.errors.append(unknown_reference_error_obj(ref_id))
return FluentNone('{{{}}}'.format(ref_id))
return FluentNone(f'{{{ref_id}}}')


class MessageReference(FTL.MessageReference, EntryReference):
Expand All @@ -211,13 +208,13 @@ class TermReference(FTL.TermReference, EntryReference):
def __call__(self, env):
if self.arguments:
if self.arguments.positional:
env.errors.append(FluentFormatError("Ignored positional arguments passed to term '{0}'"
env.errors.append(FluentFormatError("Ignored positional arguments passed to term '{}'"
.format(reference_to_id(self))))
kwargs = {kwarg.name.name: kwarg.value(env) for kwarg in self.arguments.named}
else:
kwargs = None
with env.modified_for_term_reference(args=kwargs):
return super(TermReference, self).__call__(env)
return super().__call__(env)


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

if isinstance(arg_val, (FluentType, six.text_type)):
if isinstance(arg_val, (FluentType, str)):
return arg_val
env.errors.append(TypeError("Unsupported external type: {0}, {1}"
env.errors.append(TypeError("Unsupported external type: {}, {}"
.format(name, type(arg_val))))
return FluentNone(name)

Expand Down Expand Up @@ -303,7 +300,7 @@ def __call__(self, env):
try:
function = env.context._functions[function_name]
except LookupError:
env.errors.append(FluentReferenceError("Unknown function: {0}"
env.errors.append(FluentReferenceError("Unknown function: {}"
.format(function_name)))
return FluentNone(function_name + "()")

Expand Down
Loading