Skip to content

Commit

Permalink
Merge pull request #683 from evhub/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub authored Nov 14, 2022
2 parents 0d6fba4 + 48ad7af commit fb4540e
Show file tree
Hide file tree
Showing 49 changed files with 1,720 additions and 651 deletions.
3 changes: 3 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ environment:
- PYTHON: "C:\\Python310"
PYTHON_VERSION: "3.10.x"
PYTHON_ARCH: "64"
- PYTHON: "C:\\Python311"
PYTHON_VERSION: "3.11.x"
PYTHON_ARCH: "64"

install:
# pywinpty installation fails without prior rust installation on some Python versions
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['2.7', 'pypy-2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.6']
python-version:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- 'pypy-2.7'
- 'pypy-3.6'
- 'pypy-3.7'
- 'pypy-3.8'
- 'pypy-3.9'
fail-fast: false
name: Python ${{ matrix.python-version }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
args:
- --ignore=W503,E501,E265,E402,F405,E305,E126
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.7.0
rev: v2.0.0
hooks:
- id: autopep8
args:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ After you've tested your changes locally, you'll want to add more permanent test
1. Release a new version of [`sublime-coconut`](https://github.com/evhub/sublime-coconut) if applicable
1. Edit the [`package.json`](https://github.com/evhub/sublime-coconut/blob/master/package.json) with the new version
2. Run `make publish`
3. Release a new version on GitHub
3. [Release a new version on GitHub](https://github.com/evhub/sublime-coconut/releases)
2. Merge pull request and mark as resolved
3. Release `master` on GitHub
4. `git fetch`, `git checkout master`, and `git pull`
Expand Down
232 changes: 170 additions & 62 deletions DOCS.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ I certainly hope not! Unlike most transpiled languages, all valid Python is vali

First, you're going to want a fast compiler, so you should make sure you're using [`cPyparsing`](https://github.com/evhub/cpyparsing). Second, there are two simple things you can do to make Coconut produce faster Python: compile with `--no-tco` and compile with a `--target` specification for the exact version of Python you want to run your code on. Passing `--target` helps Coconut optimize the compiled code for the Python version you want, and, though [Tail Call Optimization](./DOCS.md#tail-call-optimization) is useful, it will usually significantly slow down functions that use it, so disabling it will often provide a major performance boost.

### When I try to use Coconut on the command line, I get weird unprintable characters and numbers; how do I get rid of them?

You're probably seeing color codes while using a terminal that doesn't support them (e.g. Windows `cmd`). Try setting the `COCONUT_USE_COLOR` environment variable to `FALSE` to get rid of them.

### I want to contribute to Coconut, how do I get started?

That's great! Coconut is completely open-source, and new contributors are always welcome. Check out Coconut's [contributing guidelines](./CONTRIBUTING.md) for more information.
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ global-include *.md
global-include *.json
global-include *.toml
global-include *.coco
global-include py.typed
prune coconut/tests/dest
prune docs
prune pyston
prune pyprover
prune bbopt
prune coconut-prelude
prune .mypy_cache
prune coconut/stubs/.mypy_cache
prune .pytest_cache
prune *.egg-info
prune .github
exclude index.rst
exclude profile.json
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ dev-py3: clean setup-py3

.PHONY: setup
setup:
python -m ensurepip
python -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: setup-py2
setup-py2:
python2 -m ensurepip
python2 -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: setup-py3
setup-py3:
python3 -m ensurepip
python3 -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: setup-pypy
setup-pypy:
pypy -m ensurepip
pypy -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: setup-pypy3
setup-pypy3:
pypy3 -m ensurepip
pypy3 -m pip install --upgrade "setuptools<58" wheel pip pytest_remotedata

.PHONY: install
Expand Down Expand Up @@ -71,6 +76,7 @@ test: test-mypy

# basic testing for the universal target
.PHONY: test-univ
test-univ: export COCONUT_USE_COLOR=TRUE
test-univ:
python ./coconut/tests --strict --line-numbers --force
python ./coconut/tests/dest/runner.py
Expand All @@ -79,69 +85,87 @@ test-univ:
# same as test-univ, but doesn't recompile unchanged test files;
# should only be used when testing the tests not the compiler
.PHONY: test-tests
test-tests: export COCONUT_USE_COLOR=TRUE
test-tests:
python ./coconut/tests --strict --line-numbers
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-univ but uses Python 2
.PHONY: test-py2
test-py2: export COCONUT_USE_COLOR=TRUE
test-py2:
python2 ./coconut/tests --strict --line-numbers --force
python2 ./coconut/tests/dest/runner.py
python2 ./coconut/tests/dest/extras.py

# same as test-univ but uses Python 3
.PHONY: test-py3
test-py3: export COCONUT_USE_COLOR=TRUE
test-py3:
python3 ./coconut/tests --strict --line-numbers --force
python3 ./coconut/tests/dest/runner.py
python3 ./coconut/tests/dest/extras.py

# same as test-univ but uses PyPy
.PHONY: test-pypy
test-pypy: export COCONUT_USE_COLOR=TRUE
test-pypy:
pypy ./coconut/tests --strict --line-numbers --force
pypy ./coconut/tests/dest/runner.py
pypy ./coconut/tests/dest/extras.py

# same as test-univ but uses PyPy3
.PHONY: test-pypy3
test-pypy3: export COCONUT_USE_COLOR=TRUE
test-pypy3:
pypy3 ./coconut/tests --strict --line-numbers --force
pypy3 ./coconut/tests/dest/runner.py
pypy3 ./coconut/tests/dest/extras.py

# same as test-pypy3 but includes verbose output for better debugging
.PHONY: test-pypy3-verbose
test-pypy3-verbose: export COCONUT_USE_COLOR=TRUE
test-pypy3-verbose:
pypy3 ./coconut/tests --strict --line-numbers --force --verbose --jobs 0
pypy3 ./coconut/tests/dest/runner.py
pypy3 ./coconut/tests/dest/extras.py

# same as test-univ but also runs mypy
.PHONY: test-mypy
test-mypy: export COCONUT_USE_COLOR=TRUE
test-mypy:
python ./coconut/tests --strict --force --target sys --mypy --follow-imports silent --ignore-missing-imports --allow-redefinition
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-mypy but uses the universal target
.PHONY: test-mypy-univ
test-mypy-univ: export COCONUT_USE_COLOR=TRUE
test-mypy-univ:
python ./coconut/tests --strict --force --mypy --follow-imports silent --ignore-missing-imports --allow-redefinition
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-univ but includes verbose output for better debugging
.PHONY: test-verbose
test-verbose: export COCONUT_USE_COLOR=TRUE
test-verbose:
python ./coconut/tests --strict --line-numbers --force --verbose --jobs 0
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-mypy but uses --verbose and --check-untyped-defs
.PHONY: test-mypy-all
test-mypy-all: export COCONUT_USE_COLOR=TRUE
test-mypy-all:
python ./coconut/tests --strict --force --target sys --verbose --mypy --follow-imports silent --ignore-missing-imports --allow-redefinition --check-untyped-defs
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-univ but also tests easter eggs
.PHONY: test-easter-eggs
test-easter-eggs: export COCONUT_USE_COLOR=TRUE
test-easter-eggs:
python ./coconut/tests --strict --line-numbers --force
python ./coconut/tests/dest/runner.py --test-easter-eggs
Expand All @@ -154,13 +178,15 @@ test-pyparsing: test-univ

# same as test-univ but uses --minify
.PHONY: test-minify
test-minify: export COCONUT_USE_COLOR=TRUE
test-minify:
python ./coconut/tests --strict --line-numbers --force --minify
python ./coconut/tests/dest/runner.py
python ./coconut/tests/dest/extras.py

# same as test-univ but watches tests before running them
.PHONY: test-watch
test-watch: export COCONUT_USE_COLOR=TRUE
test-watch:
python ./coconut/tests --strict --line-numbers --force
coconut ./coconut/tests/src/cocotest/agnostic ./coconut/tests/dest/cocotest --watch --strict --line-numbers
Expand All @@ -176,6 +202,10 @@ test-mini:
diff:
git diff origin/develop

.PHONY: fix-develop
fix-develop:
git merge master -s ours

.PHONY: docs
docs: clean
sphinx-build -b html . ./docs
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Coconut is developed on GitHub_ and hosted on PyPI_. Installing Coconut is as ea

pip install coconut

after which the entire world of Coconut will be at your disposal. To help you get started, check out these links for more information about Coconut:
To help you get started, check out these links for more information about Coconut:

- Tutorial_: If you're new to Coconut, a good place to start is Coconut's **tutorial**.
- Documentation_: If you're looking for info about a specific feature, check out Coconut's **documentation**.
Expand Down
26 changes: 26 additions & 0 deletions __coconut__/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------------------------------------------------
# INFO:
# -----------------------------------------------------------------------------------------------------------------------

"""
Author: Evan Hubinger
License: Apache 2.0
Description: For type checking purposes only. Should never be imported.
"""

# -----------------------------------------------------------------------------------------------------------------------
# IMPORTS:
# -----------------------------------------------------------------------------------------------------------------------

from __future__ import print_function, absolute_import, unicode_literals, division

from coconut.root import * # NOQA

# -----------------------------------------------------------------------------------------------------------------------
# ERROR:
# -----------------------------------------------------------------------------------------------------------------------

raise ImportError("Importing the top-level __coconut__ package should never be done at runtime; __coconut__ exists for type checking purposes only. Try 'import coconut.__coconut__' instead.")
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions _coconut/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------------------------------------------------
# INFO:
# -----------------------------------------------------------------------------------------------------------------------

"""
Author: Evan Hubinger
License: Apache 2.0
Description: For type checking purposes only. Should never be imported.
"""

# -----------------------------------------------------------------------------------------------------------------------
# IMPORTS:
# -----------------------------------------------------------------------------------------------------------------------

from __future__ import print_function, absolute_import, unicode_literals, division

from coconut.root import * # NOQA

# -----------------------------------------------------------------------------------------------------------------------
# ERROR:
# -----------------------------------------------------------------------------------------------------------------------

raise ImportError("Importing the top-level _coconut package should never be done at runtime; _coconut exists for type checking purposes only. Try 'from coconut.__coconut__ import _coconut' instead.")
23 changes: 22 additions & 1 deletion coconut/stubs/_coconut.pyi → _coconut/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,32 @@ except ImportError:
else:
_abc.Sequence.register(_numpy.ndarray)

if sys.version_info < (3, 10):
try:
from typing_extensions import TypeAlias, ParamSpec, Concatenate
except ImportError:
TypeAlias = ...
ParamSpec = ...
typing.TypeAlias = TypeAlias
typing.ParamSpec = ParamSpec
typing.Concatenate = Concatenate


if sys.version_info < (3, 11):
try:
from typing_extensions import TypeVarTuple, Unpack
except ImportError:
TypeVarTuple = ...
Unpack = ...
typing.TypeVarTuple = TypeVarTuple
typing.Unpack = Unpack

# -----------------------------------------------------------------------------------------------------------------------
# STUB:
# -----------------------------------------------------------------------------------------------------------------------

typing = _t # The real _coconut doesn't import typing, but we want type-checkers to treat it as if it does
typing = _t

collections = _collections
copy = _copy
copyreg = _copyreg
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions coconut/__coconut__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
Author: Evan Hubinger
License: Apache 2.0
Description: Mimics what a compiled __coconut__.py would do.
Must match __coconut__.__init__.
"""

# -----------------------------------------------------------------------------------------------------------------------
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions coconut/_pyparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
_trim_arity = _pyparsing._trim_arity
_ParseResultsWithOffset = _pyparsing._ParseResultsWithOffset

if MODERN_PYPARSING:
warn(
"This version of Coconut is not built for pyparsing v3; some syntax features WILL NOT WORK"
+ " (run either '{python} -m pip install cPyparsing<{max_ver}' or '{python} -m pip install pyparsing<{max_ver}' to fix)".format(python=sys.executable, max_ver=max_ver_str),
)

USE_COMPUTATION_GRAPH = (
not MODERN_PYPARSING # not yet supported
and not PYPY # experimentally determined
Expand Down Expand Up @@ -174,11 +180,6 @@ def _parseCache(self, instring, loc, doActions=True, callPreParse=True):
return value[0], value[1].copy()
ParserElement.packrat_context = []
ParserElement._parseCache = _parseCache
else:
warn(
"This version of Coconut is not built for pyparsing v3; some syntax features WILL NOT WORK"
+ " (run either '{python} -m pip install --upgrade cPyparsing' or '{python} -m pip install pyparsing<{max_ver}' to fix)".format(python=sys.executable, max_ver=max_ver_str),
)


# -----------------------------------------------------------------------------------------------------------------------
Expand Down
Empty file added coconut/command/__init__.pyi
Empty file.
2 changes: 1 addition & 1 deletion coconut/command/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"--and",
metavar=("source", "dest"),
type=str,
nargs=2,
nargs="+",
action="append",
help="additional source/dest pairs to compile",
)
Expand Down
Loading

0 comments on commit fb4540e

Please sign in to comment.