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 Python 2 compatibility tricks #8

Open
wants to merge 8 commits into
base: master
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import editorconfig
from editorconfig import __version__


# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down
4 changes: 2 additions & 2 deletions editorconfig/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""EditorConfig Python Core"""

from editorconfig.versiontools import join_version
from editorconfig.version import VERSION
from editorconfig.versiontools import join_version

__all__ = ['get_properties', 'EditorConfigError', 'exceptions']

Expand All @@ -14,5 +14,5 @@ def get_properties(filename):
return handler.get_configurations()


from editorconfig.handler import EditorConfigHandler
from editorconfig.exceptions import *
from editorconfig.handler import EditorConfigHandler
41 changes: 20 additions & 21 deletions editorconfig/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@

"""

from __future__ import absolute_import, print_function, unicode_literals

import getopt
import sys

from editorconfig import VERSION, __version__
from editorconfig.compat import force_unicode
from editorconfig.exceptions import ParsingError, PathError, VersionError
from editorconfig.handler import EditorConfigHandler
from editorconfig.versiontools import split_version
from . import VERSION, __version__
from .compat import force_unicode
from .exceptions import ParsingError, PathError, VersionError
from .handler import EditorConfigHandler
from .versiontools import split_version


def version():
print("EditorConfig Python Core Version %s" % __version__)
print("EditorConfig Python Core Version {}".format(__version__))


def usage(command, error=False):
if error:
out = sys.stderr
else:
out = sys.stdout
out.write("%s [OPTIONS] FILENAME\n" % command)
out.write('-f '
'Specify conf filename other than ".editorconfig".\n')
out.write("-b "
"Specify version (used by devs to test compatibility).\n")
out.write("-h OR --help Print this help message.\n")
out.write("-v OR --version Display version information.\n")
out = sys.stderr if error else sys.stdout
print("{} [OPTIONS] FILENAME\n".format(command), file=out)
print("-f "
'Specify conf filename other than ".editorconfig".\n', file=out)
print("-b "
"Specify version (used by devs to test compatibility).\n", file=out)
print("-h OR --help Print this help message.\n", file=out)
print("-v OR --version Display version information.\n", file=out)


def main():
Expand Down Expand Up @@ -57,9 +56,9 @@ def main():
if option == '-b':
version_tuple = split_version(arg)
if version_tuple is None:
sys.exit("Invalid version number: %s" % arg)
sys.exit("Invalid version number: {}".format(arg))

if len(args) < 1:
if not args:
usage(command_name, error=True)
sys.exit(2)
filenames = args
Expand All @@ -73,9 +72,9 @@ def main():
print(str(e))
sys.exit(2)
if multiple_files:
print("[%s]" % filename)
print("[{}]".format(filename))
for key, value in options.items():
print("%s=%s" % (key, value))
print("{}={}".format(key, value))


if __name__ == "__main__":
Expand Down
10 changes: 1 addition & 9 deletions editorconfig/compat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""EditorConfig Python2/Python3 compatibility utilities"""
import sys


__all__ = ['force_unicode', 'u']
__all__ = ['force_unicode']


if sys.version_info[0] == 2:
Expand All @@ -15,10 +14,3 @@ def force_unicode(string):
if not isinstance(string, text_type):
string = text_type(string, encoding='utf-8')
return string


if sys.version_info[0] == 2:
import codecs
u = lambda s: codecs.unicode_escape_decode(s)[0]
else:
u = lambda s: s
1 change: 0 additions & 1 deletion editorconfig/fnmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import re


__all__ = ["fnmatch", "fnmatchcase", "translate"]

_cache = {}
Expand Down
9 changes: 5 additions & 4 deletions editorconfig/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

"""

import os
from __future__ import absolute_import, print_function, unicode_literals

from editorconfig import VERSION
from editorconfig.exceptions import PathError, VersionError
from editorconfig.ini import EditorConfigParser
import os

from . import VERSION
from .exceptions import PathError, VersionError
from .ini import EditorConfigParser

__all__ = ['EditorConfigHandler']

Expand Down
10 changes: 5 additions & 5 deletions editorconfig/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

"""

from __future__ import absolute_import, print_function, unicode_literals

import posixpath
import re
from codecs import open
from collections import OrderedDict
from os import sep
from os.path import dirname, normpath

from editorconfig.compat import u
from editorconfig.exceptions import ParsingError
from editorconfig.fnmatch import fnmatch

from .exceptions import ParsingError
from .fnmatch import fnmatch

__all__ = ["ParsingError", "EditorConfigParser"]

Expand Down Expand Up @@ -122,7 +122,7 @@ def _read(self, fp, fpname):
line = fp.readline()
if not line:
break
if lineno == 0 and line.startswith(u('\ufeff')):
if lineno == 0 and line.startswith('\ufeff'):
line = line[1:] # Strip UTF-8 BOM
lineno = lineno + 1
# comment or blank line?
Expand Down
5 changes: 2 additions & 3 deletions editorconfig/versiontools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import re


__all__ = ['join_version', 'split_version']


Expand All @@ -16,9 +15,9 @@

def join_version(version_tuple):
"""Return a string representation of version from given VERSION tuple"""
version = "%s.%s.%s" % version_tuple[:3]
version = "{0}.{1}.{2}".format(*version_tuple)
if version_tuple[3] != "final":
version += "-%s" % version_tuple[3]
version += "-{3}".format(*version_tuple)
return version


Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from setuptools import setup

# Read the version
Expand Down