From fc5a3fc4c27575c52dc0ec52e5a9a5b7adeab7e0 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 24 Jan 2025 15:15:18 +0100 Subject: [PATCH 1/2] Use pyproject.toml --- .github/workflows/ci.yml | 2 +- CONTRIBUTING.md | 1 - MANIFEST.in | 7 --- README.md | 2 +- pyproject.toml | 74 ++++++++++++++++++++++++++++++ setup.cfg | 69 ---------------------------- setup.py | 98 ---------------------------------------- 7 files changed, 76 insertions(+), 177 deletions(-) delete mode 100644 CONTRIBUTING.md delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6021afa9..7a599b60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,4 +96,4 @@ jobs: - name: Test with pytest run: | python -c "import sys; print(sys.version, '\n', sys.prefix)"; - pytest -v --cov pscript --cov-config=.coveragerc --cov-report=term --cov-report=html tests + pytest -v --cov pscript --cov-report=term --cov-report=html tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 055cb01f..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1 +0,0 @@ -See https://github.com/flexxui/flexx/blob/main/CONTRIBUTING.md diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 42ba0780..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,7 +0,0 @@ -include LICENSE README.md - -recursive-include tasks * - -global-exclude .git* -global-exclude *.pyo -global-exclude *.pyc diff --git a/README.md b/README.md index a49a6147..c38dec82 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ also be useful by itself. Installation ------------ -PScript is pure Python and requires Python 2.7 or 3.5+ (including Pypy). +PScript is pure Python and requires Python 3.6+ (including Pypy). It has no further dependencies. * ``pip install pscript``, or diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..fab88e31 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,74 @@ +# Notes on how to do a release. +# +# * Bump `__version__` and commit. +# * git tag vx.y +# * git push origin main vx.y +# * flit publish + +# ===== Project info + +[project] +dynamic = ["version"] +name = "pscript" +description = "Python to JavaScript compiler." +readme = "README.md" +license = { file = "LICENSE" } +authors = [{ name = "Almar Klein" }] +keywords = ["Python", "JavaScript", "compiler", "transpiler", "parser"] +requires-python = ">= 3.6" +dependencies = [] +[project.optional-dependencies] +lint = ["ruff"] +tests = ["pytest"] +docs = ["sphinx"] +dev = ["pscript[lint,tests, docs]"] + +[project.urls] +Homepage = "https://github.com/flexxui/pscript" +Documentation = "http://pscript.readthedocs.io" +Repository = "https://github.com/flexxui/pscript" + + +# ===== Building + +# Flit is great solution for simple pure-Python projects. +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + + +# ===== Tooling + +[tool.ruff] +line-length = 88 + +[tool.ruff.lint] +select = ["F", "E", "W", "B", "RUF"] +ignore = [ + # "RUF005", # Consider iterable unpacking instead of concatenation +] + + +[tool.coverage.report] + +exclude_also = [ + # Have to re-enable the standard pragma, plus a less-ugly flavor + "pragma: no cover", + "no-cover", + "raise NotImplementedError", + "raise AssertionError", + "raise JSError", + # Don't complain if non-runnable code isn't run: + "if 0:", + "if False:", + "if __name__ == .__main__.:", + "if this_is_js():", + + # Don't complain for platform specific code + "sys\\.platform.startswith\\(\\'win\\'\\)", + "sys\\.platform.startswith\\(\\'darwin\\'\\)", + "getattr\\(sys, \\'frozen\\'\\,\\ None\\)", + + # Don't complain about caught import fails + "except ImportError:", +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 5043938e..00000000 --- a/setup.cfg +++ /dev/null @@ -1,69 +0,0 @@ -[flake8] -# References: -# http://flake8.readthedocs.org/en/latest/config.html -# http://flake8.readthedocs.org/en/latest/warnings.html#error-codes -# -# Style checks turned on: -# F - all pyflake errors -# E101 - indentation contains mixed spaces and tabs -# E111 - indentation is not a multiple of four -# E501 - line too long (see max-line-length) - -# ignores: -# W291 trailing whitespace -# W293 blanc line contains whitespace -# W504 line break after binary operator -# -# E124 closing bracket does not match visual indentation -# E127 continuation line over-indented for visual indent -# E203 whitespace before ':' -# E225 missing whitespace around operator -# E226 missing whitespace around arithmetic operator -# E265 block comment should start with '# ' -# E301 expected 1 blank line, found 0 -# E302 expected 2 blank lines, found 1 -# E303 too many blank lines -# E402 module level import not at top of file -# E266 too many leading '#' for block comment -# E731 do not assign a lambda expression, use a def -# E128 continuation line under-indented for visual indent - -exclude: test_*.py,exp/*,docs/*,build/*,dist/*,pscript_legacy/*,_feedstock/*, - python_sample.py,python_sample2.py,python_sample3.py, - -ignore: W291,W293,W504,E123,E124,E126,E127,E203,E225,E226,E265,E301,E302,E303,E402, - E266,E731,E128,E306,E305,I,D,T,CG,N8,S,B - -max-line-length: 88 - - -[coverage:report] - -omit = - setup.py - # Do not cover test files themselves - */test_*.py - -exclude_lines = - # Remember that these are reg exp - - # Have to re-enable the standard pragma - pragma: no cover - - raise AssertionError - raise NotImplementedError - raise JSError - - # Don't complain if non-runnable code isn't run: - if 0: - if False: - if __name__ == .__main__.: - if this_is_js(): - - # Don't complain for platform specific code - sys\.platform.startswith\(\'win\'\) - sys\.platform.startswith\(\'darwin\'\) - getattr\(sys, \'frozen\'\,\ None\) - - # Don't complain about caught import fails - except ImportError: diff --git a/setup.py b/setup.py deleted file mode 100644 index c59c559b..00000000 --- a/setup.py +++ /dev/null @@ -1,98 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -PScript setup script. -""" - -import os -import shutil - -try: - import setuptools # noqa, analysis:ignore -except ImportError: - pass # setuptools allows for "develop", but it's not essential - -from distutils.core import setup - - -## Function we need - -def get_version_and_doc(filename): - NS = dict(__version__='', __doc__='') - docStatus = 0 # Not started, in progress, done - for line in open(filename, 'rb').read().decode().splitlines(): - if line.startswith('__version__'): - exec(line.strip(), NS, NS) - elif line.startswith('"""'): - if docStatus == 0: - docStatus = 1 - line = line.lstrip('"') - elif docStatus == 1: - docStatus = 2 - if docStatus == 1: - NS['__doc__'] += line.rstrip() + '\n' - if not NS['__version__']: - raise RuntimeError('Could not find __version__') - return NS['__version__'], NS['__doc__'] - - -def package_tree(pkgroot): - subdirs = [os.path.relpath(i[0], THIS_DIR).replace(os.path.sep, '.') - for i in os.walk(os.path.join(THIS_DIR, pkgroot)) - if '__init__.py' in i[2]] - return subdirs - - -## Collect info for setup() - -THIS_DIR = os.path.dirname(__file__) - -# Define name and description -name = 'pscript' -description = "Python to JavaScript compiler." - -# Get version and docstring (i.e. long description) -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() - - -## Setup - -setup( - name=name, - version=version, - author='Almar Klein and contributors', - author_email='almar.klein@gmail.com', - license='(new) BSD', - url='http://pscript.readthedocs.io', - download_url='https://pypi.python.org/pypi/pscript', - keywords="Python, JavaScript, compiler, transpiler", - description=description, - long_description=doc, - long_description_content_type="text/markdown", - platforms='any', - provides=[name], - install_requires=[], - packages=package_tree(name), - package_dir={name: name}, - # entry_points={'console_scripts': ['pscript = pscript.__main__:main'], }, - zip_safe=True, - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Science/Research', - 'Intended Audience :: Education', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - ], -) From e74ff9a86f68b6c4dfcc22663f87e9ca266e167d Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 24 Jan 2025 15:25:55 +0100 Subject: [PATCH 2/2] copyright --- LICENSE | 2 +- docs/conf.py | 2 +- docs/gettingstarted.rst | 10 +++++----- pscript/testing.py | 9 +-------- pyproject.toml | 1 + tests/test_commonast.py | 3 --- tests/test_parser1.py | 3 --- tests/test_parser2.py | 2 -- 8 files changed, 9 insertions(+), 23 deletions(-) diff --git a/LICENSE b/LICENSE index b4d057fd..5f45ebf6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015-2020, PScript developers +Copyright (c) 2015-2025, Almar Klein All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/docs/conf.py b/docs/conf.py index 0525516a..e3a12d58 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -59,7 +59,7 @@ # General information about the project. project = 'PScript' -copyright = '2015-2020, PScript contributors' +copyright = '2015-2025, Almar Klein' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 5a846775..25e55d02 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -4,9 +4,9 @@ Getting started Installation ------------ -PScript has no dependencies except Python. It requires Python 2.7 or 3.4+. +PScript has no dependencies except Python. It requires Python 3.6+. Use either of these to install PScript: - + * ``pip install pscript`` * ``conda install pscript`` @@ -21,16 +21,16 @@ A short example: .. code-block:: py from pscript import py2js - + def foo(a, b=2): print(a - b) - + print(py2js(foo)) Gives: .. code-block:: js - + var foo; foo = function flx_foo (a, b) { b = (b === undefined) ? 2: b; diff --git a/pscript/testing.py b/pscript/testing.py index a3c5dc4b..8cdf4b02 100644 --- a/pscript/testing.py +++ b/pscript/testing.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2016, Almar Klein -# Distributed under the (new) BSD License. - """ Functionality used for testing, based on pytest. This module is designed to just work, without modification, in most projects. @@ -16,9 +12,6 @@ and report coverage. Magic! """ - -from __future__ import absolute_import, print_function, division - import os import sys import inspect @@ -50,7 +43,7 @@ def run_tests_if_main(show_coverage=False): """ Run tests in a given file if it is run as a script - + Coverage is reported for running this single test. Set show_coverage to launch the report in the web browser. """ diff --git a/pyproject.toml b/pyproject.toml index fab88e31..485864c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ # Notes on how to do a release. # +# * Write release notes in docs/releasenotes.txt # * Bump `__version__` and commit. # * git tag vx.y # * git push origin main vx.y diff --git a/tests/test_commonast.py b/tests/test_commonast.py index 3d0352a1..1b2191ad 100644 --- a/tests/test_commonast.py +++ b/tests/test_commonast.py @@ -1,6 +1,3 @@ - -from __future__ import print_function, absolute_import - import os import sys import bz2 diff --git a/tests/test_parser1.py b/tests/test_parser1.py index c470ac5d..d1540295 100644 --- a/tests/test_parser1.py +++ b/tests/test_parser1.py @@ -91,9 +91,6 @@ def test_string_formatting2(self): assert py2jslight("'hi %f %1.2f' % (a, b)") == py2jslight("'hi {:f} {:1.2f}'.format(a, b)") assert py2jslight("'hi %s %r' % (a, b)") == py2jslight("'hi {} {!r}'.format(a, b)") - if sys.version_info < (3, 6): - return - # Verify that f-string formatting produces same JS as str.format - Python 3.6+ assert py2jslight("f'hi {a:i}'") == py2jslight("'hi {:i}'.format(a)") assert py2js("f'hi {a:i} {b:+i}'") == py2js("'hi {:i} {:+i}'.format(a, b)") diff --git a/tests/test_parser2.py b/tests/test_parser2.py index f78892eb..d44e5a93 100644 --- a/tests/test_parser2.py +++ b/tests/test_parser2.py @@ -852,8 +852,6 @@ def func(a, b): assert code.count('// docstring') == 1 def test_async_and_await(self): - if sys.version_info < (3, 6): - return foo = py2js('async def foo(): return 42\n\n') spam = py2js('async def spam(): print(await foo())\n\n')