coconut 3.1.2__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coconut-3.2.0/.claude/CLAUDE.md +91 -0
- coconut-3.2.0/.claude/settings.local.json +23 -0
- {coconut-3.1.2 → coconut-3.2.0}/CONTRIBUTING.md +202 -199
- {coconut-3.1.2 → coconut-3.2.0}/DOCS.md +4922 -4917
- {coconut-3.1.2 → coconut-3.2.0}/HELP.md +1168 -1168
- {coconut-3.1.2 → coconut-3.2.0}/PKG-INFO +204 -185
- {coconut-3.1.2 → coconut-3.2.0}/README.rst +80 -82
- {coconut-3.1.2 → coconut-3.2.0}/__coconut__/__init__.pyi +2066 -2065
- {coconut-3.1.2 → coconut-3.2.0}/_coconut/__init__.pyi +188 -180
- {coconut-3.1.2 → coconut-3.2.0}/coconut/_pyparsing.py +553 -552
- {coconut-3.1.2 → coconut-3.2.0}/coconut/api.py +397 -394
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/command.py +1239 -1238
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/compiler.py +5569 -5253
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/grammar.py +2927 -2922
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/header.py +1065 -1065
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/matching.py +1514 -1513
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/templates/header.py_template +2274 -2241
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/util.py +2277 -2281
- {coconut-3.1.2 → coconut-3.2.0}/coconut/constants.py +1383 -1364
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/root.py +360 -355
- {coconut-3.1.2 → coconut-3.2.0}/coconut/root.py +490 -478
- {coconut-3.1.2 → coconut-3.2.0}/coconut/terminal.py +680 -674
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/constants_test.py +149 -145
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/main_test.py +1153 -1125
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/main.coco +142 -134
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/primary_2.coco +521 -503
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/specific.coco +240 -203
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/suite.coco +1116 -1113
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/util.coco +2146 -2136
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_2/py2_test.coco +8 -8
- coconut-3.2.0/coconut/tests/src/cocotest/target_314/py314_test.coco +35 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/extras.coco +795 -794
- {coconut-3.1.2 → coconut-3.2.0}/coconut/util.py +515 -468
- {coconut-3.1.2 → coconut-3.2.0}/coconut.egg-info/SOURCES.txt +3 -0
- {coconut-3.1.2 → coconut-3.2.0}/FAQ.md +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/LICENSE.txt +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/MANIFEST.in +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/__coconut__/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/__coconut__/py.typed +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/_coconut/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/_coconut/py.typed +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/__coconut__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/__coconut__.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/__init__.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/__main__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/api.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/__init__.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/cli.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/command.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/mypy.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/resources/zcoconut.pth +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/util.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/command/watch.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/compiler/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/convenience.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/convenience.pyi +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/exceptions.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/highlighter.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/__main__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/coconut/kernel.json +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/coconut_py/kernel.json +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/coconut_py2/kernel.json +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/coconut_py3/kernel.json +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/icoconut/embed.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/integrations.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/main.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/py.typed +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/requirements.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/__init__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/__main__.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/__init__.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/__main__.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/primary_1.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/agnostic/tutorial.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/non_strict/non_strict_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_3/py3_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_311/py311_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_35/py35_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_36/py36_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_38/py38_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/cocotest/target_sys/target_sys_test.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/importable.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/runnable.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/coconut/tests/src/runner.coco +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/conf.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/pyproject.toml +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/setup.cfg +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/setup.py +0 -0
- {coconut-3.1.2 → coconut-3.2.0}/xontrib/coconut.py +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
Coconut is a functional programming language that compiles to Python. It adds features like pattern matching, algebraic data types, partial application, pipeline operators, and lazy evaluation on top of Python syntax. The compiler performs one-pass compilation using PyParsing. If you are ever uncertain about what the intended behavior should be, refer to the documentation in DOCS.md.
|
|
7
|
+
|
|
8
|
+
## Common Commands
|
|
9
|
+
|
|
10
|
+
### Development Setup
|
|
11
|
+
```bash
|
|
12
|
+
make dev # Install development environment with all dependencies and pre-commit hooks
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Testing
|
|
16
|
+
|
|
17
|
+
Tests can take a long time, especially when recompiling everything, so make sure to run them with a long timeout.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
make test # Recompile all test files and run them (should be used whenever testing any changes to the compiler itself)
|
|
21
|
+
make test-tests # Just recompile changed test files and run them (much faster, but should only be used when the change being tested is just a change to the tests themselves)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Running Coconut Code Directly
|
|
25
|
+
```bash
|
|
26
|
+
python -m coconut -c "your code here" # Compile and execute Coconut code passed as a string
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Architecture
|
|
30
|
+
|
|
31
|
+
### Compilation Pipeline
|
|
32
|
+
1. **Pre-processing**: String replacement markers handle special cases (`coconut/compiler/compiler.py`)
|
|
33
|
+
2. **One-pass compilation**: PyParsing grammar with attached handlers transform Coconut to Python (`coconut/compiler/grammar.py`)
|
|
34
|
+
3. **Post-processing**: Generated header prepended to output (`coconut/compiler/header.py`)
|
|
35
|
+
|
|
36
|
+
### Core Modules
|
|
37
|
+
|
|
38
|
+
**`coconut/root.py`** - Python 2/3 compatibility layer. Every module imports `from coconut.root import *`. Defines version constants and base header.
|
|
39
|
+
|
|
40
|
+
**`coconut/constants.py`** - Global configuration: version info, platform detection flags (`PY26`...`PY314`, `WINDOWS`, `PYPY`, `CPYTHON`), dependencies, magic numbers, environment variables.
|
|
41
|
+
|
|
42
|
+
**`coconut/compiler/`**:
|
|
43
|
+
- `compiler.py` - `Compiler` class inheriting from `Grammar`. Main compilation logic.
|
|
44
|
+
- `grammar.py` - `Grammar` class with PyParsing rules and basic handlers.
|
|
45
|
+
- `matching.py` - `Matcher` class for pattern matching compilation (match statements, destructuring, pattern-matching functions).
|
|
46
|
+
- `header.py` - Generates runtime header from `templates/header.py_template`.
|
|
47
|
+
|
|
48
|
+
**`coconut/command/`**:
|
|
49
|
+
- `command.py` - `Command` class; CLI entry point via `start` method.
|
|
50
|
+
- `cli.py` - `ArgumentParser` for command-line arguments.
|
|
51
|
+
- `util.py` - `Prompt` (syntax-highlighted input), `Runner` (executes compiled Python).
|
|
52
|
+
|
|
53
|
+
**`coconut/icoconut/`** - Jupyter kernel implementation (subclasses IPython kernel).
|
|
54
|
+
|
|
55
|
+
### Key Entry Points
|
|
56
|
+
- `coconut/main.py` - Entry points for `coconut` and `coconut-run` CLI commands
|
|
57
|
+
- `coconut/api.py` - External API for programmatic usage
|
|
58
|
+
- `coconut/convenience.py` - High-level functions: `cmd()`, `version()`, `parse()`, `setup()`
|
|
59
|
+
|
|
60
|
+
## Testing
|
|
61
|
+
|
|
62
|
+
Tests are written in Coconut (`.coco` files), not Python. Located in `coconut/tests/src/`:
|
|
63
|
+
- `cocotest/agnostic/` - Version-agnostic tests (main.coco, suite.coco, util.coco)
|
|
64
|
+
- `cocotest/target_*/` - Version-specific tests
|
|
65
|
+
|
|
66
|
+
To add tests: write Coconut code with `assert` statements in the appropriate `.coco` test file.
|
|
67
|
+
|
|
68
|
+
## Code Conventions
|
|
69
|
+
|
|
70
|
+
- **Module imports**: Always include `from coconut.root import *` at the top for version compatibility
|
|
71
|
+
- **Logging**: Use `logger` from `coconut.terminal` for console output
|
|
72
|
+
- **Exceptions**: Custom hierarchy in `coconut/exceptions.py`
|
|
73
|
+
- **Author attribution**: Add yourself to "Authors:" in module docstrings when modifying files
|
|
74
|
+
|
|
75
|
+
## Branches
|
|
76
|
+
- `master` - Stable releases
|
|
77
|
+
- `develop` - Active development (default branch for contributions)
|
|
78
|
+
|
|
79
|
+
## Debugging GitHub Actions
|
|
80
|
+
|
|
81
|
+
### Viewing Logs for a Specific Job
|
|
82
|
+
|
|
83
|
+
When investigating a failed GitHub Actions job, use the GitHub API directly:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
gh api repos/evhub/coconut/actions/jobs/{job_id}/logs
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Replace `{job_id}` with the job ID from the URL (e.g., for `.../job/59132870840`, use `59132870840`).
|
|
90
|
+
|
|
91
|
+
**Note:** The more common `gh run view {run_id} --log-failed` command doesn't work if the overall run is still in progress, even if the specific job you want has already completed. Using the API directly bypasses this limitation.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"WebSearch",
|
|
5
|
+
"Bash(cat:*)",
|
|
6
|
+
"Bash(cd:*)",
|
|
7
|
+
"Bash(ls:*)",
|
|
8
|
+
"Bash(echo:*)",
|
|
9
|
+
"Bash(python:*)",
|
|
10
|
+
"Bash(gh:*)",
|
|
11
|
+
"Bash(pip:*)",
|
|
12
|
+
"Bash(conda:*)",
|
|
13
|
+
"Bash(xonsh:*)",
|
|
14
|
+
"Bash(make test-tests:*)",
|
|
15
|
+
"WebFetch(domain:coconut.readthedocs.io)",
|
|
16
|
+
"WebFetch(domain:github.com)",
|
|
17
|
+
"WebFetch(domain:peps.python.org)",
|
|
18
|
+
"WebFetch(domain:pypi.org)",
|
|
19
|
+
"WebFetch(domain:discuss.python.org)",
|
|
20
|
+
"WebFetch(domain:doc.pypy.org)"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,199 +1,202 @@
|
|
|
1
|
-
# Coconut Contributing Guidelines
|
|
2
|
-
|
|
3
|
-
_By contributing to Coconut, you agree to your contribution being released under [Coconut's Apache 2.0 license](https://github.com/evhub/coconut/blob/develop/LICENSE.txt)._
|
|
4
|
-
|
|
5
|
-
**Anyone is welcome to submit an issue or pull request!** The purpose of this document is simply to explain the contribution process and the internals of how Coconut works to make contributing easier.
|
|
6
|
-
|
|
7
|
-
If you are considering contributing to Coconut, you'll be doing so on the [`develop` branch](https://github.com/evhub/coconut/tree/develop), which means you should be viewing [the `develop` version of the Contributing Guidelines](http://coconut.readthedocs.io/en/develop/CONTRIBUTING.html), if you aren't doing so already.
|
|
8
|
-
|
|
9
|
-
## Asking Questions
|
|
10
|
-
|
|
11
|
-
If you are thinking about contributing to Coconut, please don't hesitate to ask questions at Coconut's [Gitter](https://gitter.im/evhub/coconut)! That includes any questions at all about contributing, including understanding the source code, figuring out how to implement a specific change, or just trying to figure out what needs to be done.
|
|
12
|
-
|
|
13
|
-
## Good First Issues
|
|
14
|
-
|
|
15
|
-
Want to help out, but don't know what to work on? Head over to Coconut's [open issues](https://github.com/evhub/coconut/issues) and look for ones labeled "good first issue." These issues are those that require less intimate knowledge of Coconut's inner workings, and are thus possible for new contributors to work on.
|
|
16
|
-
|
|
17
|
-
## Contribution Process
|
|
18
|
-
|
|
19
|
-
Contributing to Coconut is as simple as
|
|
20
|
-
|
|
21
|
-
1. forking Coconut on [GitHub](https://github.com/evhub/coconut),
|
|
22
|
-
2. making changes to the [`develop` branch](https://github.com/evhub/coconut/tree/develop), and
|
|
23
|
-
3. proposing a pull request.
|
|
24
|
-
|
|
25
|
-
_Note: Don't forget to add yourself to the "Authors:" section in the moduledocs of any files you modify!_
|
|
26
|
-
|
|
27
|
-
## Testing New Changes
|
|
28
|
-
|
|
29
|
-
First, you'll want to set up a local copy of Coconut's recommended development environment. For that, just run `git checkout develop`, make sure your default `python` installation is some variant of Python 3, and run `make dev`. That should switch you to the `develop` branch, install all possible dependencies, bind the `coconut` command to your local copy, and set up [pre-commit](http://pre-commit.com/), which will check your code for errors for you whenever you `git commit`.
|
|
30
|
-
|
|
31
|
-
Then, you should be able to use the Coconut command-line for trying out simple things, and to run a paired-down version of the test suite locally, just `make test-univ`.
|
|
32
|
-
|
|
33
|
-
After you've tested your changes locally, you'll want to add more permanent tests to Coconut's test suite. Coconut's test suite is primarily written in Coconut itself, so testing new features just means using them inside of one of Coconut's `.coco` test files, with some `assert` statements to check validity.
|
|
34
|
-
|
|
35
|
-
## File Layout
|
|
36
|
-
|
|
37
|
-
- `DOCS.md`
|
|
38
|
-
+ Markdown file containing detailed documentation on every Coconut feature. If you are adding a new feature, you should also add documentation on it to this file.
|
|
39
|
-
- `FAQ.md`
|
|
40
|
-
+ Markdown file containing frequently asked questions and their answers. If you had a question you wished was answered earlier when learning Coconut, you should add it to this file.
|
|
41
|
-
- `HELP.md`
|
|
42
|
-
+ Markdown file containing Coconut's tutorial. The tutorial should be a streamlined introduction to Coconut and all of its most important features.
|
|
43
|
-
- `Makefile`
|
|
44
|
-
+ Contains targets for installing Coconut, building the documentation, checking for dependency updates, etc.
|
|
45
|
-
- `setup.py`
|
|
46
|
-
+ Using information from `requirements.py` and `constants.py` to install Coconut. Also reads `README.rst` to generate the PyPI description.
|
|
47
|
-
- `conf.py`
|
|
48
|
-
+ Sphinx configuration file for Coconut's documentation.
|
|
49
|
-
- coconut
|
|
50
|
-
- `__coconut__.py`
|
|
51
|
-
+ Mimics the Coconut header by generating and executing it when imported. Used by the REPL.
|
|
52
|
-
- `__init__.py`
|
|
53
|
-
+ Includes the implementation of the `%coconut` IPython magic.
|
|
54
|
-
- `__main__.py`
|
|
55
|
-
+ Imports and runs `main` from `main.py`.
|
|
56
|
-
- `constants.py`
|
|
57
|
-
+ All constants used across Coconut are defined here, including dependencies, magic numbers/strings, etc.
|
|
58
|
-
- `convenience.py`
|
|
59
|
-
+ Contains `cmd`, `version`, `setup`, and `parse` functions as convenience utilities when using Coconut as a module. Documented in `DOCS.md`.
|
|
60
|
-
- `exceptions.py`
|
|
61
|
-
+ All of the exceptions raised by Coconut are defined here, both those shown to the user and those used only internally.
|
|
62
|
-
- `highlighter.py`
|
|
63
|
-
+ Contains Coconut's Pygments syntax highlighter, as well as modified Python highlighters that don't fail if they encounter unknown syntax.
|
|
64
|
-
- `main.py`
|
|
65
|
-
+ Contains `main` and `main_run`, the entry points for the `coconut` and `coconut-run` commands, respectively.
|
|
66
|
-
- `requirements.py`
|
|
67
|
-
+ Processes Coconut's requirements from `constants.py` into a form `setup.py` can use, as well as checks for updates to Coconut's dependencies.
|
|
68
|
-
- `root.py`
|
|
69
|
-
+ `root.py` creates and executes the part of Coconut's header that normalizes Python built-ins across versions. Whenever you are writing a new file, you should always add `from coconut.root import *` to ensure compatibility with different Python versions. `root.py` also sets basic version-related constants.
|
|
70
|
-
- `terminal.py`
|
|
71
|
-
+ Contains utilities for displaying messages to the console, mainly `logger`, which is Coconut's primary method of logging a message from anywhere.
|
|
72
|
-
- command
|
|
73
|
-
- `__init__.py`
|
|
74
|
-
+ Imports everything in `command.py`.
|
|
75
|
-
- `cli.py`
|
|
76
|
-
+ Creates the `ArgumentParser` object used to parse Coconut command-line arguments.
|
|
77
|
-
- `command.py`
|
|
78
|
-
+ Contains `Command`, whose `start` method is the main entry point for the Coconut command-line utility.
|
|
79
|
-
- `mypy.py`
|
|
80
|
-
+ Contains objects necessary for Coconut's `--mypy` flag.
|
|
81
|
-
- `util.py`
|
|
82
|
-
+ Contains utilities used by `command.py`, including `Prompt` for getting syntax-highlighted input, and `Runner` for executing compiled Python.
|
|
83
|
-
- `watch.py`
|
|
84
|
-
+ Contains objects necessary for Coconut's `--watch` flag.
|
|
85
|
-
- compiler
|
|
86
|
-
- `__init__.py`
|
|
87
|
-
+ Imports everything in `compiler.py`.
|
|
88
|
-
- `compiler.py`
|
|
89
|
-
+ Contains `Compiler`, the class that actually compiles Coconut code. `Compiler` inherits from `Grammar` in `grammar.py` to get all of the basic grammatical definitions, then extends them with all of the handlers that depend on the compiler's options (e.g. the current `--target`). `Compiler` also does pre- and post-processing, including replacing strings with markers (pre-processing) and adding the header (post-processing).
|
|
90
|
-
- `grammar.py`
|
|
91
|
-
+ Contains `Grammar`, the class that specifies Coconut's grammar in PyParsing. Coconut performs one-pass compilation by attaching "handlers" to specific grammar objects to transform them into compiled Python. `grammar.py` contains all basic (non-option-dependent) handlers.
|
|
92
|
-
- `header.py`
|
|
93
|
-
+ Contains `getheader`, which generates the header at the top of all compiled Coconut files.
|
|
94
|
-
- `matching.py`
|
|
95
|
-
+ Contains `Matcher`, which handles the compilation of all Coconut pattern-matching, including `match` statements, destructuring assignment, and pattern-matching functions.
|
|
96
|
-
- `util.py`
|
|
97
|
-
+ Contains utilities for working with PyParsing objects that are primarily used by `grammar.py`.
|
|
98
|
-
- templates
|
|
99
|
-
- `header.py_template`
|
|
100
|
-
+ Template for the main body of Coconut's header; use and formatting of this file is all in `header.py`.
|
|
101
|
-
- icoconut
|
|
102
|
-
- `__init__.py`
|
|
103
|
-
+ Imports everything from `icoconut/root.py`.
|
|
104
|
-
- `__main__.py`
|
|
105
|
-
+ Contains the main entry point for Coconut's Jupyter kernel.
|
|
106
|
-
- `root.py`
|
|
107
|
-
+ Contains the implementation of Coconut's Jupyter kernel, made by subclassing the IPython kernel.
|
|
108
|
-
- tests
|
|
109
|
-
- `__init__.py`
|
|
110
|
-
+ Imports everything in `main_test.py`.
|
|
111
|
-
- `__main__.py`
|
|
112
|
-
+ When run, compiles all of the test source code, but _does not run any tests_. To run the tests, the command `make test`, or a `pytest` command to run a specific test, is necessary.
|
|
113
|
-
- `main_test.py`
|
|
114
|
-
+ Contains `TestCase` subclasses that run all of the commands for testing the Coconut files in `src`.
|
|
115
|
-
- src
|
|
116
|
-
- `extras.coco`
|
|
117
|
-
+ Directly imports and calls functions in the Coconut package, including from `convenience.py` and icoconut.
|
|
118
|
-
- `runnable.coco`
|
|
119
|
-
+ Makes sure the argument `--arg` was passed when running the file.
|
|
120
|
-
- `runner.coco`
|
|
121
|
-
+ Runs `main` from `cocotest/agnostic/main.py`.
|
|
122
|
-
- cocotest
|
|
123
|
-
+ _Note: Files in the folders below all get compiled into the top-level cocotest directory. The folders are only for differentiating what files to compile on what Python version._
|
|
124
|
-
- agnostic
|
|
125
|
-
- `__init__.coco`
|
|
126
|
-
+ Contains a docstring that `main.coco` asserts exists.
|
|
127
|
-
- `main.coco`
|
|
128
|
-
+ Contains the main test entry point as well as many simple, one-line tests.
|
|
129
|
-
- `specific.coco`
|
|
130
|
-
+ Tests to be run only on a specific Python version, but not necessarily only under a specific `--target`.
|
|
131
|
-
- `suite.coco`
|
|
132
|
-
+ Tests objects defined in `util.coco`.
|
|
133
|
-
- `tutorial.coco`
|
|
134
|
-
+ Tests all the examples in `TUTORIAL.md`.
|
|
135
|
-
- `util.coco`
|
|
136
|
-
+ Contains objects used in `suite.coco`.
|
|
137
|
-
- python2
|
|
138
|
-
- `py2_test.coco`
|
|
139
|
-
+ Tests to be run only on Python 2 with `--target 2`.
|
|
140
|
-
- python3
|
|
141
|
-
- `py3_test.coco`
|
|
142
|
-
+ Tests to be run only on Python 3 with `--target 3`.
|
|
143
|
-
- python35
|
|
144
|
-
- `py35_test.coco`
|
|
145
|
-
+ Tests to be run only on Python 3.5 with `--target 3.5`.
|
|
146
|
-
- python36
|
|
147
|
-
- `py36_test.coco`
|
|
148
|
-
+ Tests to be run only on Python 3.6 with `--target 3.6`.
|
|
149
|
-
- coconut-stubs
|
|
150
|
-
- `__coconut__.pyi`
|
|
151
|
-
+ A MyPy stub file for specifying the type of all the objects defined in Coconut's package header (which is saved as `__coconut__.py`).
|
|
152
|
-
|
|
153
|
-
## Release Process
|
|
154
|
-
|
|
155
|
-
1. Preparation:
|
|
156
|
-
1. Run `make check-reqs` and update dependencies as necessary
|
|
157
|
-
2. Run `sudo make format`
|
|
158
|
-
3.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
3.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
1
|
+
# Coconut Contributing Guidelines
|
|
2
|
+
|
|
3
|
+
_By contributing to Coconut, you agree to your contribution being released under [Coconut's Apache 2.0 license](https://github.com/evhub/coconut/blob/develop/LICENSE.txt)._
|
|
4
|
+
|
|
5
|
+
**Anyone is welcome to submit an issue or pull request!** The purpose of this document is simply to explain the contribution process and the internals of how Coconut works to make contributing easier.
|
|
6
|
+
|
|
7
|
+
If you are considering contributing to Coconut, you'll be doing so on the [`develop` branch](https://github.com/evhub/coconut/tree/develop), which means you should be viewing [the `develop` version of the Contributing Guidelines](http://coconut.readthedocs.io/en/develop/CONTRIBUTING.html), if you aren't doing so already.
|
|
8
|
+
|
|
9
|
+
## Asking Questions
|
|
10
|
+
|
|
11
|
+
If you are thinking about contributing to Coconut, please don't hesitate to ask questions at Coconut's [Gitter](https://gitter.im/evhub/coconut)! That includes any questions at all about contributing, including understanding the source code, figuring out how to implement a specific change, or just trying to figure out what needs to be done.
|
|
12
|
+
|
|
13
|
+
## Good First Issues
|
|
14
|
+
|
|
15
|
+
Want to help out, but don't know what to work on? Head over to Coconut's [open issues](https://github.com/evhub/coconut/issues) and look for ones labeled "good first issue." These issues are those that require less intimate knowledge of Coconut's inner workings, and are thus possible for new contributors to work on.
|
|
16
|
+
|
|
17
|
+
## Contribution Process
|
|
18
|
+
|
|
19
|
+
Contributing to Coconut is as simple as
|
|
20
|
+
|
|
21
|
+
1. forking Coconut on [GitHub](https://github.com/evhub/coconut),
|
|
22
|
+
2. making changes to the [`develop` branch](https://github.com/evhub/coconut/tree/develop), and
|
|
23
|
+
3. proposing a pull request.
|
|
24
|
+
|
|
25
|
+
_Note: Don't forget to add yourself to the "Authors:" section in the moduledocs of any files you modify!_
|
|
26
|
+
|
|
27
|
+
## Testing New Changes
|
|
28
|
+
|
|
29
|
+
First, you'll want to set up a local copy of Coconut's recommended development environment. For that, just run `git checkout develop`, make sure your default `python` installation is some variant of Python 3, and run `make dev`. That should switch you to the `develop` branch, install all possible dependencies, bind the `coconut` command to your local copy, and set up [pre-commit](http://pre-commit.com/), which will check your code for errors for you whenever you `git commit`.
|
|
30
|
+
|
|
31
|
+
Then, you should be able to use the Coconut command-line for trying out simple things, and to run a paired-down version of the test suite locally, just `make test-univ`.
|
|
32
|
+
|
|
33
|
+
After you've tested your changes locally, you'll want to add more permanent tests to Coconut's test suite. Coconut's test suite is primarily written in Coconut itself, so testing new features just means using them inside of one of Coconut's `.coco` test files, with some `assert` statements to check validity.
|
|
34
|
+
|
|
35
|
+
## File Layout
|
|
36
|
+
|
|
37
|
+
- `DOCS.md`
|
|
38
|
+
+ Markdown file containing detailed documentation on every Coconut feature. If you are adding a new feature, you should also add documentation on it to this file.
|
|
39
|
+
- `FAQ.md`
|
|
40
|
+
+ Markdown file containing frequently asked questions and their answers. If you had a question you wished was answered earlier when learning Coconut, you should add it to this file.
|
|
41
|
+
- `HELP.md`
|
|
42
|
+
+ Markdown file containing Coconut's tutorial. The tutorial should be a streamlined introduction to Coconut and all of its most important features.
|
|
43
|
+
- `Makefile`
|
|
44
|
+
+ Contains targets for installing Coconut, building the documentation, checking for dependency updates, etc.
|
|
45
|
+
- `setup.py`
|
|
46
|
+
+ Using information from `requirements.py` and `constants.py` to install Coconut. Also reads `README.rst` to generate the PyPI description.
|
|
47
|
+
- `conf.py`
|
|
48
|
+
+ Sphinx configuration file for Coconut's documentation.
|
|
49
|
+
- coconut
|
|
50
|
+
- `__coconut__.py`
|
|
51
|
+
+ Mimics the Coconut header by generating and executing it when imported. Used by the REPL.
|
|
52
|
+
- `__init__.py`
|
|
53
|
+
+ Includes the implementation of the `%coconut` IPython magic.
|
|
54
|
+
- `__main__.py`
|
|
55
|
+
+ Imports and runs `main` from `main.py`.
|
|
56
|
+
- `constants.py`
|
|
57
|
+
+ All constants used across Coconut are defined here, including dependencies, magic numbers/strings, etc.
|
|
58
|
+
- `convenience.py`
|
|
59
|
+
+ Contains `cmd`, `version`, `setup`, and `parse` functions as convenience utilities when using Coconut as a module. Documented in `DOCS.md`.
|
|
60
|
+
- `exceptions.py`
|
|
61
|
+
+ All of the exceptions raised by Coconut are defined here, both those shown to the user and those used only internally.
|
|
62
|
+
- `highlighter.py`
|
|
63
|
+
+ Contains Coconut's Pygments syntax highlighter, as well as modified Python highlighters that don't fail if they encounter unknown syntax.
|
|
64
|
+
- `main.py`
|
|
65
|
+
+ Contains `main` and `main_run`, the entry points for the `coconut` and `coconut-run` commands, respectively.
|
|
66
|
+
- `requirements.py`
|
|
67
|
+
+ Processes Coconut's requirements from `constants.py` into a form `setup.py` can use, as well as checks for updates to Coconut's dependencies.
|
|
68
|
+
- `root.py`
|
|
69
|
+
+ `root.py` creates and executes the part of Coconut's header that normalizes Python built-ins across versions. Whenever you are writing a new file, you should always add `from coconut.root import *` to ensure compatibility with different Python versions. `root.py` also sets basic version-related constants.
|
|
70
|
+
- `terminal.py`
|
|
71
|
+
+ Contains utilities for displaying messages to the console, mainly `logger`, which is Coconut's primary method of logging a message from anywhere.
|
|
72
|
+
- command
|
|
73
|
+
- `__init__.py`
|
|
74
|
+
+ Imports everything in `command.py`.
|
|
75
|
+
- `cli.py`
|
|
76
|
+
+ Creates the `ArgumentParser` object used to parse Coconut command-line arguments.
|
|
77
|
+
- `command.py`
|
|
78
|
+
+ Contains `Command`, whose `start` method is the main entry point for the Coconut command-line utility.
|
|
79
|
+
- `mypy.py`
|
|
80
|
+
+ Contains objects necessary for Coconut's `--mypy` flag.
|
|
81
|
+
- `util.py`
|
|
82
|
+
+ Contains utilities used by `command.py`, including `Prompt` for getting syntax-highlighted input, and `Runner` for executing compiled Python.
|
|
83
|
+
- `watch.py`
|
|
84
|
+
+ Contains objects necessary for Coconut's `--watch` flag.
|
|
85
|
+
- compiler
|
|
86
|
+
- `__init__.py`
|
|
87
|
+
+ Imports everything in `compiler.py`.
|
|
88
|
+
- `compiler.py`
|
|
89
|
+
+ Contains `Compiler`, the class that actually compiles Coconut code. `Compiler` inherits from `Grammar` in `grammar.py` to get all of the basic grammatical definitions, then extends them with all of the handlers that depend on the compiler's options (e.g. the current `--target`). `Compiler` also does pre- and post-processing, including replacing strings with markers (pre-processing) and adding the header (post-processing).
|
|
90
|
+
- `grammar.py`
|
|
91
|
+
+ Contains `Grammar`, the class that specifies Coconut's grammar in PyParsing. Coconut performs one-pass compilation by attaching "handlers" to specific grammar objects to transform them into compiled Python. `grammar.py` contains all basic (non-option-dependent) handlers.
|
|
92
|
+
- `header.py`
|
|
93
|
+
+ Contains `getheader`, which generates the header at the top of all compiled Coconut files.
|
|
94
|
+
- `matching.py`
|
|
95
|
+
+ Contains `Matcher`, which handles the compilation of all Coconut pattern-matching, including `match` statements, destructuring assignment, and pattern-matching functions.
|
|
96
|
+
- `util.py`
|
|
97
|
+
+ Contains utilities for working with PyParsing objects that are primarily used by `grammar.py`.
|
|
98
|
+
- templates
|
|
99
|
+
- `header.py_template`
|
|
100
|
+
+ Template for the main body of Coconut's header; use and formatting of this file is all in `header.py`.
|
|
101
|
+
- icoconut
|
|
102
|
+
- `__init__.py`
|
|
103
|
+
+ Imports everything from `icoconut/root.py`.
|
|
104
|
+
- `__main__.py`
|
|
105
|
+
+ Contains the main entry point for Coconut's Jupyter kernel.
|
|
106
|
+
- `root.py`
|
|
107
|
+
+ Contains the implementation of Coconut's Jupyter kernel, made by subclassing the IPython kernel.
|
|
108
|
+
- tests
|
|
109
|
+
- `__init__.py`
|
|
110
|
+
+ Imports everything in `main_test.py`.
|
|
111
|
+
- `__main__.py`
|
|
112
|
+
+ When run, compiles all of the test source code, but _does not run any tests_. To run the tests, the command `make test`, or a `pytest` command to run a specific test, is necessary.
|
|
113
|
+
- `main_test.py`
|
|
114
|
+
+ Contains `TestCase` subclasses that run all of the commands for testing the Coconut files in `src`.
|
|
115
|
+
- src
|
|
116
|
+
- `extras.coco`
|
|
117
|
+
+ Directly imports and calls functions in the Coconut package, including from `convenience.py` and icoconut.
|
|
118
|
+
- `runnable.coco`
|
|
119
|
+
+ Makes sure the argument `--arg` was passed when running the file.
|
|
120
|
+
- `runner.coco`
|
|
121
|
+
+ Runs `main` from `cocotest/agnostic/main.py`.
|
|
122
|
+
- cocotest
|
|
123
|
+
+ _Note: Files in the folders below all get compiled into the top-level cocotest directory. The folders are only for differentiating what files to compile on what Python version._
|
|
124
|
+
- agnostic
|
|
125
|
+
- `__init__.coco`
|
|
126
|
+
+ Contains a docstring that `main.coco` asserts exists.
|
|
127
|
+
- `main.coco`
|
|
128
|
+
+ Contains the main test entry point as well as many simple, one-line tests.
|
|
129
|
+
- `specific.coco`
|
|
130
|
+
+ Tests to be run only on a specific Python version, but not necessarily only under a specific `--target`.
|
|
131
|
+
- `suite.coco`
|
|
132
|
+
+ Tests objects defined in `util.coco`.
|
|
133
|
+
- `tutorial.coco`
|
|
134
|
+
+ Tests all the examples in `TUTORIAL.md`.
|
|
135
|
+
- `util.coco`
|
|
136
|
+
+ Contains objects used in `suite.coco`.
|
|
137
|
+
- python2
|
|
138
|
+
- `py2_test.coco`
|
|
139
|
+
+ Tests to be run only on Python 2 with `--target 2`.
|
|
140
|
+
- python3
|
|
141
|
+
- `py3_test.coco`
|
|
142
|
+
+ Tests to be run only on Python 3 with `--target 3`.
|
|
143
|
+
- python35
|
|
144
|
+
- `py35_test.coco`
|
|
145
|
+
+ Tests to be run only on Python 3.5 with `--target 3.5`.
|
|
146
|
+
- python36
|
|
147
|
+
- `py36_test.coco`
|
|
148
|
+
+ Tests to be run only on Python 3.6 with `--target 3.6`.
|
|
149
|
+
- coconut-stubs
|
|
150
|
+
- `__coconut__.pyi`
|
|
151
|
+
+ A MyPy stub file for specifying the type of all the objects defined in Coconut's package header (which is saved as `__coconut__.py`).
|
|
152
|
+
|
|
153
|
+
## Release Process
|
|
154
|
+
|
|
155
|
+
1. Preparation:
|
|
156
|
+
1. Run `make check-reqs` and update dependencies as necessary
|
|
157
|
+
2. Run `sudo make format`
|
|
158
|
+
3. Run manual tests:
|
|
159
|
+
1. Temporarily set `test_computation_graph_pickling = True` in `constants.py` and run `make test`
|
|
160
|
+
2. Run `make docs` and ensure local documentation looks good
|
|
161
|
+
3. Ensure that `coconut --watch` can successfully compile files when they're modified
|
|
162
|
+
4. Make sure `make test-pyright` and `make test-easter-eggs` are passing
|
|
163
|
+
4. Check all the tooling:
|
|
164
|
+
1. Make sure [`coconut-develop`](https://pypi.python.org/pypi/coconut-develop) package looks good
|
|
165
|
+
2. Check changes in [`compiled-cocotest`](https://github.com/evhub/compiled-cocotest), [`pyprover`](https://github.com/evhub/pyprover), and [`coconut-prelude`](https://github.com/evhub/coconut-prelude)
|
|
166
|
+
3. Check [Codebeat](https://codebeat.co/a/evhub/projects) and [LGTM](https://lgtm.com/dashboard) for `coconut` and `compiled-cocotest`
|
|
167
|
+
5. Make sure all of the following are passing:
|
|
168
|
+
1. [Github Actions](https://github.com/evhub/coconut/actions)
|
|
169
|
+
2. [AppVeyor](https://ci.appveyor.com/project/evhub/coconut)
|
|
170
|
+
3. [readthedocs](https://readthedocs.org/projects/coconut/builds/)
|
|
171
|
+
6. Make sure [develop documentation](http://coconut.readthedocs.io/en/develop/) looks good
|
|
172
|
+
7. Turn off `develop` in `root.py`
|
|
173
|
+
8. Set `root.py` to new version number
|
|
174
|
+
9. If major release, set `root.py` to new version name
|
|
175
|
+
|
|
176
|
+
2. Pull Request:
|
|
177
|
+
1. Move unresolved issues to new milestone
|
|
178
|
+
2. Create a pull request to merge `develop` into `master`
|
|
179
|
+
3. Link contributors on pull request
|
|
180
|
+
4. Wait until everything is passing
|
|
181
|
+
|
|
182
|
+
3. Release:
|
|
183
|
+
1. Release a new version of [`sublime-coconut`](https://github.com/evhub/sublime-coconut) if applicable
|
|
184
|
+
1. Edit the [`package.json`](https://github.com/evhub/sublime-coconut/blob/master/package.json) with the new version
|
|
185
|
+
2. Run `make publish`
|
|
186
|
+
3. [Release a new version on GitHub](https://github.com/evhub/sublime-coconut/releases)
|
|
187
|
+
2. Merge pull request and mark as resolved
|
|
188
|
+
3. Release `master` on GitHub
|
|
189
|
+
4. `git fetch`, `git checkout master`, and `git pull`
|
|
190
|
+
5. Run `sudo make upload`
|
|
191
|
+
6. `git checkout develop`, `git rebase master`, and `git push`
|
|
192
|
+
7. Turn on `develop` in `root`
|
|
193
|
+
8. Run `sudo make dev`
|
|
194
|
+
9. Push to `develop`
|
|
195
|
+
10. Wipe all updated versions on [readthedocs](https://readthedocs.org/projects/coconut/versions/)
|
|
196
|
+
11. Build all updated versions on [readthedocs](https://readthedocs.org/projects/coconut/builds/)
|
|
197
|
+
12. Copy [PyPI](https://pypi.python.org/pypi/coconut) keywords to [readthedocs tags](https://readthedocs.org/dashboard/coconut/edit/)
|
|
198
|
+
13. Get SHA-256 hash from [PyPI](https://pypi.python.org/pypi/coconut) `.tar.gz` file and use that as well as the current version requirements in [`constants.py`](https://github.com/evhub/coconut/blob/master/coconut/constants.py) to update the [local feedstock](https://github.com/evhub/coconut-feedstock)
|
|
199
|
+
14. Submit PR to update [Coconut's `conda-forge` feedstock](https://github.com/conda-forge/coconut-feedstock)
|
|
200
|
+
15. Update [website](https://github.com/evhub/coconut/tree/gh-pages) if it needs updating
|
|
201
|
+
16. Wait until feedstock PR is passing then merge it
|
|
202
|
+
17. Close release [milestone](https://github.com/evhub/coconut/milestones?direction=asc&sort=due_date)
|