From cf23fb04b70b4ee42896571ba0eb721fddc306dc Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 31 Dec 2024 18:20:59 +0300 Subject: [PATCH 1/4] Use python3-embed as pkg-config dependency Attempts to use Cabal custom build failed miserably. It's better not to try it again unless absolutely necessary --- inline-python.cabal | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inline-python.cabal b/inline-python.cabal index 4fb6c2c..e449c35 100644 --- a/inline-python.cabal +++ b/inline-python.cabal @@ -16,6 +16,8 @@ Bug-reports: https://github.com/Shimuuar/inline-python/issues Category: FFI extra-doc-files: ChangeLog.md +extra-source-files: + include/inline-python.h data-files: py/bound-vars.py @@ -53,10 +55,7 @@ Library include-dirs: include c-sources: cbits/python.c cc-options: -g -Wall - -- FIXME: I think should use python-config instead of pkg-config. For now this - -- will do - pkgconfig-depends: python3 - extra-libraries: python3.12 + pkgconfig-depends: python3-embed -- Exposed-modules: Python.Inline.Literal From c0847ddaf99e691d2489be54d70bf8089acb496c Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 31 Dec 2024 18:24:49 +0300 Subject: [PATCH 2/4] Attempt to add CI --- .github/workflows/ci.yml | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ffa05dd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,73 @@ +name: CI + +# Trigger the workflow on push or pull request, but only for the master branch +on: + pull_request: + push: + branches: [master] + +defaults: + run: + shell: bash + +jobs: + cabal: + name: ${{ matrix.os }} / ghc ${{ matrix.ghc }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - { cabal: "3.12", os: ubuntu-latest, ghc: "9.2.8" } + - { cabal: "3.12", os: ubuntu-latest, ghc: "9.4.8" } + - { cabal: "3.12", os: ubuntu-latest, ghc: "9.6.6" } + - { cabal: "3.12", os: ubuntu-latest, ghc: "9.8.2" } + - { cabal: "3.12", os: ubuntu-latest, ghc: "9.10.1" } + fail-fast: false + steps: + # ---------------- + - uses: actions/checkout@v4 + # ---------------- + - uses: haskell-actions/setup@v2 + id: setup-haskell-cabal + name: Setup Haskell + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + # ---------------- + - uses: actions/cache@v3 + name: Cache ~/.cabal/store + with: + path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} + key: ${{ runner.os }}-${{ matrix.ghc }}--${{ github.Shah }} + # ---------------- + - name: Versions + run: | + cabal -V + ghc -V + pkg-config python3-embed --cflags + pkg-config python3-embed --libs + # ---------------- + - name: Make sdist + run: | + mkdir sdist + cabal sdist -o sdist + - name: Unpack + run: | + mkdir unpacked + tar -C unpacked -xzf sdist/inline-python*tar.gz + cd unpacked + # ---------------- + - name: cabal check + run: | + cabal -vnormal check + # ---------------- + - name: Build + run: | + if [ "${{ matrix.skip-test }}" == "" ]; then FLAG_TEST=--enable-test; fi + if [ "${{ matrix.skip-bench }}" == "" ]; then FLAG_BENCH=--enable-benchmarks; fi + cabal configure $FLAG_TEST $FLAG_BENCH + cabal build all --write-ghc-environment-files=always + # ---------------- + - name: Test + run: | + if [ "${{ matrix.skip-test }}" == "" ]; then cabal test all; fi From 567f9103cf8cd9f7073cfcb821f5f1c2187d12cb Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 31 Dec 2024 18:29:29 +0300 Subject: [PATCH 3/4] I don't need test executable anymore --- exe/tst.hs | 38 -------------------------------------- inline-python.cabal | 9 --------- 2 files changed, 47 deletions(-) delete mode 100644 exe/tst.hs diff --git a/exe/tst.hs b/exe/tst.hs deleted file mode 100644 index 46959ac..0000000 --- a/exe/tst.hs +++ /dev/null @@ -1,38 +0,0 @@ -{-# LANGUAGE QuasiQuotes #-} - --- {-# OPTIONS_GHC -ddump-splices #-} -module Main where - -import Control.Exception -import Python.Inline -import Python.Inline.QQ - -main :: IO () -main = withPython $ do - [py| - x = 3 - y = 1000 - import math - import gc - import sys - print(x+y,(x,y)) - |] - -- - -- let z = 1000000 :: Int - -- q = 1.2 :: Double - -- r1 <- [pye|x * y + z_hs|] - -- print =<< fromPy @Int r1 - -- print =<< fromPy @Double r1 - -- r2 <- [pye| math.sin(q_hs) |] - -- print =<< fromPy @Int r2 - -- print =<< fromPy @Double r2 - let sin_ = pure @IO . sin @Double - foo :: Int -> Int -> IO Int - foo a b = pure $ a `div` b - [py| - try: - print( sin__hs(1,3)) - except Exception as e: - print("OOPS", e) - |] `catch` (\(e::PyError) -> print ("OUCH",e)) - [py| print(foo_hs(1,0)) |] `catch` (\(e::PyError) -> print ("OUCH",e)) diff --git a/inline-python.cabal b/inline-python.cabal index e449c35..733289f 100644 --- a/inline-python.cabal +++ b/inline-python.cabal @@ -100,12 +100,3 @@ test-suite inline-python-tests1 , inline-python , inline-python:test , tasty - - --- Executable pyt --- import: language --- ghc-options: -O2 -Wall -threaded --- Build-Depends: base --- , inline-python --- hs-source-dirs: exe --- Main-is: tst.hs From 46ed424e8d9dc140ef2fb178f07fed14cfaeefae Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 31 Dec 2024 18:38:04 +0300 Subject: [PATCH 4/4] Fix cabal --- LICENSE | 2 +- inline-python.cabal | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/LICENSE b/LICENSE index 0161a4c..f5f133d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) Aleksey Khudyakov +Copyright 2024 (c) Alexey Khudyakov All rights reserved. diff --git a/inline-python.cabal b/inline-python.cabal index 733289f..869033b 100644 --- a/inline-python.cabal +++ b/inline-python.cabal @@ -3,11 +3,14 @@ Build-Type: Simple Name: inline-python Version: 0.1 -Synopsis: Embedding python interpreter into haskell +Synopsis: Python interpreter embedded into haskell. Description: - Embedding python interpreter + This package embeds python interpreter into haskell program and + allows to write python snippets as quasiquotes. Values could be + easily transferred between python and haskell. It's possible to + call haskell from python as well. - License: BSD-3-Clause +License: BSD-3-Clause License-File: LICENSE Author: Aleksey Khudyakov Maintainer: Aleksey Khudyakov @@ -43,14 +46,14 @@ common language ---------------------------------------------------------------- Library import: language - Build-Depends: base >=4.14 && <5 - , primitive >=0.6.2 - , vector >=0.13.2 - , containers + Build-Depends: base >=4.14 && <5 + , primitive >=0.6.2 + , vector >=0.13.2 + , containers >=0.5 , process - , transformers - , inline-c >=0.9.1 - , template-haskell + , transformers >=0.4 + , inline-c >=0.9.1 + , template-haskell -any hs-source-dirs: src include-dirs: include c-sources: cbits/python.c @@ -68,6 +71,8 @@ Library Python.Internal.Eval Python.Internal.EvalQQ Paths_inline_python + Autogen-modules: + Paths_inline_python ---------------------------------------------------------------- library test