Skip to content

Commit

Permalink
Merge pull request #189 from level12/162-remove-six
Browse files Browse the repository at this point in the history
remove six and python2 support
  • Loading branch information
guruofgentoo committed Oct 27, 2022
2 parents d45a44e + 18a41d6 commit f2339df
Show file tree
Hide file tree
Showing 34 changed files with 31 additions and 124 deletions.
12 changes: 3 additions & 9 deletions docs/requirements.txt
@@ -1,10 +1,4 @@
--extra-index-url https://package-index.level12.net

sphinx
appdirs
BlazeUtils
blinker
Click>=3.0
Flask
Flask-SQLAlchemy
pathlib
python-json-logger
six
-e .[tests]
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -21,7 +21,7 @@
# -- Project information -----------------------------------------------------

project = 'Keg'
copyright = u'{}, Level 12'.format(dt.datetime.utcnow().year)
copyright = '{}, Level 12'.format(dt.datetime.utcnow().year)
author = 'Level 12'

cfg = configparser.SafeConfigParser()
Expand Down
2 changes: 0 additions & 2 deletions keg/__init__.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from flask import current_app # noqa: F401

from keg.version import VERSION # noqa: F401
Expand Down
3 changes: 0 additions & 3 deletions keg/app.py
@@ -1,9 +1,6 @@
from __future__ import absolute_import

import importlib

import flask
from six.moves import range
from werkzeug.datastructures import ImmutableDict

from keg.blueprints import keg as kegbp
Expand Down
7 changes: 2 additions & 5 deletions keg/assets.py
@@ -1,10 +1,7 @@
from __future__ import absolute_import

from collections import defaultdict
import pathlib

from jinja2 import TemplateNotFound
import six

from keg.extensions import lazy_gettext as _

Expand Down Expand Up @@ -33,9 +30,9 @@ def load_asset(self, asset_name):
return False

