Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a nix build and testing infra #10

Open
wants to merge 42 commits into
base: v8.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2b53595
misspelled empty
quinn-dougherty Nov 5, 2021
233f82e
init nix commit
quinn-dougherty Nov 5, 2021
664fbf9
nixified
quinn-dougherty Nov 5, 2021
aa89797
in submodule: git checkout v8.13+pyml
quinn-dougherty Nov 5, 2021
8be4221
manually updated .opam file to new stuff from zulip
quinn-dougherty Nov 5, 2021
f8b29de
trying to fix mc
quinn-dougherty Nov 5, 2021
c656b40
fixed mc
quinn-dougherty Nov 5, 2021
542d91f
stuff a python linter would tell you
quinn-dougherty Nov 5, 2021
e1afaa3
python packaging, dev tools
quinn-dougherty Nov 5, 2021
b972ccd
current bottleneck: can't make pytype and pytest aware of pycoq
quinn-dougherty Nov 5, 2021
99b7622
python versions to matrix: first attempt
quinn-dougherty Nov 5, 2021
f23df6c
added python 3.11-alpha.1
quinn-dougherty Nov 5, 2021
4ca57d8
seeing if dummy `__init__.py` files will work
quinn-dougherty Nov 5, 2021
3b76067
ci should... pass?
quinn-dougherty Nov 5, 2021
3e0bd52
pushing, taking a break
quinn-dougherty Nov 5, 2021
53b5ec8
Not sure why Makefile is busted
quinn-dougherty Nov 7, 2021
a452f31
[build] Run tests using dune
ejgallego Nov 7, 2021
37303b8
[build] Track deps correctly in pip3 call
ejgallego Nov 7, 2021
a7f8b52
[test] Test output of examples as a crude form of testing.
ejgallego Nov 7, 2021
86f9046
[test] Group out files in their own dir.
ejgallego Nov 7, 2021
b1a7baa
gonna fetch from upstream
quinn-dougherty Nov 7, 2021
e21f683
fake manual rebase mostly
quinn-dougherty Nov 7, 2021
7a3a56b
I think it might just work...
quinn-dougherty Nov 7, 2021
087d3e9
fixed help message
quinn-dougherty Nov 7, 2021
b585bd5
misspelled empty
quinn-dougherty Nov 5, 2021
260daae
init nix commit
quinn-dougherty Nov 5, 2021
dba13c6
nixified
quinn-dougherty Nov 5, 2021
cdc1a1c
manually updated .opam file to new stuff from zulip
quinn-dougherty Nov 5, 2021
4271453
stuff a python linter would tell you
quinn-dougherty Nov 5, 2021
5f0b32d
python packaging, dev tools
quinn-dougherty Nov 5, 2021
fbfa0c0
current bottleneck: can't make pytype and pytest aware of pycoq
quinn-dougherty Nov 5, 2021
9d95cad
python versions to matrix: first attempt
quinn-dougherty Nov 5, 2021
68c8ae6
added python 3.11-alpha.1
quinn-dougherty Nov 5, 2021
13b4c42
seeing if dummy `__init__.py` files will work
quinn-dougherty Nov 5, 2021
b304bcb
ci should... pass?
quinn-dougherty Nov 5, 2021
168817e
pushing, taking a break
quinn-dougherty Nov 5, 2021
393f51d
Not sure why Makefile is busted
quinn-dougherty Nov 7, 2021
bf32c3a
gonna fetch from upstream
quinn-dougherty Nov 7, 2021
453d865
fake manual rebase mostly
quinn-dougherty Nov 7, 2021
53f7c17
I think it might just work...
quinn-dougherty Nov 7, 2021
fc0ba5e
fixed help message
quinn-dougherty Nov 7, 2021
3986b15
rebased, longhand, but messed up submodules
quinn-dougherty Nov 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
# ignore F401 is essential until we figure out what's up with `import pycoq`
ignore = F401
max-line-length = 100
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
max-complexity = 10
20 changes: 14 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: PyCoq CI

