chialisp 0.5.0

tools for working with chialisp language; compiler, repl, python and wasm bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# Thanks: clvm_rs' github actions.
name: Build

on:
  push:
    branches:
      - base
      - dev
  release:
    types: [published]
  pull_request:
    branches:
      - '**'

permissions:
  id-token: write
  contents: read

jobs:
  build_wheels:
    name: Wheel on ${{ matrix.os }} py-${{ matrix.python }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-15-intel, ubuntu-latest, windows-latest]
        python: ['3.10', 3.11, 3.12]

    steps:
    - uses: actions/checkout@v7
      with:
        fetch-depth: 0

    - name: Set up rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: 1.97.1

    - uses: actions/setup-python@v6
      name: Install Python ${{ matrix.python }}
      with:
        python-version: ${{ matrix.python }}

    - uses: chia-network/actions/create-venv@main
      id: create-venv

    - uses: chia-network/actions/activate-venv@main
      with:
        directories: ${{ steps.create-venv.outputs.activate-venv-directories }}

    - name: Install dependencies
      run: |
          python -m pip install --upgrade pip
          python -m pip install maturin==1.10.2

    - name: Build MacOs with maturin on Python ${{ matrix.python }}
      if: startsWith(matrix.os, 'macos')
      env:
        MACOSX_DEPLOYMENT_TARGET: '15.0'
      run: |
        maturin build -i python --release --strip

    - name: Build Linux in manylinux_2_28 with maturin on Python ${{ matrix.python }}
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        docker run --rm -v $(pwd):/io ghcr.io/pyo3/maturin:v1.10.2 build --release --strip --manylinux 2_28 --sdist
        # Refresh in case any ownerships changed.
        mv target target.docker && cp -r target.docker target
        # Ensure an empty .cargo-lock file exists.
        touch target/release/.cargo-lock

    - name: Build Windows with maturin on Python ${{ matrix.python }}
      if: startsWith(matrix.os, 'windows')
      run: |
        maturin build -i python --release --strip
        # Find and install the newly built wheel
        pip install --no-index --find-links target/wheels/ chialisp

    - name: Install chialisp wheel
      if: ${{ !startsWith(matrix.os, 'windows') }}
      run: |
        ls target/wheels/
        # this mess puts the name of the `.whl` file into `$WHEEL_PATH`
        # remove the dot, use the `glob` lib to grab the file from the directory
        export WHEEL_PATH=$(echo ${{ matrix.python }} | python -c 'DOTLESS=input().replace(".", ""); import glob; print(" ".join(filter(lambda x: "musl" not in x, glob.glob("target/wheels/chialisp-*-cp*-*.whl"))))' )
        echo ${WHEEL_PATH}
        pip install ${WHEEL_PATH}

    - name: Install other wheels
      run: |
        python -m pip install pytest
        python -m pip install blspy

    - name: install clvm & clvm_tools
      run: |
        git clone https://github.com/Chia-Network/clvm.git --branch=main --single-branch
        python -m pip install ./clvm

        echo "installing clvm_rs via pip"
        pip install clvm_rs

        # Ensure clvm_tools is installed from its own repo.
        echo "installing clvm_tools for clvm tests"
        git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch
        python -m pip install ./clvm_tools

        # Install chialisp pkg as "clvm_tools_rs" for older test framework
        pip uninstall -v -y clvm_tools_rs
        pip install chialisp
        pip install -e ./tmp


    - name: Ensure clvm, clvm_rs, chialisp are installed
      run: |
        python -c 'import clvm; print("clvm:", clvm.__file__)'
        python -c 'import clvm_rs; print("clvm_rs", clvm_rs.__file__)'
        python -c 'import chialisp; print("chialisp:", chialisp.__file__)'
        python -c 'import clvm_tools_rs; print("clvm_tools_rs:", clvm_tools_rs.__file__)'
        echo "CLVM_TOOLS_RS_VERSION=$(python -c 'import clvm_tools_rs; print(clvm_tools_rs.get_version())')" >> "$GITHUB_ENV"
        echo "CHIALISP_VERSION=$(python -c 'import chialisp; print(chialisp.get_version())')" >> "$GITHUB_ENV"

    # Test cldb output both run from python and via its command line tool.
    - name: "Run step run tests"
      run: |
        cargo build
        # This finds and installs a compatible wheel from the target directory on linux.
        # We do it here as a hedge against changes in the python environment that might
        # have happened due to pulling in the trunk versions of other packages that
        # depend on chialisp.
        pip install --no-index --find-links target/wheels/ chialisp
        pip install clvm_rs
        pip install clvm_tools
        cd resources/tests
        python test_clvm_step.py
        python mandelbrot-cldb.py
        python test_compile_from_string.py
        python test_binutils_api.py

    - name: "Test step run with mandelbrot, setting print only"
      run: |
        python ./resources/tests/lib/steprun.py ./resources/tests/mandelbrot/mandelbrot.clvm.hex resources/tests/mandelbrot/mand_args.txt ./resources/tests/mandelbrot/mandelbrot.sym > mand_output.txt
        # git diff invoked this way returns 0 (as /bin/true) if there is no difference or 1 if there is.
        git diff --no-index -s --quiet -- mand_output.txt ./resources/tests/mandelbrot/mand_test.txt
        # Remove file in a compatible way using git as a general tool
        git add mand_output.txt
        git rm --force mand_output.txt


    - name: Verify recompilation of old sources match with new compiler
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        # Build cmd line tools
        echo "START PWD:" $(pwd) && \
        PYO3_PYTHON=`which python` cargo build --release

        # Grab chia_puzzles
        rm -rf chia_puzzles
        git clone https://github.com/Chia-Network/chia_puzzles

        # Check that recompiling deployed puzzles match with their deployed hashes
        # chia_puzzles is the directory the repo is cloned in.  It contains a subdir
        # called chia_puzzles_py, which is a bit confusing, but that's where the
        # manage_clvm.py script is.  That's why the code below runs
        # chia_puzzles_py/manage_clvm.py while being in ./chia_puzzles.
        cp support/install_deps.sh support/verify_compiler_version.sh chia_puzzles
        (cd chia_puzzles && python -m venv .venv && . .venv/bin/activate && pip install --upgrade pip && \
        python -m pip install maturin==1.10.2 && \
        cd .. && \
        pip install --no-index --find-links target/wheels/ chialisp && \
        cd chia_puzzles && \
        pip install click typing_extensions chia_rs clvm chia_puzzles_py) && \
        pip uninstall -v -y clvm_tools_rs && \
        pip uninstall -v -y chialisp && \
        pip install -v --no-index --find-links target/wheels/ chialisp && \
        pip uninstall -v -y clvm_tools_rs && \
        echo "PWD:" $(pwd) && \
        pip install -e ./tmp && \
        (cd chia_puzzles && export PYTHONPATH=${PYTHONPATH}:$(pwd) && \
        ./verify_compiler_version.sh ${CLVM_TOOLS_RS_VERSION} && . .venv/bin/activate && \
        echo "Running check" && \
        python chia_puzzles_py/manage_clvm.py check && \
        echo "Check successful")

    - name: Test Classic command line tools with pytest
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        python -m pip install pytest
        # This script installs the wheel built during this workflow.
        pip install --no-index --find-links wheel/target/wheels/ chialisp
        # TODO: bring in the other tests in resources/tests/cmdline/tests besides cmds_test.py
        (cd resources/tests/cmdline/tests && py.test cmds_test.py )

    - name: Verify recompilation of cl21 sources
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        # We need chia-rs for the following.
        pip install chia-rs
        # Ensure we're using the sources we have.  This is a hedge against
        # changes made by any other step doing operations on pip.
        # This script installs the wheel built during this workflow.
        pip install --no-index --find-links wheel/target/wheels/ chialisp
        (cd resources/tests && python check-recompiles.py)

    - name: Verify recompilation follows date and modification rules
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        pip install --no-index --find-links wheel/target/wheels/ chialisp
        python resources/tests/test-clvm-recompile-behavior.py

    - name: Install pytest
      run: |
        pip install pytest pytest-asyncio

    - name: Run tests from clvm
      run: |
        cd clvm
        pytest tests

    - name: Run tests from clvm_tools
      run: |
        cd clvm_tools
        pytest tests

    - name: Run tests
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: cargo test --features=fuzz

    - name: Exhaustive assign tests
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: cargo test -- --include-ignored assign

    - name: Check coverage
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        cargo install grcov
        rustup component add llvm-tools-preview
        python ./resources/coverage/run_coverage.py --require-percent 60

    - name: Build alpine wheel via docker
      if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python, '3.12')
      run: |
        cd resources/alpine && docker build -t clvm-tools-rs-alpine .
        docker run -v ${GITHUB_WORKSPACE}:/root/chialisp -t clvm-tools-rs-alpine sh /root/build-alpine.sh

    - name: Upload artifacts
      uses: actions/upload-artifact@v7
      with:
        name: wheels-${{ matrix.os }}-py-${{ matrix.python }}
        path: ./target/wheels/

  upload:
    name: Upload to PyPI
    runs-on: ubuntu-latest
    needs: build_wheels
    steps:
    - name: Checkout code
      uses: actions/checkout@v7
      with:
        fetch-depth: 0

    - name: Set Env
      uses: Chia-Network/actions/setjobenv@main
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    - name: Install python
      uses: Chia-Network/actions/setup-python@main
      with:
        python-version: "3.12"

    - name: Download artifacts
      uses: actions/download-artifact@v8
      with:
        merge-multiple: true
        pattern: wheels-*-py-3.12
        path: ./target/wheels/

    - name: List artifacts
      run: |
        ls -la target/wheels/
        sha256sum target/wheels/*

    - name: Check for incompatible wheels and bail if found
      run: |
        set -e
        # Check for a wheel with -linux_x86_64 platform tag, which will
        # fail uploading to pypi.
        find target -name \*-linux_x86_64.whl -exec /bin/false '{}' '+'

    - name: Publish distribution to PyPI
      if: env.RELEASE == 'true'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        packages-dir: target/wheels/
        skip-existing: true

    - name: Publish distribution to Test PyPI
      if: env.PRE_RELEASE == 'true'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
        packages-dir: target/wheels/
        skip-existing: true

    - name: Test for secrets access
      id: check_secrets
      shell: bash
      run: |
        unset HAS_AWS_SECRET

        if [ -n "$AWS_SECRET" ]; then HAS_AWS_SECRET='true' ; fi
        echo HAS_AWS_SECRET=${HAS_AWS_SECRET} >>$GITHUB_OUTPUT
      env:
        AWS_SECRET: "${{ secrets.CHIA_AWS_ACCOUNT_ID }}"

    - name: Configure AWS credentials
      if: steps.check_secrets.outputs.HAS_AWS_SECRET
      uses: aws-actions/configure-aws-credentials@v6.2.0
      with:
        role-to-assume: arn:aws:iam::${{ secrets.CHIA_AWS_ACCOUNT_ID }}:role/installer-upload
        aws-region: us-west-2

    - name: Publish Dev
      if: steps.check_secrets.outputs.HAS_AWS_SECRET && github.ref == 'refs/heads/dev'
      shell: bash
      working-directory: ./target/wheels
      run: |
        FILES=$(find . -type f -name '*.whl')
        while IFS= read -r file; do
          filename=$(basename $file)
          aws --no-progress s3 cp "$file" "s3://download.chia.net/simple-dev/clvm-tools-rs/$filename"
        done <<< "$FILES"

  clippy:
    runs-on: ubuntu-22.04
    name: clippy
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 1
      - name: Install rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
          toolchain: 1.97.1-x86_64-unknown-linux-gnu
      - name: clippy
        run: |
          # Add --all-targets as a separate step
          cargo clippy --workspace -- -D warnings
      - name: cargo fmt
        run: cargo fmt --all -- --files-with-diff --check

  typing:
    runs-on: ubuntu-22.04
    name: typing
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 1
      - uses: actions/setup-python@v6
        with:
          python-version: "3.12"
      - name: Install rust
        uses: dtolnay/rust-toolchain@stable
      - name: stubtest
        run: |
          python -m pip install --upgrade pip
          python -m pip install maturin==1.10.2 mypy
          maturin build --release
          pip install target/wheels/chialisp-*.whl
          stubtest --concise chialisp

  cargo_fmt:
    runs-on: ubuntu-22.04
    name: cargo fmt
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 1
      - name: Install rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
          toolchain: 1.97.1-x86_64-unknown-linux-gnu
      - name: cargo fmt
        run: cargo fmt --all -- --files-with-diff --check

  unit_tests:
    runs-on: ubuntu-22.04
    name: Unit tests
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 1
      - name: Install rust
        uses: actions-rs/toolchain@v1
        with:
            toolchain: 1.97.1
            components: rustfmt, clippy
      - name: cargo test
        run: cargo test

  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions-rs/toolchain@v1
        with:
            toolchain: 1.97.1
      - name: Install coverage tools
        run: |
          sudo apt-get update
          sudo apt-get install lcov -y
          rustup component add llvm-tools-preview
          cargo install grcov
          export RUSTFLAGS="-Cinstrument-coverage"
          export LLVM_PROFILE_FILE=$(pwd)/target/chialisp-%p-%m.profraw
          export CARGO_TARGET_DIR=$(pwd)/target
          cargo test --release --workspace
      - name: Configure pip
        run: |
          echo "PWD:" $(pwd)
          python -m pip install --upgrade pip
          python -m venv venv
          source venv/bin/activate
          python -m pip install --upgrade pip
      - name: clone clvm_tools so we have an exact match of the tests run in both repos
        run: |
          source venv/bin/activate
          git clone https://github.com/Chia-Network/clvm_tools.git --branch=main --single-branch
          pip install ./clvm_tools
      - name: install maturin & pytest
        run: |
          source venv/bin/activate
          python -m pip install maturin==1.10.2
          pip install pytest
      - name: Build maturin interface
        run: |
          source venv/bin/activate
          maturin develop --release
      - name: verify chialisp install
        run: |
          source venv/bin/activate
          pip show chialisp
          python -c 'import chialisp; print("chialisp:", chialisp.__file__)'
      #- name: Install chialisp
      #  run: |
      #    source venv/bin/activate
      #    pip uninstall -v -y chialisp
      #    pip install -v --no-index --find-links target/wheels/ chialisp
      - name: Install chialisp pkg as "clvm_tools_rs" for older test framework
        run: |
          source venv/bin/activate
          pip uninstall -v -y clvm_tools_rs
          pip install -e ./tmp
      - name: Run pytest in resources/tests/cmdline/tests for coverage
        run: |
          source venv/bin/activate
          (cd resources/tests/cmdline/tests && pytest)
      - name: Run grcov for coverage
        run: |
          source venv/bin/activate
          grcov . --binary-path target -s . --branch --ignore-not-existing --ignore='*/.cargo/*' --ignore='*/tests/*' -o rust_cov.info
      - name: Process lcov.info
        run: |
          source venv/bin/activate
          python -c 'with open("rust_cov.info") as f: lines = [l for l in f if not (l.startswith("DA:") and int(l.split(",")[1].strip()) >= 2**63)]; open("lcov.info", "w").writelines(lines)'
      - name: Upload to Coveralls
        uses: coverallsapp/github-action@v2
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
        with:
          path-to-lcov: './lcov.info'