Skip to content

Commit

Permalink
Add python port.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Jan 30, 2025
1 parent 6ff649f commit cae5ed4
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export GUILE_WARN_DEPRECATED='detailed'
# Uses --no-grafts option in order to avoid conflicts between duplicated versions

# Build
guix build metacall --fallback -L /metacall/nonguix -L /metacall/source
guix build metacall metacall-python-port --fallback -L /metacall/nonguix -L /metacall/source

# Install
echo 'metacall' >> /metacall/source/metacall.scm
Expand All @@ -39,7 +39,7 @@ guix lint -L /metacall/nonguix -L /metacall/source metacall
# Pack
guix pack --no-grafts \
-S /gnu/bin=bin -S /gnu/etc=etc -S /gnu/lib=lib -S /gnu/include=include -S /gnu/share=share \
-RR metacall nss-certs \
-RR metacall metacall-python-port nss-certs \
-L /metacall/nonguix -L /metacall/source | tee build.log

# Copy
Expand Down
11 changes: 6 additions & 5 deletions scripts/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ cd /metacall/nonguix
git checkout e0951349603581895e0ba61f0e7410368ea1902a # Fix nonguix version
apk del git-deps

# Build (i386 workaround for NodeJS)
if [[ "${TARGETPLATFORM:-}" == "linux/386" ]]; then
guix install --fallback --without-tests=node node-lts
guix install --fallback --without-tests=node-lts libnode
fi
# TODO:
# # Build (i386 workaround for NodeJS)
# if [[ "${TARGETPLATFORM:-}" == "linux/386" ]]; then
# guix install --fallback --without-tests=node node-lts
# guix install --fallback --without-tests=node-lts libnode
# fi

# Build
guix build --fallback \
Expand Down
18 changes: 18 additions & 0 deletions source/metacall.scm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#:use-module (guix build-system gnu)
#:use-module (guix build-system cmake)
#:use-module (guix build-system node)
#:use-module (guix build-system python)
#:use-module (guix build json)
#:use-module (guix build union)
#:use-module ((guix licenses) #:prefix license:)
Expand Down Expand Up @@ -520,3 +521,20 @@ methods or procedures between programming languages.
With METACALL you can transparently execute code from / to any
programming language, for example, call Python code from NodeJS code.")
(license license:asl2.0)))

; MetaCall Python Port
; TODO: Can it be unified with metacall package?
; https://www.futurile.net/2024/07/23/guix-package-structure-build-system-phases/
(define-public metacall-python-port
(package
(inherit metacall)
(name "metacall-python-port")
(build-system python-build-system)
(arguments
`(#:tests? #f
#:phases (modify-phases %standard-phases
(add-before 'build 'change-directory
(lambda _
(chdir "source/ports/py_port")))
(delete 'test))))
(inputs (list metacall))))
14 changes: 11 additions & 3 deletions tests/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ RUN echo "Running tests ${CACHE_INVALIDATE}" \
| grep -e 'function add(a, b)' -e 'function mult(a, b)' \
&& printf "load py sum.py\ninspect\nexit" \
| metacallcli \
| grep -e 'function sum(a, b, c)'
| grep -e 'function sum(a, b, c)' \
&& metacallcli port-test.js \
| grep "Node.js port works" \
&& metacallcli port-test.py \
| grep "Python port works"

# | grep -e 'function sum(a, b, c)' \
# TODO: C# Loader
# && printf "load cs say.cs\ninspect\nexit" \
# | metacallcli || cat /root/metacall.log
# | metacallcli

# TODO: Ruby Port
# && metacallcli port-test.rb \
# | grep "Ruby port works"

ENTRYPOINT ["sh", "-c"]
25 changes: 25 additions & 0 deletions tests/scripts/port-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

/*
* MetaCall Distributable by Parra Studios
* Distributable infrastructure for MetaCall.
*
* Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

const { metacall } = require('metacall');

console.log("Node.js port works");
24 changes: 24 additions & 0 deletions tests/scripts/port-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

#
# MetaCall Distributable by Parra Studios
# Distributable infrastructure for MetaCall.
#
# Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import metacall

print("Python port works")
24 changes: 24 additions & 0 deletions tests/scripts/port-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby

#
# MetaCall Distributable by Parra Studios
# Distributable infrastructure for MetaCall.
#
# Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'metacall'

puts "Ruby port works"

0 comments on commit cae5ed4

Please sign in to comment.