Skip to content
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
108 changes: 63 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,98 @@ name: CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]


jobs:
build:

lint:
name: Linting
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Ruff lint
run: |
ruff check --output-format=github .
- name: Ruff format
run: |
ruff format --check .

docs:
name: Docs
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip
#pip install -U -e .[docs]
pip install sphinx
- name: Build docs
run: |
cd docs
make html SPHINXOPTS="-W --keep-going"

tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Lint
os: ubuntu-latest
pyversion: '3.7'
dolint: 1
- name: Linux py36
os: ubuntu-latest
pyversion: '3.6'
tests: 1
- name: Linux py37
os: ubuntu-latest
pyversion: '3.7'
tests: 1
- name: Linux py38
os: ubuntu-latest
pyversion: '3.8'
tests: 1
- name: Linux py39
os: ubuntu-latest
pyversion: '3.9'
tests: 1
#
- name: Linux pypy3
os: ubuntu-latest
pyversion: 'pypy3'
tests: 1
pyversion: 'pypy3.9'
- name: Windows py38
os: windows-latest
pyversion: '3.8'
tests: 1
- name: MacOS py38
os: macos-latest
pyversion: '3.8'
tests: 1

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.pyversion }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.pyversion }}
- uses: actions/setup-node@v2
if: matrix.dolint == 1
with:
node-version: '14'
- name: Install dependencies (lint and docs)
if: matrix.dolint == 1
- name: Install dependencies for unit tests
shell: bash
run: |
python -m pip install --upgrade pip
pip install invoke pycodestyle flake8 sphinx
- name: Install dependencies (unit tests)
if: matrix.tests == 1
run: |
python -m pip install --upgrade pip
pip install invoke pytest pytest-cov
- name: Lint
if: matrix.dolint == 1
run: |
invoke test --style
- name: Build docs
if: matrix.dolint == 1
run: |
invoke docs --clean --build
pip install pytest pytest-cov
pip install .
rm -rf ./pscript ./build ./egg-info
- name: Test with pytest
if: matrix.tests == 1
run: |
invoke test --unit
python -c "import sys; print(sys.version, '\n', sys.prefix)";
pytest -v --cov pscript --cov-config=.coveragerc --cov-report=term --cov-report=html tests
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
See https://github.com/flexxui/flexx/blob/master/CONTRIBUTING.md
See https://github.com/flexxui/flexx/blob/main/CONTRIBUTING.md
31 changes: 10 additions & 21 deletions pscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,6 @@

logger = logging.getLogger(__name__)

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

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

# flake8: noqa

if ok:
from .parser0 import Parser0, JSError
from .parser1 import Parser1
from .parser2 import Parser2
from .parser3 import Parser3
from .base import *

from .parser0 import Parser0, JSError
from .parser1 import Parser1
from .parser2 import Parser2
from .parser3 import Parser3
from .base import *
from .functions import py2js, evaljs, evalpy, JSString
from .functions import script2js, js_rename, create_js_module
from .stdlib import get_full_std_lib, get_all_std_names
from .stubs import RawJS, JSConstant, window, undefined

from .functions import py2js, evaljs, evalpy, JSString
from .functions import script2js, js_rename, create_js_module
from .stdlib import get_full_std_lib, get_all_std_names
from .stubs import RawJS, JSConstant, window, undefined


del logging, sys, ok
del logging, sys
2 changes: 0 additions & 2 deletions pscript/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ def evaljs(jscode, whitespace=True, print_result=True, extra_nodejs_args=None):
filename = None
p_or_e = ['-p', '-e'] if print_result else ['-e']
cmd += ['--use_strict'] + p_or_e + [jscode]
if sys.version_info[0] < 3:
cmd = [c.encode('raw_unicode_escape') for c in cmd]

# Call node
try:
Expand Down
6 changes: 0 additions & 6 deletions pscript/parser0.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class Parser0:
'True' : 'true',
'False' : 'false',
'None' : 'null',
'unicode': 'str', # legacy Py compat
'unichr': 'chr',
'xrange': 'range',
'self': 'this',
Expand Down Expand Up @@ -208,12 +207,7 @@ def __init__(self, code, pysource=None, indent=0, docstrings=True,
self._pysource = str(pysource[0]), int(pysource[1])
elif pysource is not None:
logger.warning('Parser ignores pysource; it must be str or (str, int).')
if sys.version_info[0] == 2:
fut = 'from __future__ import unicode_literals, print_function\n'
code = fut + code
self._root = ast.parse(code)
if sys.version_info[0] == 2:
self._root.body_nodes.pop(0) # remove that import node we added
self._stack = []
self._indent = indent
self._dummy_counter = 0
Expand Down
3 changes: 0 additions & 3 deletions pscript/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def __init__(self, code, _resolve_defining_module=True):
raise Exception()
except Exception as err:
tb = getattr(err, '__traceback__', None)
if tb is None: # Legacy Python 2.x
import sys
_, _, tb = sys.exc_info()
self._globals = tb.tb_frame.f_back.f_globals
del tb
self.__module__ = self._globals['__name__']
Expand Down
27 changes: 2 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ def package_tree(pkgroot):
return subdirs


def copy_for_legacy_python(src_dir, dest_dir):
from translate_to_legacy import LegacyPythonTranslator
# Dirs and files to explicitly not translate
skip = ['tests/python_sample.py',
'tests/python_sample2.py',
'tests/python_sample3.py']
# Make a fresh copy of the package
if os.path.isdir(dest_dir):
shutil.rmtree(dest_dir)
ignore = lambda src, names: [n for n in names if n == '__pycache__']
shutil.copytree(src_dir, dest_dir, ignore=ignore)
# Translate in-place
LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)


## Collect info for setup()

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

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


## Setup

Expand All @@ -96,8 +73,8 @@ def copy_for_legacy_python(src_dir, dest_dir):
platforms='any',
provides=[name],
install_requires=[],
packages=package_tree(name) + package_tree(name_legacy),
package_dir={name: name, name_legacy: name_legacy},
packages=package_tree(name),
package_dir={name: name},
# entry_points={'console_scripts': ['pscript = pscript.__main__:main'], },
zip_safe=True,
classifiers=[
Expand Down
33 changes: 0 additions & 33 deletions tasks/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions tasks/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions tasks/__main__.py

This file was deleted.

11 changes: 0 additions & 11 deletions tasks/_config.py

This file was deleted.

Loading
Loading