Skip to content

Commit 0c37fc8

Browse files
authored
Remove support for Python 2.7 (#70)
* Remove support for Python 2.7 * fix typo * fix another typo * update ci * drop more old stuff * more modern * tweaks * fix
1 parent 5ac86c1 commit 0c37fc8

33 files changed

+93
-1071
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,98 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99

1010
jobs:
11-
build:
11+
12+
lint:
13+
name: Linting
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: 3.12
23+
- name: Set up Node
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '18'
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install ruff
31+
- name: Ruff lint
32+
run: |
33+
ruff check --output-format=github .
34+
- name: Ruff format
35+
run: |
36+
ruff format --check .
37+
38+
docs:
39+
name: Docs
40+
runs-on: ubuntu-latest
41+
strategy:
42+
fail-fast: false
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up Python
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: 3.13
49+
- name: Install dev dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
#pip install -U -e .[docs]
53+
pip install sphinx
54+
- name: Build docs
55+
run: |
56+
cd docs
57+
make html SPHINXOPTS="-W --keep-going"
58+
59+
tests:
1260
name: ${{ matrix.name }}
1361
runs-on: ${{ matrix.os }}
1462
strategy:
63+
fail-fast: false
1564
matrix:
1665
include:
17-
- name: Lint
18-
os: ubuntu-latest
19-
pyversion: '3.7'
20-
dolint: 1
21-
- name: Linux py36
22-
os: ubuntu-latest
23-
pyversion: '3.6'
24-
tests: 1
25-
- name: Linux py37
26-
os: ubuntu-latest
27-
pyversion: '3.7'
28-
tests: 1
2966
- name: Linux py38
3067
os: ubuntu-latest
3168
pyversion: '3.8'
32-
tests: 1
3369
- name: Linux py39
3470
os: ubuntu-latest
3571
pyversion: '3.9'
36-
tests: 1
72+
#
3773
- name: Linux pypy3
3874
os: ubuntu-latest
39-
pyversion: 'pypy3'
40-
tests: 1
75+
pyversion: 'pypy3.9'
4176
- name: Windows py38
4277
os: windows-latest
4378
pyversion: '3.8'
44-
tests: 1
4579
- name: MacOS py38
4680
os: macos-latest
4781
pyversion: '3.8'
48-
tests: 1
4982

5083
steps:
51-
- uses: actions/checkout@v2
84+
- uses: actions/checkout@v4
5285
- name: Set up Python ${{ matrix.pyversion }}
53-
uses: actions/setup-python@v2
86+
uses: actions/setup-python@v5
5487
with:
5588
python-version: ${{ matrix.pyversion }}
56-
- uses: actions/setup-node@v2
57-
if: matrix.dolint == 1
58-
with:
59-
node-version: '14'
60-
- name: Install dependencies (lint and docs)
61-
if: matrix.dolint == 1
89+
- name: Install dependencies for unit tests
90+
shell: bash
6291
run: |
6392
python -m pip install --upgrade pip
64-
pip install invoke pycodestyle flake8 sphinx
65-
- name: Install dependencies (unit tests)
66-
if: matrix.tests == 1
67-
run: |
68-
python -m pip install --upgrade pip
69-
pip install invoke pytest pytest-cov
70-
- name: Lint
71-
if: matrix.dolint == 1
72-
run: |
73-
invoke test --style
74-
- name: Build docs
75-
if: matrix.dolint == 1
76-
run: |
77-
invoke docs --clean --build
93+
pip install pytest pytest-cov
94+
pip install .
95+
rm -rf ./pscript ./build ./egg-info
7896
- name: Test with pytest
79-
if: matrix.tests == 1
8097
run: |
81-
invoke test --unit
98+
python -c "import sys; print(sys.version, '\n', sys.prefix)";
99+
pytest -v --cov pscript --cov-config=.coveragerc --cov-report=term --cov-report=html tests

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
See https://github.com/flexxui/flexx/blob/master/CONTRIBUTING.md
1+
See https://github.com/flexxui/flexx/blob/main/CONTRIBUTING.md

pscript/__init__.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,6 @@
248248

249249
logger = logging.getLogger(__name__)
250250

251-
# Assert compatibility and redirect to legacy version on Python 2.7
252-
ok = True
253-
if sys.version_info[0] == 2: # pragma: no cover
254-
if sys.version_info < (2, 7):
255-
raise RuntimeError('PScript needs at least Python 2.7')
256-
if type(b'') == type(''): # noqa - will be str and unicode after conversion
257-
sys.modules[__name__] = __import__(__name__ + '_legacy')
258-
ok = False
259251

260252
# NOTE: The code for the parser is quite long, especially if you want
261253
# to document it well. Therefore it is split in multiple modules, which
@@ -267,20 +259,17 @@
267259
# demonstrating the features defined in that module. In the docs these
268260
# docstrings are combined into one complete guide.
269261

270-
# flake8: noqa
271262

272-
if ok:
263+
from .parser0 import Parser0, JSError
264+
from .parser1 import Parser1
265+
from .parser2 import Parser2
266+
from .parser3 import Parser3
267+
from .base import *
273268

274-
from .parser0 import Parser0, JSError
275-
from .parser1 import Parser1
276-
from .parser2 import Parser2
277-
from .parser3 import Parser3
278-
from .base import *
269+
from .functions import py2js, evaljs, evalpy, JSString
270+
from .functions import script2js, js_rename, create_js_module
271+
from .stdlib import get_full_std_lib, get_all_std_names
272+
from .stubs import RawJS, JSConstant, window, undefined
279273

280-
from .functions import py2js, evaljs, evalpy, JSString
281-
from .functions import script2js, js_rename, create_js_module
282-
from .stdlib import get_full_std_lib, get_all_std_names
283-
from .stubs import RawJS, JSConstant, window, undefined
284274

285-
286-
del logging, sys, ok
275+
del logging, sys

pscript/functions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ def evaljs(jscode, whitespace=True, print_result=True, extra_nodejs_args=None):
279279
filename = None
280280
p_or_e = ['-p', '-e'] if print_result else ['-e']
281281
cmd += ['--use_strict'] + p_or_e + [jscode]
282-
if sys.version_info[0] < 3:
283-
cmd = [c.encode('raw_unicode_escape') for c in cmd]
284282

285283
# Call node
286284
try:

pscript/parser0.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class Parser0:
152152
'True' : 'true',
153153
'False' : 'false',
154154
'None' : 'null',
155-
'unicode': 'str', # legacy Py compat
156155
'unichr': 'chr',
157156
'xrange': 'range',
158157
'self': 'this',
@@ -208,12 +207,7 @@ def __init__(self, code, pysource=None, indent=0, docstrings=True,
208207
self._pysource = str(pysource[0]), int(pysource[1])
209208
elif pysource is not None:
210209
logger.warning('Parser ignores pysource; it must be str or (str, int).')
211-
if sys.version_info[0] == 2:
212-
fut = 'from __future__ import unicode_literals, print_function\n'
213-
code = fut + code
214210
self._root = ast.parse(code)
215-
if sys.version_info[0] == 2:
216-
self._root.body_nodes.pop(0) # remove that import node we added
217211
self._stack = []
218212
self._indent = indent
219213
self._dummy_counter = 0

pscript/stubs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def __init__(self, code, _resolve_defining_module=True):
5858
raise Exception()
5959
except Exception as err:
6060
tb = getattr(err, '__traceback__', None)
61-
if tb is None: # Legacy Python 2.x
62-
import sys
63-
_, _, tb = sys.exc_info()
6461
self._globals = tb.tb_frame.f_back.f_globals
6562
del tb
6663
self.__module__ = self._globals['__name__']

setup.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ def package_tree(pkgroot):
4343
return subdirs
4444

4545

46-
def copy_for_legacy_python(src_dir, dest_dir):
47-
from translate_to_legacy import LegacyPythonTranslator
48-
# Dirs and files to explicitly not translate
49-
skip = ['tests/python_sample.py',
50-
'tests/python_sample2.py',
51-
'tests/python_sample3.py']
52-
# Make a fresh copy of the package
53-
if os.path.isdir(dest_dir):
54-
shutil.rmtree(dest_dir)
55-
ignore = lambda src, names: [n for n in names if n == '__pycache__']
56-
shutil.copytree(src_dir, dest_dir, ignore=ignore)
57-
# Translate in-place
58-
LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)
59-
60-
6146
## Collect info for setup()
6247

6348
THIS_DIR = os.path.dirname(__file__)
@@ -70,14 +55,6 @@ def copy_for_legacy_python(src_dir, dest_dir):
7055
version, doc = get_version_and_doc(os.path.join(THIS_DIR, name, '__init__.py'))
7156
doc = "" # won't render open(os.path.join(THIS_DIR, 'README.md'), "rb").read().decode()
7257

73-
# Support for legacy Python: we install a second package with the
74-
# translated code. We generate that code when we can. We use
75-
# "name_legacy" below in "packages", "package_dir", and "package_data".
76-
name_legacy = name + '_legacy'
77-
if os.path.isfile(os.path.join(THIS_DIR, 'translate_to_legacy.py')):
78-
copy_for_legacy_python(os.path.join(THIS_DIR, name),
79-
os.path.join(THIS_DIR, name_legacy))
80-
8158

8259
## Setup
8360

@@ -96,8 +73,8 @@ def copy_for_legacy_python(src_dir, dest_dir):
9673
platforms='any',
9774
provides=[name],
9875
install_requires=[],
99-
packages=package_tree(name) + package_tree(name_legacy),
100-
package_dir={name: name, name_legacy: name_legacy},
76+
packages=package_tree(name),
77+
package_dir={name: name},
10178
# entry_points={'console_scripts': ['pscript = pscript.__main__:main'], },
10279
zip_safe=True,
10380
classifiers=[

tasks/README.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

tasks/__init__.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

tasks/__main__.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tasks/_config.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)