Skip to content

Commit

Permalink
refs #31 Drop python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
shimizukawa committed Jun 1, 2019
1 parent f412899 commit cbe7495
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 77 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -3,13 +3,11 @@ python:
- "3.7"
- "3.6"
- "3.5"
- "2.7"
matrix:
exclude:
- python: "3.7"
- python: "3.6"
- python: "3.5"
- python: "2.7"
include:
- python: "3.7"
dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069)
Expand All @@ -24,8 +22,6 @@ matrix:
env: TOXENV=py36
- python: "3.5"
env: TOXENV=py35
- python: "2.7"
env: TOXENV=py27
install:
- pip install -r requirements-testing.txt
cache: pip
Expand Down
19 changes: 19 additions & 0 deletions CHANGES.rst
Expand Up @@ -2,6 +2,25 @@
CHANGES
=======

2.0.0 (unreleased)
==================

Environments
------------
- Drop supporting Python-2.7

Incompatibility
---------------

Features
--------

Documentation
-------------

Bug Fixes
---------

1.0.0 (2019/05/12)
===================

Expand Down
5 changes: 1 addition & 4 deletions setup.py
Expand Up @@ -6,7 +6,6 @@

install_requires = [
'setuptools',
'six',
'click',
'babel',
'sphinx',
Expand Down Expand Up @@ -46,8 +45,6 @@
"Topic :: Utilities",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
Expand All @@ -62,7 +59,7 @@
include_package_data=True,
zip_safe=False,
install_requires=install_requires,
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
python_requires=">=3.5",
extras_require=extras_require,
entry_points="""\
[console_scripts]
Expand Down
113 changes: 46 additions & 67 deletions sphinx_intl/pycompat.py
@@ -1,84 +1,63 @@
# -*- coding: utf-8 -*-
"""
Python compatibility functions.
"""

import sys
import os
from six import PY3, exec_, b

FS_ENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()


if sys.version_info >= (2, 6):
# Python >= 2.6
relpath = os.path.relpath
else:
from os.path import curdir

def relpath(path, start=curdir):
"""Return a relative version of a path"""
from os.path import sep, abspath, commonprefix, join, pardir

if not path:
raise ValueError("no path specified")
import warnings

start_list = abspath(start).split(sep)
path_list = abspath(path).split(sep)
if False:
from typing import Any, Callable # NOQA

# Work out how much of the filepath is shared by start and path.
i = len(commonprefix([start_list, path_list]))

rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return start
return join(*rel_list)
del curdir
# ------------------------------------------------------------------------------
# Python 2/3 compatibility
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()

if PY3:
def convert_with_2to3(filepath):
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
from lib2to3.pgen2.parse import ParseError
fixers = get_fixers_from_package('lib2to3.fixes')
refactoring_tool = RefactoringTool(fixers)
source = refactoring_tool._read_python_source(filepath)[0]
try:
tree = refactoring_tool.refactor_string(source, 'conf.py')
except ParseError:
typ, err, tb = sys.exc_info()
# do not propagate lib2to3 exceptions
lineno, offset = err.context[1]
# try to match ParseError details with SyntaxError details
raise SyntaxError(err.msg, (filepath, lineno, offset, err.value))
return str(tree)
else:
convert_with_2to3 = None


def execfile_(filepath, _globals):
# get config source -- 'b' is a no-op under 2.x, while 'U' is
# ignored under 3.x (but 3.x compile() accepts \r\n newlines)
f = open(filepath, 'rbU')
def relpath(path, start=os.curdir):
# type: (str, str) -> str
"""Return a relative version of a path"""
try:
return os.path.relpath(path, start)
except ValueError:
return path


# convert_with_2to3():
# support for running 2to3 over config files
def convert_with_2to3(filepath):
# type: (str) -> str
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
from lib2to3.pgen2.parse import ParseError
fixers = get_fixers_from_package('lib2to3.fixes')
refactoring_tool = RefactoringTool(fixers)
source = refactoring_tool._read_python_source(filepath)[0]
try:
tree = refactoring_tool.refactor_string(source, 'conf.py')
except ParseError as err:
# do not propagate lib2to3 exceptions
lineno, offset = err.context[1]
# try to match ParseError details with SyntaxError details
raise SyntaxError(err.msg, (filepath, lineno, offset, err.value))
return str(tree)


def execfile_(filepath, _globals, open=open):
# type: (str, Any, Callable) -> None
with open(filepath, 'rb') as f:
source = f.read()
finally:
f.close()

# py25,py26,py31 accept only LF eol instead of CRLF
if sys.version_info[:2] in ((2, 5), (2, 6), (3, 1)):
source = source.replace(b('\r\n'), b('\n'))

# compile to a code object, handle syntax errors
filepath_enc = filepath.encode(FS_ENCODING)
filepath_enc = filepath.encode(fs_encoding)
try:
code = compile(source, filepath_enc, 'exec')
except SyntaxError:
if convert_with_2to3:
# maybe the file uses 2.x syntax; try to refactor to
# 3.x syntax using 2to3
source = convert_with_2to3(filepath)
code = compile(source, filepath_enc, 'exec')
else:
raise

exec_(code, _globals)
# maybe the file uses 2.x syntax; try to refactor to
# 3.x syntax using 2to3
source = convert_with_2to3(filepath)
code = compile(source, filepath_enc, 'exec')
warnings.warn('Support for evaluating Python 2 syntax is deprecated '
'and will be removed in sphinx-intl 4.0. '
'Convert %s to Python 3 syntax.',
filepath)
exec(code, _globals)
1 change: 0 additions & 1 deletion sphinx_intl/sphinx_util.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

if False:
from typing import Iterator, List

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist=py37,py36,py35,py27,flake8,sdist
envlist=py37,py36,py35,flake8,sdist

[testenv]
deps=-e.[transifex,test]
Expand Down

0 comments on commit cbe7495

Please sign in to comment.