def load_related(self, template_name):
js_asset_name = six.text_type(pathlib.PurePosixPath(template_name).with_suffix('.js'))
js_asset_name = str(pathlib.PurePosixPath(template_name).with_suffix('.js'))
js_found = self.load_asset(js_asset_name)
css_asset_name = six.text_type(pathlib.PurePosixPath(template_name).with_suffix('.css'))
css_asset_name = str(pathlib.PurePosixPath(template_name).with_suffix('.css'))
css_found = self.load_asset(css_asset_name)
if not js_found and not css_found:
raise AssetException(_('Could not find related assets for template: {template_name}',
Expand Down
2 changes: 0 additions & 2 deletions keg/blueprints/__init__.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import flask

from keg.extensions import lazy_gettext as _
Expand Down
4 changes: 1 addition & 3 deletions keg/cli.py
@@ -1,13 +1,11 @@
from __future__ import absolute_import

from collections import defaultdict
from contextlib import contextmanager
from itertools import chain
import urllib

import click
import flask
import flask.cli
from six.moves import urllib

from keg import current_app
from keg.extensions import gettext as _
Expand Down
15 changes: 0 additions & 15 deletions keg/compat.py

This file was deleted.

5 changes: 1 addition & 4 deletions keg/config.py
@@ -1,12 +1,9 @@
from __future__ import absolute_import

import os.path as osp

import appdirs
from blazeutils.helpers import tolist
import flask
from pathlib import PurePath
import six
from werkzeug.utils import (
import_string,
ImportStringError
Expand Down Expand Up @@ -191,7 +188,7 @@ class TestProfile(object):
KEG_LOG_SYSLOG_ENABLED = False

# set this to allow generation of URLs without a request context
SERVER_NAME = 'keg.example.com' if six.PY3 else b'keg.example.com'
SERVER_NAME = 'keg.example.com'

# simple value for testing is fine
SECRET_KEY = '12345'
Expand Down
2 changes: 0 additions & 2 deletions keg/ctx.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from flask.ctx import RequestContext
from keg.assets import AssetManager

Expand Down
1 change: 0 additions & 1 deletion keg/db/__init__.py
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import warnings

import flask_sqlalchemy as fsa
Expand Down
5 changes: 1 addition & 4 deletions keg/db/dialect_ops.py
@@ -1,7 +1,4 @@
from __future__ import absolute_import

from sqlalchemy import MetaData
import six

from ..db import db

Expand Down Expand Up @@ -128,7 +125,7 @@ def drop_all(self):
'U': 'drop table [{schema_name}].[{name}]',
}
delete_sql = []
for type, drop_sql in six.iteritems(mapping):
for type, drop_sql in mapping.items():
sql = 'select name, object_name( parent_object_id ) as parent_name '\
', OBJECT_SCHEMA_NAME(object_id) as schema_name '\
'from sys.objects where type in (\'{}\')'.format("', '".join(type))
Expand Down
2 changes: 0 additions & 2 deletions keg/logging.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import datetime as dt
import logging
from logging.handlers import SysLogHandler
Expand Down
2 changes: 0 additions & 2 deletions keg/signals.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from flask.signals import Namespace

_signals = Namespace()
Expand Down
2 changes: 0 additions & 2 deletions keg/templating.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

# flask.globals.request_ctx is only available in Flask >= 2.2.0
try:
from flask.globals import request_ctx
Expand Down
10 changes: 0 additions & 10 deletions keg/testing.py
@@ -1,11 +1,8 @@
from __future__ import absolute_import

import contextlib

import click
import click.testing
import flask
import six
from flask_webtest import TestApp
from werkzeug.datastructures import ImmutableMultiDict, MultiDict

Expand Down Expand Up @@ -157,13 +154,6 @@ def invoke_command(app_cls, *args, **kwargs):
env[app_key] = 'true'
result = runner.invoke(app_cls.cli, args, env=env, catch_exceptions=False, **kwargs)

# if an exception was raised, make sure you output the output to make debugging easier
# -1 as an exit code indicates a non SystemExit exception.
# 9/16/15: Not sure this is necessary anymore since we force catch_exceptions=False above (RLS).
if result.exit_code == -1:
click.echo(result.output)
six.reraise(result.exc_info[1], None, result.exc_info[2])

error_message = 'Command exit code {}, expected {}. Result output follows:\n{}'
assert result.exit_code == exit_code, error_message.format(result.exit_code, exit_code,
result.output)
Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_app.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from unittest import mock

import pytest
Expand Down
5 changes: 1 addition & 4 deletions keg/tests/test_assets.py
@@ -1,9 +1,6 @@
from __future__ import absolute_import

import os

import pytest
import six

import keg
from keg.assets import AssetManager, AssetException
Expand Down Expand Up @@ -40,7 +37,7 @@ def test_load_related_none_found(self):
with pytest.raises(AssetException) as e:
am = AssetManager(keg.current_app)
am.load_related('_not_there.html')
assert six.text_type(e) == 'Could not find related assets for template: _not_there.html'
assert str(e) == 'Could not find related assets for template: _not_there.html'

def test_load_single_asset(self):
am = AssetManager(keg.current_app)
Expand Down
4 changes: 1 addition & 3 deletions keg/tests/test_cli.py
@@ -1,8 +1,6 @@
from __future__ import absolute_import

import os
from unittest import mock

import mock
import pytest

from keg.cli import dotenv, get_load_dotenv
Expand Down
5 changes: 1 addition & 4 deletions keg/tests/test_config.py
@@ -1,8 +1,5 @@
from __future__ import absolute_import

import os

import mock
from unittest import mock

from keg.app import Keg
from keg.config import Config
Expand Down
7 changes: 3 additions & 4 deletions keg/tests/test_db.py
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from unittest import mock

import pytest
Expand Down Expand Up @@ -35,21 +34,21 @@ def test_primary_db_entity(self):
# the component has loaded properly
from keg_apps.db.blog.model.entities import Blog
assert Blog.query.count() == 0
blog = Blog(title=u'foo')
blog = Blog(title='foo')
db.session.add(blog)
db.session.commit()
assert Blog.query.count() == 1

def test_postgres_bind_db_entity(self):
assert ents.PGDud.query.count() == 0
dud = ents.PGDud(name=u'foo')
dud = ents.PGDud(name='foo')
db.session.add(dud)
db.session.commit()
assert ents.PGDud.query.count() == 1

def test_postgres_db_enttity_alt_schema(self):
assert ents.PGDud2.query.count() == 0
dud = ents.PGDud2(name=u'foo')
dud = ents.PGDud2(name='foo')
db.session.add(dud)
db.session.commit()
assert ents.PGDud2.query.count() == 1
Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_db_dialects.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import pytest

from keg import current_app
Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_flask_wtf_bug.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import flask
import flask_webtest
from keg_apps.flaskwtf_bug import BugFixApp, BugApp
Expand Down
15 changes: 6 additions & 9 deletions keg/tests/test_logging.py
@@ -1,9 +1,6 @@
from __future__ import absolute_import

from io import StringIO
import logging

import mock
import six
from unittest import mock

from keg import signals
from keg_apps.logging import LoggingApp, log
Expand All @@ -12,10 +9,10 @@
class TestLogging(object):

def test_stream_handler(self):
with mock.patch('sys.stderr', new_callable=six.StringIO) as m_stderr:
with mock.patch('sys.stderr', new_callable=StringIO) as m_stderr:
LoggingApp().init(use_test_profile=True)
log.warning(u'test warn log')
log.info(u'test info log')
log.warning('test warn log')
log.info('test info log')

output = m_stderr.getvalue().strip().splitlines()
assert len(output) == 2, output
Expand Down Expand Up @@ -61,7 +58,7 @@ class TestJsonFormatter(object):
def setup_method(self):
self.logger = logging.getLogger('logging-test')
self.logger.setLevel(logging.DEBUG)
self.buffer = six.StringIO()
self.buffer = StringIO()

self.logHandler = logging.StreamHandler(self.buffer)
self.logger.addHandler(self.logHandler)
Expand Down
5 changes: 1 addition & 4 deletions keg/tests/test_templating.py
@@ -1,10 +1,7 @@
from __future__ import absolute_import

import os

from jinja2 import TemplateSyntaxError
import pytest
import six

from keg import current_app
from keg_apps.templating.app import TemplatingApp
Expand Down Expand Up @@ -50,7 +47,7 @@ def test_include(self):
def test_include_with_params(self):
with pytest.raises(TemplateSyntaxError) as e:
self.render('assets_with_params.html')
assert six.text_type(e) == 'asset_include does not yet support parameters'
assert str(e) == 'asset_include does not yet support parameters'

def test_assets_content(self):
self.ctx.assets.content['css'].append(('fake-file.css', 'foo', '//fake-file.css content'))
Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_utils.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import tempfile
from unittest import mock

Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_view_routing.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from unittest import mock

import flask
Expand Down
1 change: 0 additions & 1 deletion keg/tests/test_view_templating.py
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from keg.testing import WebBase

from keg_apps.web.app import WebApp
Expand Down
2 changes: 0 additions & 2 deletions keg/tests/test_web.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import flask
from keg.component import KegComponent
from keg.testing import WebBase
Expand Down
2 changes: 0 additions & 2 deletions keg/utils.py
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import inspect
import os
import weakref
Expand Down

0 comments on commit f2339df

Please sign in to comment.