coconut 3.1.2__tar.gz → 3.3.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.
Files changed (130) hide show
  1. coconut-3.3.0/.claude/CLAUDE.md +91 -0
  2. coconut-3.3.0/.claude/settings.local.json +33 -0
  3. coconut-3.3.0/.claude-plugin/marketplace.json +23 -0
  4. coconut-3.3.0/CONTRIBUTING.md +323 -0
  5. {coconut-3.1.2 → coconut-3.3.0}/DOCS.md +5663 -4917
  6. {coconut-3.1.2 → coconut-3.3.0}/FAQ.md +97 -97
  7. {coconut-3.1.2 → coconut-3.3.0}/HELP.md +1457 -1168
  8. {coconut-3.1.2 → coconut-3.3.0}/PKG-INFO +195 -163
  9. {coconut-3.1.2 → coconut-3.3.0}/README.rst +84 -82
  10. coconut-3.3.0/__coconut__/__init__.pyi +2885 -0
  11. {coconut-3.1.2 → coconut-3.3.0}/_coconut/__init__.pyi +223 -180
  12. {coconut-3.1.2 → coconut-3.3.0}/coconut/__coconut__.pyi +2 -2
  13. {coconut-3.1.2 → coconut-3.3.0}/coconut/_pyparsing.py +555 -552
  14. {coconut-3.1.2 → coconut-3.3.0}/coconut/api.py +417 -394
  15. {coconut-3.1.2 → coconut-3.3.0}/coconut/api.pyi +176 -162
  16. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/cli.py +362 -313
  17. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/command.py +1507 -1238
  18. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/mypy.py +77 -76
  19. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/util.py +1022 -927
  20. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/compiler.py +7607 -5253
  21. coconut-3.3.0/coconut/compiler/exhaustiveness.py +327 -0
  22. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/grammar.py +3331 -2922
  23. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/header.py +1105 -1065
  24. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/matching.py +1722 -1513
  25. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/templates/header.py_template +2954 -2241
  26. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/util.py +2694 -2281
  27. {coconut-3.1.2 → coconut-3.3.0}/coconut/constants.py +1516 -1364
  28. {coconut-3.1.2 → coconut-3.3.0}/coconut/exceptions.py +351 -312
  29. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/root.py +391 -355
  30. coconut-3.3.0/coconut/llms.txt +431 -0
  31. coconut-3.3.0/coconut/lsp/__init__.py +17 -0
  32. coconut-3.3.0/coconut/lsp/__main__.py +31 -0
  33. coconut-3.3.0/coconut/lsp/cli.py +398 -0
  34. coconut-3.3.0/coconut/lsp/compiler.py +441 -0
  35. coconut-3.3.0/coconut/lsp/data/docs.json +781 -0
  36. coconut-3.3.0/coconut/lsp/docs.py +162 -0
  37. coconut-3.3.0/coconut/lsp/generate_docs.py +224 -0
  38. coconut-3.3.0/coconut/lsp/intel.py +797 -0
  39. coconut-3.3.0/coconut/lsp/mcp.py +346 -0
  40. coconut-3.3.0/coconut/lsp/overlay.py +274 -0
  41. coconut-3.3.0/coconut/lsp/protocol.py +152 -0
  42. coconut-3.3.0/coconut/lsp/server.py +883 -0
  43. coconut-3.3.0/coconut/lsp/sourcemap.py +246 -0
  44. coconut-3.3.0/coconut/lsp/symbols.py +310 -0
  45. coconut-3.3.0/coconut/lsp/typecheck.py +164 -0
  46. coconut-3.3.0/coconut/lsp/uris.py +59 -0
  47. coconut-3.3.0/coconut/lsp/worker.py +217 -0
  48. coconut-3.3.0/coconut/project_config.py +195 -0
  49. coconut-3.3.0/coconut/pytest_plugin.py +159 -0
  50. {coconut-3.1.2 → coconut-3.3.0}/coconut/requirements.py +433 -372
  51. {coconut-3.1.2 → coconut-3.3.0}/coconut/root.py +523 -478
  52. {coconut-3.1.2 → coconut-3.3.0}/coconut/terminal.py +716 -674
  53. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/constants_test.py +149 -145
  54. coconut-3.3.0/coconut/tests/header_test.py +102 -0
  55. coconut-3.3.0/coconut/tests/lsp_test.py +888 -0
  56. coconut-3.3.0/coconut/tests/main_test.py +2285 -0
  57. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/main.coco +156 -134
  58. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/primary_1.coco +1440 -1306
  59. coconut-3.3.0/coconut/tests/src/cocotest/agnostic/primary_2.coco +1262 -0
  60. coconut-3.3.0/coconut/tests/src/cocotest/agnostic/shadowed_builtins_test.coco +258 -0
  61. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/specific.coco +310 -203
  62. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/suite.coco +1297 -1113
  63. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/tutorial.coco +521 -518
  64. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/util.coco +2370 -2136
  65. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/non_strict/non_strict_test.coco +121 -121
  66. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/target_2/py2_test.coco +8 -8
  67. coconut-3.3.0/coconut/tests/src/cocotest/target_311/py311_test.coco +30 -0
  68. coconut-3.3.0/coconut/tests/src/cocotest/target_314/py314_test.coco +58 -0
  69. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/target_36/py36_test.coco +89 -80
  70. coconut-3.3.0/coconut/tests/src/cocotest/target_38/py38_test.coco +37 -0
  71. coconut-3.3.0/coconut/tests/src/cocotest/target_sys/builtins_typing_test.coco +779 -0
  72. coconut-3.3.0/coconut/tests/src/cocotest/target_sys/lazy_annotations_test.coco +182 -0
  73. coconut-3.3.0/coconut/tests/src/extras.coco +1513 -0
  74. {coconut-3.1.2 → coconut-3.3.0}/coconut/util.py +536 -468
  75. {coconut-3.1.2 → coconut-3.3.0}/coconut.egg-info/SOURCES.txt +34 -0
  76. {coconut-3.1.2 → coconut-3.3.0}/conf.py +92 -85
  77. coconut-3.3.0/editors/claude-code/.claude-plugin/plugin.json +25 -0
  78. coconut-3.3.0/editors/claude-code/.lsp.json +15 -0
  79. coconut-3.3.0/editors/claude-code/skills/coconut/SKILL.md +17 -0
  80. coconut-3.3.0/interactive_tutorial.py +452 -0
  81. coconut-3.1.2/CONTRIBUTING.md +0 -199
  82. coconut-3.1.2/__coconut__/__init__.pyi +0 -2065
  83. coconut-3.1.2/coconut/tests/main_test.py +0 -1125
  84. coconut-3.1.2/coconut/tests/src/cocotest/agnostic/primary_2.coco +0 -503
  85. coconut-3.1.2/coconut/tests/src/cocotest/target_311/py311_test.coco +0 -12
  86. coconut-3.1.2/coconut/tests/src/cocotest/target_38/py38_test.coco +0 -15
  87. coconut-3.1.2/coconut/tests/src/extras.coco +0 -794
  88. {coconut-3.1.2 → coconut-3.3.0}/LICENSE.txt +0 -0
  89. {coconut-3.1.2 → coconut-3.3.0}/MANIFEST.in +0 -0
  90. {coconut-3.1.2 → coconut-3.3.0}/__coconut__/__init__.py +0 -0
  91. {coconut-3.1.2 → coconut-3.3.0}/__coconut__/py.typed +0 -0
  92. {coconut-3.1.2 → coconut-3.3.0}/_coconut/__init__.py +0 -0
  93. {coconut-3.1.2 → coconut-3.3.0}/_coconut/py.typed +0 -0
  94. {coconut-3.1.2 → coconut-3.3.0}/coconut/__coconut__.py +0 -0
  95. {coconut-3.1.2 → coconut-3.3.0}/coconut/__init__.py +0 -0
  96. {coconut-3.1.2 → coconut-3.3.0}/coconut/__init__.pyi +0 -0
  97. {coconut-3.1.2 → coconut-3.3.0}/coconut/__main__.py +0 -0
  98. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/__init__.py +0 -0
  99. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/__init__.pyi +0 -0
  100. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/command.pyi +0 -0
  101. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/resources/zcoconut.pth +0 -0
  102. {coconut-3.1.2 → coconut-3.3.0}/coconut/command/watch.py +0 -0
  103. {coconut-3.1.2 → coconut-3.3.0}/coconut/compiler/__init__.py +0 -0
  104. {coconut-3.1.2 → coconut-3.3.0}/coconut/convenience.py +0 -0
  105. {coconut-3.1.2 → coconut-3.3.0}/coconut/convenience.pyi +0 -0
  106. {coconut-3.1.2 → coconut-3.3.0}/coconut/highlighter.py +0 -0
  107. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/__init__.py +0 -0
  108. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/__main__.py +0 -0
  109. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/coconut/kernel.json +0 -0
  110. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/coconut_py/kernel.json +0 -0
  111. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/coconut_py2/kernel.json +0 -0
  112. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/coconut_py3/kernel.json +0 -0
  113. {coconut-3.1.2 → coconut-3.3.0}/coconut/icoconut/embed.py +0 -0
  114. {coconut-3.1.2 → coconut-3.3.0}/coconut/integrations.py +0 -0
  115. {coconut-3.1.2 → coconut-3.3.0}/coconut/main.py +0 -0
  116. {coconut-3.1.2 → coconut-3.3.0}/coconut/py.typed +0 -0
  117. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/__init__.py +0 -0
  118. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/__main__.py +0 -0
  119. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/__init__.coco +0 -0
  120. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/agnostic/__main__.coco +0 -0
  121. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/target_3/py3_test.coco +0 -0
  122. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/target_35/py35_test.coco +0 -0
  123. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/cocotest/target_sys/target_sys_test.coco +0 -0
  124. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/importable.coco +0 -0
  125. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/runnable.coco +0 -0
  126. {coconut-3.1.2 → coconut-3.3.0}/coconut/tests/src/runner.coco +0 -0
  127. {coconut-3.1.2 → coconut-3.3.0}/pyproject.toml +0 -0
  128. {coconut-3.1.2 → coconut-3.3.0}/setup.cfg +0 -0
  129. {coconut-3.1.2 → coconut-3.3.0}/setup.py +0 -0
  130. {coconut-3.1.2 → coconut-3.3.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,33 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "WebSearch",
5
+ "Bash(cat:*)",
6
+ "Bash(cd:*)",
7
+ "Bash(ls:*)",
8
+ "Bash(echo:*)",
9
+ "Bash(grep:*)",
10
+ "Bash(find:*)",
11
+ "Bash(findstr:*)",
12
+ "Bash(python:*)",
13
+ "Bash(python3:*)",
14
+ "Bash(gh:*)",
15
+ "Bash(pip:*)",
16
+ "Bash(conda:*)",
17
+ "Bash(log \")",
18
+ "Bash(test:*)",
19
+ "Bash(done)",
20
+ "WebFetch(domain:github.com)",
21
+ "WebFetch(domain:raw.githubusercontent.com)",
22
+ "WebFetch(domain:gist.github.com)",
23
+ "WebFetch(domain:coconut.readthedocs.io)",
24
+ "WebFetch(domain:peps.python.org)",
25
+ "WebFetch(domain:pypi.org)",
26
+ "WebFetch(domain:discuss.python.org)",
27
+ "WebFetch(domain:doc.pypy.org)",
28
+ "Bash(git status:*)",
29
+ "Bash(make test-tests:*)",
30
+ "Bash(xonsh:*)"
31
+ ]
32
+ }
33
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "description": "Coconut language support for Claude Code: the Coconut language server (errors after every edit, code navigation), MCP tools for checking and compiling Coconut and looking up its documentation, and a skill pointing Claude to Coconut's AI guide.",
3
+ "name": "coconut",
4
+ "owner": {
5
+ "name": "evhub",
6
+ "url": "https://github.com/evhub"
7
+ },
8
+ "plugins": [
9
+ {
10
+ "category": "development",
11
+ "description": "Coconut language server, MCP tools (check, compile, docs, hover, definitions, references, symbols), and a skill for writing idiomatic Coconut. Requires coconut[lsp].",
12
+ "name": "coconut",
13
+ "source": "./editors/claude-code",
14
+ "tags": [
15
+ "coconut",
16
+ "python",
17
+ "functional",
18
+ "lsp",
19
+ "language-server"
20
+ ]
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,323 @@
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!** This document explains the contribution process, how Coconut works internally, how to test changes, and how releases are made.
6
+
7
+ Contributions are made against the [`develop` branch](https://github.com/evhub/coconut/tree/develop), so make sure you're reading [the `develop` version of these guidelines](https://coconut.readthedocs.io/en/develop/CONTRIBUTING.html).
8
+
9
+ ## Getting Started
10
+
11
+ ### Asking Questions
12
+
13
+ The best place to ask a question, including about contributing, understanding the source code, or figuring out how to implement something, is to [open a GitHub issue](https://github.com/evhub/coconut/issues/new). Questions are always welcome there. (Coconut's old Gitter chat room is no longer used.)
14
+
15
+ ### Good First Issues
16
+
17
+ Want to help out but don't know what to work on? Look through the [issues labeled "good first issue"](https://github.com/evhub/coconut/labels/good%20first%20issue). They need less knowledge of Coconut's internals, so new contributors can take them on.
18
+
19
+ ### Contribution Process
20
+
21
+ 1. Fork Coconut on [GitHub](https://github.com/evhub/coconut) and make a branch off of `develop`.
22
+ 2. Make your changes, including tests (see [Testing](#testing)) and, for any user-facing change, documentation in [`DOCS.md`](./DOCS.md).
23
+ 3. Open a pull request against `develop`.
24
+
25
+ _Note: Don't forget to add yourself to the `Author:`/`Authors:` line in the module docstring of any file you modify!_
26
+
27
+ ### Using AI Coding Assistants
28
+
29
+ If you use an AI coding assistant, these resources help it work on Coconut:
30
+
31
+ - [`.claude/CLAUDE.md`](https://github.com/evhub/coconut/blob/develop/.claude/CLAUDE.md) has project instructions (commands, architecture, conventions) that Claude Code loads automatically. Point other assistants at it.
32
+ - `coconut --ai-docs` prints Coconut's condensed guide to writing idiomatic Coconut ([`coconut/llms.txt`](https://github.com/evhub/coconut/blob/develop/coconut/llms.txt), also served at [coconut.readthedocs.io/en/latest/llms.txt](https://coconut.readthedocs.io/en/latest/llms.txt)). It's useful when writing `.coco` tests. `test_ai_docs` runs its code examples, so keep them working when you change syntax.
33
+ - This repository is also a Claude Code plugin marketplace (`.claude-plugin/`, `editors/claude-code/`) that gives Claude the Coconut language server and MCP tools; see [AI Coding Assistant Support](./DOCS.md#ai-coding-assistant-support).
34
+ - On GitHub, `.github/workflows/claude.yml` runs Claude Code when `@claude` is mentioned in an issue or PR comment, and `.github/workflows/claude-code-review.yml` posts an automated Claude code review on pull requests.
35
+
36
+ ## Development Setup
37
+
38
+ Use a Python 3 virtual environment (`.venv` is gitignored), then run `make dev`:
39
+
40
+ ```bash
41
+ git clone https://github.com/<your-username>/coconut.git
42
+ cd coconut
43
+ git checkout develop
44
+ python -m venv .venv && . .venv/bin/activate
45
+ make dev
46
+ ```
47
+
48
+ `make dev` does the following:
49
+
50
+ 1. `make clean`: deletes build and docs output, `coconut/tests/dest`, and all `__coconut_cache__` directories.
51
+ 2. `make setup`: runs `ensurepip` and upgrades `setuptools`, `wheel`, `pip`, and `cython`.
52
+ 3. `pip install --upgrade -e .[dev]`: an editable install of `coconut-develop` with every optional dependency (Jupyter, MyPy, Pyright, the language server, xonsh, numpy/pandas/xarray, watchdog, Sphinx, pytest, ...), plus pure-Python `pyparsing` and the dev tools `pre-commit`, `requests`, `vprof`, and `py-spy`. If a release `coconut` is installed in the same environment, `pip uninstall coconut` first.
53
+ 4. `pre-commit install -f --install-hooks`: runs autopep8, flake8, and the [pre-commit](https://pre-commit.com/) hooks in `.pre-commit-config.yaml` on every `git commit`.
54
+ 5. `coconut --site-install`: adds `zcoconut.pth` to `site-packages` so that `coconut.api` is imported at startup, which makes `.coco` files importable. Undo it with `coconut --site-uninstall`.
55
+
56
+ Other setup targets:
57
+
58
+ - `make install`: `pip install -e .[tests]`, which installs only the dependencies the test suite needs on the current Python. This is what CI runs. `install-py2`, `install-py3`, `install-pypy`, and `install-pypy3` do the same with `python2`, `python3`, `pypy`, and `pypy3`. `make install-purepy` installs with `--no-deps` plus `pyparsing<3`.
59
+ - `make dev-py2` and `make dev-py3` are `make dev` for `python2` and `python3`.
60
+ - `make format`: runs `make dev`, then `pre-commit autoupdate` and every hook on every file.
61
+ - `make docs`: builds the documentation into `docs/` with Sphinx and MyST (needs the `docs` extra, which `.[dev]` includes).
62
+ - `make check-reqs`: checks PyPI for newer versions of Coconut's dependencies.
63
+ - `make clean` removes test and build output. `make wipe` also removes `*.egg-info`, `__pycache__`, and `.pyc` files, runs `--site-uninstall`, and `pip uninstall`s `coconut` and `coconut-develop` (it asks for confirmation).
64
+ - Profiling: `make profile`, `make pyspy` (plus `pyspy-purepy`, `pyspy-native`, `pyspy-runtime`), `make vprof-time`, and `make vprof-memory`.
65
+
66
+ Once you're set up, `python -m coconut -c "<code>"` compiles and runs a snippet, and `coconut` gives you the interpreter.
67
+
68
+ ## Architecture
69
+
70
+ ### Compilation Pipeline
71
+
72
+ Compilation happens in `Compiler.parse` in `coconut/compiler/compiler.py`:
73
+
74
+ 1. **Pre-processing** (`Compiler.preprocs`): `str_proc` replaces every string and comment with a marker that refers to its stored contents, so the grammar never sees what's inside them. `passthrough_proc` does the same for `\(...)` code passthroughs, `operator_proc` handles custom `operator` declarations, and `ind_proc` turns indentation into explicit open/close indentation marker characters.
75
+ 2. **Parsing**: a single pass of the PyParsing grammar in `coconut/compiler/grammar.py`. Handlers that transform Coconut into Python are attached to grammar elements with `attach` from `coconut/compiler/util.py`. Handlers that depend on compiler options such as `--target` are bound in `Compiler.bind`. A handler doesn't run as soon as its element matches: it creates a node in a **computation graph**, and the graph is only evaluated once the parse is certain (`final`/`evaluate_tokens`). That way backtracking doesn't repeat handler work, and parse results can be cached. Parsing uses [cPyparsing](https://github.com/evhub/cpyparsing) when it's available, or pure-Python `pyparsing` otherwise (`coconut/_pyparsing.py`). On CPython 3.8+ with cPyparsing, parse results are also saved to `__coconut_cache__/*.pkl` next to the source file, so recompiling a slightly changed file is faster.
76
+ 3. **Post-processing** (`Compiler.postprocs`): inserts deferred code, puts back passthroughs, indentation, strings, and comments, adds the line-number comments that point back to the Coconut source, prepends the header (`coconut/compiler/header.py`, which fills in `templates/header.py_template`), and polishes the result. `run_final_checks` then reports any remaining errors and warnings.
77
+
78
+ ### File Layout
79
+
80
+ Top level:
81
+
82
+ - `DOCS.md`: documentation for every Coconut feature. Document new features here.
83
+ - `HELP.md`: the tutorial. `test_tutorial` checks its examples.
84
+ - `FAQ.md`: frequently asked questions. If you had a question you wish had been answered earlier when learning Coconut, add it here.
85
+ - `README.rst`: the PyPI description. `conf.py` also turns it into the documentation's `index.rst`.
86
+ - `Makefile`: targets for setup, testing, docs, releases, and profiling.
87
+ - `setup.py`, `setup.cfg`, `pyproject.toml`, `MANIFEST.in`: packaging. Requirements are defined in `coconut/constants.py`.
88
+ - `conf.py`, `.readthedocs.yaml`: the Sphinx/MyST configuration for [readthedocs](https://coconut.readthedocs.io). The docs also serve `coconut/llms.txt` and an interactive version of the tutorial.
89
+ - `interactive_tutorial.py`: generates the interactive tutorial, which runs every example in the browser with Pyodide.
90
+ - `.gitattributes`: tells git and GitHub to treat `.coco` and `.py_template` files as Python (`diff=python`, `linguist-language=python`). If you add a new file extension containing Python-like code, add the same rules for it here.
91
+ - `__coconut__/`, `_coconut/`: type stubs for the compiled header. `__coconut__/__init__.pyi` must match every built-in the header defines. `--mypy` and `--pyright` link these directories, along with the `coconut` package, into `$COCONUT_HOME/.coconut_stubs`.
92
+ - `xontrib/coconut.py`: the xonsh xontrib.
93
+ - `editors/claude-code/`, `.claude-plugin/marketplace.json`: the Claude Code plugin.
94
+ - `.claude/CLAUDE.md`: instructions for AI coding assistants.
95
+ - `.github/workflows/`, `.appveyor.yml`: CI (see [What CI Covers](#what-ci-covers)).
96
+
97
+ `coconut/`:
98
+
99
+ - `root.py`: version constants (`VERSION`, `VERSION_NAME`, `DEVELOP`, `ALPHA`) and the header code that makes Python 2 and 3 built-ins behave alike. Every module starts with `from coconut.root import *`.
100
+ - `constants.py`: every global constant, including platform flags (`PY39`, `PYPY`, `WINDOWS`, `MYPY`, ...), dependencies and version bounds, supported targets, built-in lists, and environment variables.
101
+ - `requirements.py`: turns the requirements in `constants.py` into `setup.py` requirements and extras, and implements `make check-reqs`.
102
+ - `api.py`: the external API (`cmd`, `parse`, `setup`, `auto_compilation`, the import hook, ...). `convenience.py` is a deprecated alias for it.
103
+ - `main.py`: the entry points for `coconut` and `coconut-run`.
104
+ - `__init__.py` and `integrations.py`: `embed`, the `%coconut` IPython extension, and the xonsh integration.
105
+ - `__coconut__.py`: does what a compiled `__coconut__.py` header module would do (used by the interpreter).
106
+ - `_pyparsing.py`: chooses between cPyparsing and pyparsing and sets up packrat/incremental parsing and the computation graph (which is always on with the supported versions of cPyparsing and pyparsing; `COCONUT_USE_COMPUTATION_GRAPH=FALSE` turns it off for debugging, but isn't supported, and some features don't work without it).
107
+ - `exceptions.py`, `terminal.py` (`logger`, used for all console output), `util.py`, and `highlighter.py` (Pygments lexers).
108
+ - `project_config.py`: the `[tool.coconut]` table in `pyproject.toml`.
109
+ - `pytest_plugin.py`: the opt-in `pytest -p coconut.pytest_plugin` plugin.
110
+ - `llms.txt`: the AI guide that `coconut --ai-docs` prints.
111
+ - `command/`: the command-line tool. `command.py` holds `Command`, whose `start` method is the CLI entry point. `cli.py` defines the arguments. `util.py` has `Prompt`, `Runner`, stub installation, and subprocess helpers. `mypy.py` and `watch.py` implement `--mypy` and `--watch`, and `resources/zcoconut.pth` is used by `--site-install`.
112
+ - `compiler/`: `compiler.py` (`Compiler`, which inherits the grammar from `Grammar` in `grammar.py`), `matching.py` (`Matcher`, which compiles all pattern matching), `exhaustiveness.py` (exhaustiveness checks of pattern matching that only type checkers see), `header.py` and `templates/header.py_template` (the header), and `util.py` (PyParsing utilities and the computation graph).
113
+ - `icoconut/`: the Jupyter kernel (`root.py`, `embed.py`, `__main__.py`, and the kernel specs).
114
+ - `lsp/`: the language server (`coconut --lsp`), its command line (`python -m coconut.lsp`), and the MCP server (`coconut --mcp`). The hover documentation in `data/docs.json` is generated from `DOCS.md` by `python -m coconut.lsp.generate_docs`, and `lsp_test.py` fails if it's out of date.
115
+ - `tests/`: the test suite (see [Testing](#testing)).
116
+
117
+ ## Testing
118
+
119
+ ### Writing Tests
120
+
121
+ Most of Coconut's tests are written in Coconut, as `assert` statements in `.coco` files under `coconut/tests/src/`. `make test` compiles them with `--strict` (except `non_strict/`), so test code has to pass strict mode.
122
+
123
+ - `cocotest/agnostic/` is compiled with whichever target the run uses:
124
+ - `primary_1.coco`, `primary_2.coco`: most simple tests of syntax and built-ins.
125
+ - `util.coco` and `suite.coco`: larger definitions go in `util.coco`, and the tests that use them go in `suite.coco`.
126
+ - `specific.coco`: tests that depend on the Python version running them rather than on `--target`.
127
+ - `tutorial.coco`: examples from the website and the tutorial.
128
+ - `main.coco`: the entry point. `run_main` decides which sub-suites run on which Python version.
129
+ - `cocotest/target_<N>/` (`target_2`, `target_3`, `target_35`, `target_36`, `target_38`, `target_311`, `target_314`) is compiled with `--target <N>` and only run on Python versions that support it. Use these folders for syntax that needs a specific target.
130
+ - `cocotest/target_sys/` is compiled with `--target sys`. `builtins_typing_test.coco` checks that the built-in type stubs are precise, so update it along with `__coconut__/__init__.pyi` when you add or change a built-in.
131
+ - `cocotest/non_strict/` is compiled without `--strict`, for code that strict mode disallows.
132
+ - `extras.coco` uses Coconut's API directly. It holds tests of compile errors and warnings (e.g. `assert_raises(-> parse("..."), CoconutSyntaxError)`), `parse`/`setup`/`cmd`, incremental parsing, the Jupyter kernel, and numpy/pandas/xarray support.
133
+ - `runner.coco` runs the compiled `cocotest` package. `runnable.coco` and `importable.coco` are used for the `coconut-run`, import hook, and `--and` tests.
134
+ - `coconut/tests/main_test.py` holds the Python-level pytest tests. `TestShell` covers command-line behavior and integrations such as MyPy/Pyright output, Jupyter, xonsh, the pytest plugin, and the tutorial. `TestCompilation` compiles and runs the whole suite with different flags. `TestExternal` compiles other projects written in Coconut, and compiles the newest Python's own tests of its syntax as Coconut (`test_cpython`). CLI-level tests go here.
135
+ - `coconut/tests/lsp_test.py` tests the language server, its CLI, and the MCP server. `coconut/tests/constants_test.py` checks `constants.py`.
136
+
137
+ All the folders under `cocotest/` are compiled into a single `coconut/tests/dest/cocotest` package. To add a new `target_<N>` folder, add a `comp_<N>` function to `main_test.py`, call it from both `run()` and `comp_all()`, and import the new tests in `run_main` in `main.coco`.
138
+
139
+ When you change `DOCS.md`, run `python -m coconut.lsp.generate_docs`. When you change syntax, keep the examples in `HELP.md` and `coconut/llms.txt` working, since tests run both.
140
+
141
+ ### Makefile Test Targets
142
+
143
+ Most targets first run `make clean`, then compile the test sources with `python ./coconut/tests <flags>` (which only compiles; see `coconut/tests/__main__.py`), and then run `coconut/tests/dest/runner.py` and `coconut/tests/dest/extras.py`. **These targets never run `main_test.py`, `lsp_test.py`, or `constants_test.py`. Only `make test-all` (pytest) does.** Times are rough: `make test` takes a few minutes on a 4-core Linux machine, and `make test-all` takes 20 to 60 minutes per Python version on CI.
144
+
145
+ | Target | What it does |
146
+ | --- | --- |
147
+ | `make test` | The default while developing. Same as `make test-mypy`: `--target sys`, `--strict --keep-lines --force --no-cache`, and `--mypy`. Use it to test any compiler change. |
148
+ | `make test-tests` | `make test` without `make clean` or `--force`, so only test files that changed are recompiled. Use it only when you've changed nothing but the tests: unchanged test files aren't recompiled with your modified compiler. |
149
+ | `make test-all` | `make clean`, then `pytest --strict-markers -s ./coconut/tests`. Runs all three test files, and is what CI runs. |
150
+ | `make test-univ` | Universal target, no MyPy. `make test-univ-tests` skips `--force`, like `test-tests`. |
151
+ | `make test-mypy-univ` | Universal target with `--mypy`. |
152
+ | `make test-mypy-all` | `make test` plus `--check-untyped-defs`. |
153
+ | `make test-pyright` | `--target sys --pyright`. |
154
+ | `make test-py2`, `test-py3`, `test-pypy`, `test-pypy3` | `make test-univ` with `python2`, `python3 ... --target 3`, `pypy`, or `pypy3`. |
155
+ | `make test-easter-eggs` | `make test-univ` with `runner.py --test-easter-eggs`. |
156
+ | `make test-minify`, `make test-no-wrap` | `make test-univ` with `--minify` or `--no-wrap`. |
157
+ | `make test-purepy` | `make test-univ` with `COCONUT_PURE_PYTHON=TRUE`: pure-Python `pyparsing` instead of cPyparsing. Several times slower. |
158
+ | `make test-any-of` | `make test-univ` with `COCONUT_ADAPTIVE_ANY_OF=TRUE` and `COCONUT_REVERSE_ANY_OF=TRUE`, which reverses the alternatives in every `any_of` grammar element (their order shouldn't matter). |
159
+ | `make test-univ-debug` | `make test-univ` with `COCONUT_TEST_DEBUG_PYTHON=TRUE`, which compiles under `python -X dev`. |
160
+ | `make test-verbose` | `make test-univ` with `--verbose`. Variants: `-cache` (reuses the incremental cache), `-no-cache`, `-sync` (`--jobs 0`), and `test-mypy-verbose`. |
161
+ | `make test-watch` | Compiles, then runs `make just-watch` (`--watch` on `cocotest/agnostic`, which blocks until you press Ctrl-C), then runs the tests. |
162
+ | `make test-mini` | Only compiles `cocotest/agnostic` with `coconut` and runs nothing. The fastest check that the compiler can handle the suite. Variants: `-verbose`, `-cache` (doesn't save to the cache), `-sync` (`--jobs 0 --fail-fast`), `-debug` (`python -X dev`, `--jobs 0`), and `-debug-purepy`. |
163
+ | `make debug-test-crash` | Runs the already-compiled `runner.py` under `python -X dev`. |
164
+
165
+ After any of these, `python coconut/tests/dest/runner.py` reruns the compiled suite without recompiling.
166
+
167
+ ### Running Individual Tests
168
+
169
+ Run pytest tests from the repository root by file and node ID:
170
+
171
+ ```bash
172
+ pytest --strict-markers -s "coconut/tests/main_test.py::TestCompilation::test_no_wrap"
173
+ pytest --strict-markers -s coconut/tests/main_test.py -k mypy
174
+ pytest --strict-markers -s coconut/tests/lsp_test.py
175
+ ```
176
+
177
+ Each `TestCompilation` test compiles and runs the entire suite, so each one takes minutes. Set `COCONUT_KEEP_TEST_FILES=TRUE` to keep `coconut/tests/dest` and the cloned external projects afterwards so you can inspect them.
178
+
179
+ Pitfalls:
180
+
181
+ - **Run one suite at a time per checkout.** Every target and pytest test uses the same `coconut/tests/dest`, the same `__coconut_cache__` directories in `coconut/tests/src`, and the same clone directories in the repository root (`coconut-prelude/`, `cpython/`, ...), and they delete these when they start. To run suites in parallel, use separate checkouts (e.g. `git worktree add`).
182
+ - **Use a separate `COCONUT_HOME` for each checkout you type-check from at the same time.** `--mypy` and `--pyright` link the current checkout's stubs into `$COCONUT_HOME/.coconut_stubs`, and `--pyright` writes `$COCONUT_HOME/.coconut_pyrightconfig.json`. `COCONUT_HOME` defaults to your home directory.
183
+ - **Don't point pytest at `coconut/tests` while `coconut/tests/dest` exists.** The compiled suite contains files such as `py314_test.py` that match pytest's `*_test.py` pattern, so collection fails with syntax errors. Pass the test file paths, or run `make clean` first (`make test-all` does).
184
+ - **The gates check the interpreter, not what's installed.** For example, the MyPy tests exist on every non-Windows CPython 3.10+, whether or not MyPy is installed. Install `.[tests]` (whose contents follow the same conditions) with the Python you're testing.
185
+ - **Caching.** Without `--force`, Coconut skips files whose source and compiler options haven't changed. That's why the `*-tests` targets miss compiler changes. The incremental parsing cache in `__coconut_cache__` is used unless you pass `--no-cache`, and `make clean` deletes it.
186
+ - **`make test-all` touches the network and your environment.** `TestExternal` clones projects from GitHub, and on CPython 3.10+ `test_prelude` runs coconut-prelude's `make base-install`, which `pip install`s pytest and coconut-prelude into the active environment. Only run it in a virtual environment.
187
+ - `constants_test.py::test_imports` needs a complete standard library (e.g. `tkinter` and `dbm.gnu` on CPython), so it fails on minimal Python builds.
188
+
189
+ ### Running Every Test Configuration
190
+
191
+ To save time, many tests only run on some Python versions, platforms, or settings, and some configurations are only reachable through a Makefile target or a constant. `make test` on one Python version misses a lot. For example, `test_no_wrap` and `test_standalone` only exist on Python versions below 3.12, so `make test` (or even `make test-all`) on Python 3.13 never runs the suite with `--no-wrap`.
192
+
193
+ These are the conditions that decide which tests run, with the flag definitions in `coconut/constants.py`:
194
+
195
+ | Condition | Tests | How to enable | Run by CI? |
196
+ | --- | --- | --- | --- |
197
+ | `COCONUT_TEST_ALL` (on by default except on Windows) | `test_strict_keep_lines`, `test_and`, `test_run_arg`, `test_run_dir`, `test_any_of` (CPython only), `test_jobs_zero` and `test_incremental` (not PyPy), and all of `TestExternal` | `COCONUT_TEST_ALL=TRUE` (or `FALSE` to skip them) | Yes |
198
+ | Python < 3.12 | `test_standalone`, and also `test_no_wrap` on Python 3.5+ | Run pytest with Python 3.11 or older. `make test-no-wrap` works on any version, but there's no Makefile target for `--standalone`. | `test_standalone`: 2.7, 3.7 to 3.11, and all PyPy versions; `test_no_wrap`: the same minus Python 2. `--standalone` is never tested on 3.12+. |
199
+ | Python 3.12+ | `TestExternal.test_bbopt` (compile only, with `COCONUT_TEST_ALL`) | Python 3.12+ | CPython 3.12 to 3.15 |
200
+ | CPython 3, and whether it's the newest Python (`supported_py3_vers[-1]`) | `TestExternal.test_cpython` (with `COCONUT_TEST_ALL`), which tests that Coconut supports the newest Python's syntax. It always sparse-clones the newest Python's tests from CPython (the tag for the running version on the newest Python, otherwise that version's branch, falling back to `main`) and compiles the ones listed in `cpython_test_modules` as Coconut with `--target sys`. On the newest Python, it then runs them with `unittest`, skipping the tests listed in `cpython_tests_not_run` (by test id prefix), which test things Coconut intentionally does differently. On older versions of Python, it instead checks that the only compilation errors are `CoconutTargetError`s (for syntax that requires a newer target) and that everything else compiles to valid Python for that version (other than code that hits bugs in older versions of CPython's compiler, listed in `cpython_compiler_bugs`). A new Python version can break it by adding tests of new syntax, which is the point. | CPython 3, including the newest Python | CPython 3.7 to 3.15 (3.15 runs the tests) |
201
+ | Python 2 or 3 | Python 2 compiles `target_2` and uses `--target 2` in `test_target`. Python 3 compiles `target_3` and runs `test_pickle_main`, `test_target_3_snip`, and `test_pytest_plugin` (which also needs pytest 7+). | Both a Python 2 and a Python 3 interpreter | 2.7, PyPy 2.7, and 3.x |
202
+ | Python 3.5, 3.6, 3.8, 3.11, or 3.14+ | The matching `target_<N>` folder, plus `specific.coco` tests gated on the version. `make test` compiles every folder but only runs those the current Python supports. `target_314` is only MyPy-checked on 3.14+, and `target_2` never is. `test_zipapp` needs 3.5+, and `test_tutorial` needs 3.7+. | The newest Python, plus older ones | 2.7 and 3.7 to 3.15 |
203
+ | `always_sys_versions` (the newest Python 2 and the two newest Python 3 versions: currently 2.7, 3.14, and 3.15) | `test_always_sys` (every folder compiled with `--target sys`) | One of those versions | Yes |
204
+ | Python at least the oldest version the PSF still supports (currently 3.11; set by the dates in `py_vers_with_eols`) | `test_simple_psf` | 3.11+ | 3.11+, including PyPy 3.11 |
205
+ | `MYPY`: CPython 3.10+, not on Windows | The MyPy and Pyright snippet tests in `TestShell` (`test_*_mypy_snip`, `test_mypy_source_lines`, `test_exhaustiveness`, `test_addpattern_redefinition`, `test_pyright`), `test_mypy_sys`, and running coconut-prelude's tests in `test_prelude`. The `tests` extra only installs MyPy and Pyright when this holds. | CPython 3.10+ on Linux or macOS | CPython 3.10 to 3.15 |
206
+ | `LSP`: Python 3.9+ | `test_lsp`. `lsp_test.py` skips itself below 3.8. Some of its checks also need `pyflakes` or `mypy` installed. | 3.9+ with `.[tests]` | `lsp_test.py`: 3.8+; `test_lsp`: 3.9+ |
207
+ | `IPY`: 3.6+, but not 3.7, not PyPy below 3.11, and not PyPy on Windows | `test_ipython_extension`, `test_kernel_run_cell_kwargs`, `test_kernel_installation`, `test_jupyter_console` (not on Windows or PyPy), and the kernel tests in `extras.coco` | CPython 3.8+ | CPython 3.8 to 3.15, PyPy 3.11 |
208
+ | `XONSH`: 3.5 or 3.8+, excluding PyPy 3.9+, and not on Windows | `test_xontrib` | CPython 3.8+ on Linux or macOS | CPython 3.8 to 3.15 |
209
+ | `NUMPY`: CPython 2.7 or 3.4+ | The numpy tests in `extras.coco`, plus pandas (3.6+) and xarray (3.10+) | CPython | CPython |
210
+ | `CPYTHON` or `PYPY` | cPyparsing is only installed on CPython, so PyPy uses pure-Python `pyparsing` and never uses incremental parsing or the parse cache. PyPy also compiles with `--jobs 0` and takes different branches in the `.coco` tests. | PyPy 2 and 3 | Yes |
211
+ | `WINDOWS` | Turns off `COCONUT_TEST_ALL` (by default), `MYPY`, `test_xontrib`, `test_jupyter_console`, and `test_import_hook_preserves_stdin` | Windows | **No**: `.appveyor.yml` still exists, but AppVeyor hasn't run a build since March 2024 |
212
+ | `markdown_it` importable | The interactive tutorial part of `test_tutorial` (otherwise silently skipped) | `pip install markdown-it-py` (included in `.[docs]` and `.[dev]`) | **No**: `.[tests]` doesn't include it |
213
+ | Running from a source checkout | `test_tutorial` needs `HELP.md`. `lsp_test.py`'s plugin and docs checks need `.claude-plugin/` and `DOCS.md`. | A git checkout | Yes |
214
+ | `COCONUT_TEST_VERBOSE` or `COCONUT_TEST_TRACE` | `test_verbose` (`--verbose`) or `test_trace` (`--trace`) | Set the variable to `TRUE` | **No** |
215
+ | `--test-easter-eggs` | `easter_egg_test` in `main.coco` | `make test-easter-eggs` | **No** |
216
+ | Makefile-only compiler settings | The full suite with `--pyright`, `--check-untyped-defs`, `--minify`, or `--watch`, or with pure-Python pyparsing (`test-mypy-all`'s `--check-untyped-defs` also checks the suite's own untyped test code, which isn't written to pass it, so it's expected to report errors there; it's for catching type errors in Coconut's generated code) | `make test-pyright`, `test-mypy-all`, `test-minify`, `test-watch`, `test-purepy` | **No**, except that PyPy jobs use pure-Python pyparsing |
217
+ | `test_computation_graph_pickling` in `constants.py` | Checks that every computation graph action can be pickled, for every handler the suite exercises | Temporarily set it to `True` and run `make test`. `constants_test.py` fails until you set it back. | **No** |
218
+
219
+ The `.coco` tests also branch on `sys.version_info`, PyPy, and the platform internally, so every extra interpreter tests more code paths. External projects come from GitHub: `test_prelude` and `test_imp_issue` run everywhere `TestExternal` does (except that `test_prelude` doesn't run on PyPy 3), and the pyprover test is commented out.
220
+
221
+ #### Testing on Multiple Python Versions
222
+
223
+ The simplest approach is one virtual environment per interpreter, each with Coconut's test dependencies installed, and then `PYTHONPATH` pointed at the checkout you want to test. That way you can reuse the same environments for any checkout or worktree. With [uv](https://docs.astral.sh/uv/):
224
+
225
+ ```bash
226
+ cd /path/to/coconut
227
+ for v in 3.11 3.13 3.15 pypy@3.11; do
228
+ uv venv -p "$v" "$HOME/.venvs/coconut-$v"
229
+ uv pip install -p "$HOME/.venvs/coconut-$v/bin/python" ".[tests]" markdown-it-py
230
+ done
231
+ ```
232
+
233
+ uv can't create Python 2 environments (and may not have Python 3.7 builds). For those, use pyenv, conda, or a system interpreter with `virtualenv`, and `pip install ".[tests]"`.
234
+
235
+ To run the suite with one of those environments, put its `bin` directory first on `PATH`. The tests run `coconut`, `coconut-run`, `pytest`, `jupyter`, `ipython`, and `xonsh` from `PATH`. Then set `PYTHONPATH` to the checkout:
236
+
237
+ ```bash
238
+ cd /path/to/coconut
239
+ PATH="$HOME/.venvs/coconut-3.11/bin:$PATH" PYTHONPATH="$PWD" COCONUT_TEST_ALL=TRUE make test-all
240
+ ```
241
+
242
+ To run several versions in a row (one at a time, since they share `coconut/tests/dest`):
243
+
244
+ ```bash
245
+ for v in 3.11 3.13 3.15 pypy@3.11; do
246
+ PATH="$HOME/.venvs/coconut-$v/bin:$PATH" PYTHONPATH="$PWD" COCONUT_TEST_ALL=TRUE \
247
+ make test-all > "test-all-$v.log" 2>&1 || echo "FAILED on $v"
248
+ done
249
+ ```
250
+
251
+ To run versions in parallel, give each one its own worktree and `COCONUT_HOME`. If you only have one checkout, `uv pip install -e ".[tests]"` works too and doesn't need `PYTHONPATH`.
252
+
253
+ #### Full Test Checklist
254
+
255
+ CI covers every Python version on Linux, so passing CI covers everything above except the rows marked **No**. Before a release, or after a change that could affect one of those configurations, also run:
256
+
257
+ 1. `make test-all` on CI, or locally on Python 3.11 *and* the newest Python, and on PyPy and Python 2.7 if you touched compatibility code. This covers both the below-3.12 side (`test_no_wrap`, `test_standalone`) and the 3.12+ side of the gates.
258
+ 2. `make test-pyright`, `make test-easter-eggs`, `make test-purepy`, `make test-minify`, and `make test-no-wrap` (which also covers `--no-wrap` on 3.12+).
259
+ 3. `pytest --strict-markers -s "coconut/tests/main_test.py::TestShell::test_tutorial"` with `markdown-it-py` installed.
260
+ 4. Set `test_computation_graph_pickling = True` in `coconut/constants.py`, run `make test`, and set it back.
261
+ 5. Check that `coconut --watch` recompiles files when they change (`make test-watch`).
262
+ 6. On Windows, if your change could behave differently there, since CI doesn't cover it.
263
+
264
+ ### What CI Covers
265
+
266
+ - **`.github/workflows/run-tests.yml`** runs on every push to `evhub/coconut` (it has no `pull_request` trigger, so for a pull request from a fork, enable Actions on your fork to run it there). Superseded runs on the same branch are cancelled. It runs on Linux with CPython 2.7 and 3.7 to 3.15 and PyPy 2.7, 3.9, 3.10, and 3.11. Each job runs `make install` (`pip install -e .[tests]`), `make test-all` with the default environment (so `COCONUT_TEST_ALL` is on), and `make build`. On `master` and `develop`, it then uploads to PyPI ("Publish to PyPI", `continue-on-error`). Jobs time out after 150 minutes.
267
+ - **`.github/workflows/codeql-analysis.yml`** runs CodeQL on pushes and pull requests to `master` and `gh-pages`, and weekly.
268
+ - **`.github/workflows/claude.yml`** and **`claude-code-review.yml`** run Claude Code on `@claude` mentions and review pull requests.
269
+ - **`.appveyor.yml`** would run `make test-all` on Windows (Python 2.6, 2.7, 3.5, 3.9, 3.10, and 3.11), but the AppVeyor project hasn't built since March 2024.
270
+ - **readthedocs** builds the documentation from `.readthedocs.yaml` (Python 3.11, `.[docs]`).
271
+
272
+ CI doesn't catch: anything Windows- or macOS-specific; Python 2.6 and 3.2 to 3.6, which are supported targets but have no CI interpreter; the configurations marked **No** above; and anything that only shows up with a dirty `__coconut_cache__` or `coconut/tests/dest`, since CI always starts clean.
273
+
274
+ ## Release Process
275
+
276
+ `DEVELOP = N` in `coconut/root.py` makes the version `VERSION-post_devN`. Every push to `develop` that passes CI publishes that version as [`coconut-develop`](https://pypi.org/project/coconut-develop/), so bump `DEVELOP` whenever you want to publish a new development build (PyPI won't accept the same version twice).
277
+
278
+ _Steps marked **(confirm)** couldn't be verified from the repository; the maintainer should confirm whether they're still done._
279
+
280
+ 1. Preparation:
281
+ 1. Run `make check-reqs` (it needs network access to PyPI) and use it to update Coconut's dependencies. It prints three groups:
282
+ 1. **Updates to make**: requirements in `unpinned_min_versions` in `coconut/constants.py` that have newer releases, each with a suggested new minimum (at the current minimum's precision) and the Python versions that the oldest release allowed by that minimum supports. Update each of these in `unpinned_min_versions`, unless that release doesn't support every Python the requirement's environment marker allows (e.g. `("jedi", "py>=39")` can't require a version that needs Python 3.10, since Coconut supports 3.9). In that case, leave it, or split the requirement into version-specific entries (in both `unpinned_min_versions` and the groups in `all_reqs` that use it). If `typing_extensions` is updated, add anything it newly backports to `new_to_old_stdlib`.
283
+ 2. **Pinned**: requirements in `pinned_min_versions`, which are deliberately held back (see the comment on each). Only update one of these if its reason no longer applies.
284
+ 3. **Up to date**: requirements whose newer releases are already allowed by their current minimums. Nothing needs to change for these.
285
+ Then reinstall (`make dev`) and run the tests, since the new minimums change what gets installed.
286
+ 2. Run `make format`.
287
+ 3. If a new Python version has come out or one has reached end of life, update `supported_py3_vers`, `py_vers_with_eols`, and `specific_targets` in `coconut/constants.py`, the list of targets in `DOCS.md`, and the CI matrix in `.github/workflows/run-tests.yml`.
288
+ 4. Go through the [full test checklist](#full-test-checklist). The `test-purepy`, `test-minify`, `test-no-wrap`, interactive tutorial, and Windows checks are new to this list **(confirm they pass today)**.
289
+ 5. Run `make docs` and make sure the local documentation looks good (`docs/index.html`). If `DOCS.md` changed, make sure `python -m coconut.lsp.generate_docs` was run.
290
+ 6. Check all the tooling:
291
+ 1. Make sure the [`coconut-develop`](https://pypi.org/project/coconut-develop/) package looks good.
292
+ 2. Check changes in [`compiled-cocotest`](https://github.com/evhub/compiled-cocotest), [`pyprover`](https://github.com/evhub/pyprover) (its test in `TestExternal` is commented out), and [`coconut-prelude`](https://github.com/evhub/coconut-prelude).
293
+ 3. Make sure [`sublime-coconut`](https://github.com/evhub/sublime-coconut) (the Sublime Text package and VS Code extension) supports everything new in the release:
294
+ 1. Its syntax highlighting (`sublime_coconut/specification.py`, rebuilt into `langs/Coconut.tmLanguage` by `python build.py`) should highlight every new keyword, built-in, operator, and string prefix, and any other new syntax. Its `server/tests/test_grammar.py` checks the built-ins, keywords, and string prefixes against the installed Coconut (its CI runs it against `coconut-develop`), but check other new syntax by hand.
295
+ 2. Its bundled language server (used with versions of Coconut that don't have `coconut --lsp`) should have any fixes made to `coconut/lsp/` since the last release, and up-to-date hover docs: run `python scripts/generate_docs.py path/to/coconut/DOCS.md`.
296
+ 7. Make sure the [GitHub Actions](https://github.com/evhub/coconut/actions) and [readthedocs](https://readthedocs.org/projects/coconut/builds/) builds are passing.
297
+ 8. Make sure the [develop documentation](https://coconut.readthedocs.io/en/develop/) looks good.
298
+ 9. In `coconut/root.py`, set `VERSION` to the new version and `DEVELOP = False` (`ALPHA` must be `False` too). Optionally set `VERSION_NAME` for a major release (v2.0.0 had one; v3.0.0 didn't). With `DEVELOP = False` the package is `coconut` rather than `coconut-develop`, but CI's PyPI token only covers `coconut-develop`, so CI's "Publish to PyPI" step fails harmlessly (it's allowed to fail) and nothing is published until step 3.5.
299
+
300
+ 2. Pull Request:
301
+ 1. Move unresolved issues to the next [milestone](https://github.com/evhub/coconut/milestones).
302
+ 2. Create a pull request to merge `develop` into `master`, titled "Release vX.Y.Z", with the `release` label and the release's milestone. Put the release notes, linking every resolved issue, in its description.
303
+ 3. Link contributors on the pull request.
304
+ 4. Wait until everything is passing.
305
+
306
+ 3. Release:
307
+ 1. If `sublime-coconut` changed, release it: bump `version` in its [`package.json`](https://github.com/evhub/sublime-coconut/blob/master/package.json) and add a `CHANGELOG.md` entry. Once that reaches its `master`, its Release workflow tags the version, creates the GitHub release, and publishes to the VS Code Marketplace and Open VSX, and Package Control picks up the tag for Sublime Text.
308
+ 2. Merge the pull request (with a merge commit) and label it `resolved`.
309
+ 3. [Release `master` on GitHub](https://github.com/evhub/coconut/releases/new): tag `vX.Y.Z`, title "Coconut vX.Y.Z", and the release notes from the pull request.
310
+ 4. `git fetch`, `git checkout master`, and `git pull`.
311
+ 5. Run `make upload`, which runs `make wipe` and `make dev`, then builds and uploads to PyPI with `twine` (it asks for a PyPI token) **(confirm)**. This is the only way `coconut` itself gets published: CI's PyPI token only covers `coconut-develop`, so CI's "Publish to PyPI" step fails harmlessly for releases.
312
+ 6. `git checkout develop`, `git rebase master` (a fast-forward, since `master` is now `develop` plus the merge commit), and `git push`. `make fix-develop` (`git merge master -s ours`) records a merge of `master` into `develop` without changing `develop`'s files, for when the two have diverged.
313
+ 7. Set `DEVELOP = 1` in `coconut/root.py`.
314
+ 8. Run `make dev`.
315
+ 9. Push to `develop`.
316
+ 10. Wipe all updated versions on [readthedocs](https://readthedocs.org/projects/coconut/versions/) **(confirm)**.
317
+ 11. Build all updated versions on [readthedocs](https://readthedocs.org/projects/coconut/builds/).
318
+ 12. Copy the [PyPI](https://pypi.org/project/coconut/) keywords to the [readthedocs tags](https://readthedocs.org/dashboard/coconut/edit/) **(confirm)**.
319
+ 13. Update the recipe (`recipe/meta.yaml`) of [Coconut's `conda-forge` feedstock](https://github.com/conda-forge/coconut-feedstock), on a branch of the [fork](https://github.com/evhub/coconut-feedstock) made from conda-forge's `main` (the fork's `master` is out of date): set the version and the SHA-256 hash of the `.tar.gz` file from [PyPI](https://pypi.org/project/coconut/#files), and make its run requirements match Coconut's for the Python versions conda-forge supports (`python -c "from coconut.requirements import extras; print(extras)"` prints them; they come from [`constants.py`](https://github.com/evhub/coconut/blob/master/coconut/constants.py)). The recipe is `noarch: python`, so it can't select requirements by Python version; requirements only needed on older Pythons (like `exceptiongroup`) are always included. Use `pyparsing` until `cpyparsing` is on conda-forge.
320
+ 14. Open a pull request from that branch to `conda-forge/coconut-feedstock`, or push to the one conda-forge's bot opens for the new PyPI release. If the build configuration changed (e.g. the Python versions), comment `@conda-forge-admin, please rerender` on it.
321
+ 15. Update the [website](https://github.com/evhub/coconut/tree/gh-pages) if it needs updating.
322
+ 16. Wait until the feedstock pull request is passing, then merge it.
323
+ 17. Close the release [milestone](https://github.com/evhub/coconut/milestones?direction=asc&sort=due_date).