on:
push:
Expand All @@ -17,12 +17,14 @@ jobs:
fail-fast: false
matrix:
ocaml-version: [4.11.1, 4.12.0]
python-version: [3.6, 3.7, 3.8, 3.9, 3.10]
os: [ubuntu-20.04]
env:
OPAMJOBS: "2"
OPAMROOTISOK: "true"
OPAMYES: "true"
NJOBS: "2"
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
Expand All @@ -32,19 +34,25 @@ jobs:
uses: avsm/setup-ocaml@v1
with:
ocaml-version: ${{ matrix.ocaml-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: OPAM dependencies setup
run: |
opam repos add coq-released http://coq.inria.fr/opam/released
opam config set-global jobs $NJOBS
opam install --deps-only .
opam install pythonlib
# Disabled due to vendoring
# opam install pythonlib ppx_python
# opam pin add ppx_python https://github.com/ejgallego/ppx_python.git#fixup
opam list
- name: Build and Test PyCoq
- name: Build PyCoq
run: |
set -e
eval $(opam env)
make
make test
make build_pycoq
- name: Validate examples
run: make examples
- name: Lint, typecheck, and test python
run: make pyci
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__pycache__
_build
*~
result
.pytype
pycoq.egg-info/
.hypothesis
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "coq-serapi"]
path = coq-serapi
url = https://github.com/ejgallego/coq-serapi.git
branch = v8.13+pyml
45 changes: 36 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
.PHONY: python help
.PHONY: build_pycoq help

PYNAME=pycoq
SERAPI=coq-serapi/coq-serapi.install

# coq-serapi.install is required so plugins are in place [runtime dep]
python:
build_pycoq:
dune build $(SERAPI) pycoq/$(PYNAME).so pycoq/__init__.py setup.py
( cd _build/default && python3 setup.py build && pip3 install . )
cp requirements.txt _build/default/requirements.txt && cp README.md _build/default/README.md
cd _build/default && python3 setup.py build && pip3 install .

test:
dune build examples/test.py examples/test2.py examples/error.py
dune exec -- python3 _build/default/examples/test.py
dune exec -- python3 _build/default/examples/test2.py
dune exec -- python3 _build/default/examples/error.py
examples: build_pycoq
dune build examples/add_commutative.py examples/definitions_ast.py examples/syntax_error.py
dune exec -- python3 _build/default/examples/add_commutative.py
dune exec -- python3 _build/default/examples/definitions_ast.py
dune exec -- python3 _build/default/examples/syntax_error.py

pyci: build_pycoq
pip install .[dev]
black .
flake8 .
pytype .
pytest testpy

nix_build_pycoq:
nix-build nix/opam2nix.nix
./result/bin/opam2nix resolve --ocaml-version 4.12.0 ./pycoq.opam --dest nix/opam-selection.nix
nix-shell nix/default.nix --run "eval $(opam env)"
nix-shell nix/default.nix --run "dune build $(SERAPI) pycoq/$(PYNAME).so pycoq/__init__.py setup.py"
nix-shell nix/default.nix --run "cd _build/default && python3 setup.py build && pip3 install ."

nix_examples: nix_build_pycoq
nix-shell nix/default.nix --run "dune build examples/add_commutative.py examples/definitions_ast.py examples/syntax_error.py"
nix-shell nix/default.nix --run "dune exec -- python3 _build/default/examples/add_commutative.py"
nix-shell nix/default.nix --run "dune exec -- python3 _build/default/examples/definitions_ast.py"
nix-shell nix/default.nix --run "dune exec -- python3 _build/default/examples/syntax_error.py"

allpy: build_pycoq pyci examples

help:
@echo Nothing to display
@echo "If you have nix installed, try 'make nix_examples'. Else, try 'make examples'."

clean:
rm -rf _build
rm -r .pytype
2 changes: 1 addition & 1 deletion coq-serapi
42 changes: 42 additions & 0 deletions examples/add_commutative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pycoq # the thing breaks if this isn't imported, even tho it's not invoked
import coq

if __name__ == "__main__":
# Some common definitions we'll use
ppopts = {
"pp_format": ("PpSer", None),
"pp_depth": 1000,
"pp_elide": "...",
"pp_margin": 90,
}

# Add a full document chunk [mainly parsing]
opts = {"newtip": None, "ontop": 1, "lim": 20}
res = coq.add(
"""
Lemma addnC n m : n + m = m + n. Proof. now induction n; simpl; auto; rewrite IHn. Qed.
""",
opts,
)

# Check the proof.
res = coq.exec(5)

# We can show the goals at the tactic point
opts = {"limit": 100, "preds": [], "sid": 3, "pp": ppopts, "route": 0}
cmd = ("Goals", None)
res = coq.query(opts, cmd)
print(res)

# We can also output the ast for example, of the main tactic in our
# document
opts = {"limit": 100, "preds": [], "sid": 3, "pp": ppopts, "route": 0}
cmd = ("Ast", None)
res_ast = coq.query(opts, cmd)
print(res)

# Such AST can be actually pretty-printed
obj = res[0][1][0][0]
opts = {"pp": {"pp_format": ("PpStr", None)}}
res = coq.print(obj, opts)
print(res)
36 changes: 36 additions & 0 deletions examples/definitions_ast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pycoq # the thing breaks if this isn't imported, even tho it's not invoked
import coq

if __name__ == "__main__":

print("==> Adding a sentence")
opts = {"newtip": 2, "ontop": 1, "lim": 10}
res = coq.add("Definition a := 3.", opts)
print(res)

print("==> Adding another sentence")
opts = {"newtip": 3, "ontop": 2, "lim": 10}
res = coq.add("Definition b := 2.", opts)
print(res)

print("==> Checking the second sentence")
res = coq.exec(3)
print(res)

print("==> Printing the AST")
ppopts = {
"pp_format": ("PpSer", None),
"pp_depth": 1000,
"pp_elide": "...",
"pp_margin": 90,
}
opts = {"limit": 100, "preds": [], "sid": 3, "pp": ppopts, "route": 0}
cmd = ("Ast", None)
res = coq.query(opts, cmd)
print(res)

print("==> Formatting the AST")
obj = res[0][1][0][0]
opts = {"pp": {"pp_format": ("PpStr", None)}}
res = coq.print(obj, opts)
print(res)
6 changes: 0 additions & 6 deletions examples/error.py

This file was deleted.

9 changes: 9 additions & 0 deletions examples/syntax_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pycoq # the thing breaks if this isn't imported, even tho it's not invoked
import coq

if __name__ == "__main__":

# parsing error
opts = {"newtip": None, "ontop": None, "lim": 10}
res = coq.add("Definition a := .", opts)
print(res)
28 changes: 0 additions & 28 deletions examples/test.py

This file was deleted.

30 changes: 0 additions & 30 deletions examples/test2.py

This file was deleted.

3 changes: 3 additions & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Currently (11-05-2021) not working.

`opam2nix` has a mysterious disappearing `coq`. that's blocking actual isolation and reproducibility.
11 changes: 11 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs ? import ./pkgs.nix {}
, opam2nix ? import ./opam2nix.nix {}
}:
let
ocaml = pkgs.ocaml;
selection = opam2nix.build {
inherit ocaml;
selection = ./opam-selection.nix;
src = ../.;
};
in selection.pycoq
Loading