Skip to content

Commit 590fc30

Browse files
committed
Add documentation to nodejs port and python port about metacall cli for launching the scripts. EnaAdapt python port to the new way of install distributable tarballs.
1 parent 56d47ec commit 590fc30

File tree

6 files changed

+112
-44
lines changed

6 files changed

+112
-44
lines changed

source/ports/node_port/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ metacall_load_from_file('py', [ 'sum.py' ]);
3636

3737
metacall('sum', 3, 4); // 7
3838
```
39+
40+
``` sh
41+
metacall node main.js
42+
```

source/ports/py_port/package/README.rst

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,42 @@ Programming Language. With **METACALL** Python Port you can
1212
transparently execute code from Python to any programming language, for
1313
example, calling JavaScript, NodeJS, Ruby or C# code from Python.
1414

15+
Install
16+
========
17+
18+
Install MetaCall binaries first:
19+
20+
.. code:: console
21+
22+
curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash
23+
24+
Then install Python package:
25+
1526
.. code:: console
1627
1728
pip install metacall
1829
19-
``sum.js``
30+
Example
31+
========
32+
33+
``multiply.rb``
2034

21-
.. code:: javascript
35+
.. code:: ruby
2236
23-
module.exports = function sum(a, b) {
24-
return a + b;
25-
};
37+
def multiply(left, right)
38+
return left * right
39+
end
2640
2741
``main.py``
2842

2943
.. code:: python
3044
3145
from metacall import metacall_load_from_file, metacall
3246
33-
metacall_load_from_file('node', [ 'sum.js' ]);
47+
metacall_load_from_file('rb', [ 'multiply.rb' ]);
48+
49+
metacall('multiply', 3, 4); # 12
50+
51+
.. code:: console
3452
35-
metacall('sum', 3, 4); # 7
53+
metacall py main.py

source/ports/py_port/package/helper/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20+
# TODO: Update to the new install / distributable tarballs
21+
2022
import sys
2123
import os
2224
import re
@@ -223,7 +225,7 @@ def uninstall_prompt():
223225
* this action DOES NOT uninstall the python package, only MetaCall CLI and MetaCall libs
224226
* for a complete uninstall you have to run metacall-uninstall && pip uninstall metacall
225227
* (the order of execution is important)
226-
228+
227229
Proceed (y/n)? '''.format(''.join('''{}\n '''.format(l) for l in paths))
228230

229231
answers = {'yes': True, 'y': True, 'no': False, 'n': False}

source/ports/py_port/package/metacall/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@
1919

2020
import os
2121
import sys
22+
import re
2223

23-
sys.path.append(os.environ.get('PORT_LIBRARY_PATH', '/usr/local/lib'));
24+
# Append environment variable or default install path when building manually (TODO: Cross-platform paths)
25+
sys.path.append(os.environ.get('PORT_LIBRARY_PATH', os.path.join(os.path.sep, 'usr', 'local', 'lib')));
26+
27+
# Find is MetaCall is installed as a distributable tarball (TODO: Cross-platform paths)
28+
rootdir = os.path.join(os.path.sep, 'gnu', 'store')
29+
regex = re.compile('.*-metacall-.*')
30+
31+
for root, dirs, _ in os.walk(rootdir):
32+
for folder in dirs:
33+
if regex.match(folder) and not folder.endswith('R'):
34+
sys.path.append(os.path.join(rootdir, folder, 'lib'))
2435

2536
try:
2637
from _py_port import * # TODO: Import only the functions that will be exported
2738
except ImportError as e:
2839
try:
40+
print('Error when importing MetaCall Python Port:', e);
2941
from _py_portd import * # TODO: Import only the functions that will be exported
30-
except ImportError as ed:
31-
print("MetaCall Core is not correctly installed:", e, "-", ed)
42+
print('MetaCall Python Port Debug Imported');
43+
except ImportError as e:
44+
print('\x1b[31m\x1b[1m', 'You do not have MetaCall installed or we cannot find it (', e, ')\x1b[0m');
45+
print('\x1b[33m\x1b[1m', 'If you do not have it installed, you have three options:', '\x1b[0m');
46+
print('\x1b[1m', ' 1) Go to https://github.com/metacall/install and install it.', '\x1b[0m');
47+
print('\x1b[1m', ' 2) Contribute to https://github.com/metacall/distributable by providing support for your platform and architecture.', '\033[0m');
48+
print('\x1b[1m', ' 3) Be a x10 programmer and compile it by yourself, then define the install folder (if it is different from the default /usr/local/lib) in os.environ[\'LOADER_LIBRARY_PATH\'].', '\x1b[0m');
49+
print('\x1b[33m\x1b[1m', 'If you have it installed in an non-standard folder, please define os.environ[\'LOADER_LIBRARY_PATH\'].', '\x1b[0m');
3250
pass
51+
52+
# TODO: Monkey patch

source/ports/py_port/package/setup.py

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from codecs import open
2222
import os
2323
import sys
24+
import re
2425

2526
# Always prefer setuptools over distutils
2627
from setuptools import setup, find_packages
@@ -38,7 +39,7 @@
3839
# Versions should comply with PEP440. For a discussion on single-sourcing
3940
# the version across setup.py and the project code, see
4041
# https://packaging.python.org/en/latest/single_source_version.html
41-
'version': '0.1.11',
42+
'version': '0.1.17',
4243

4344
'description': 'A library for providing inter-language foreign function interface calls',
4445
'long_description': long_description,
@@ -117,7 +118,17 @@
117118
# Detect if metacall port is already installed
118119
port_installed = False
119120

120-
sys.path.append(os.environ.get('PORT_LIBRARY_PATH', '/usr/local/lib'));
121+
# Append environment variable or default install path when building manually (TODO: Cross-platform paths)
122+
sys.path.append(os.environ.get('PORT_LIBRARY_PATH', os.path.join(os.path.sep, 'usr', 'local', 'lib')));
123+
124+
# Find is MetaCall is installed as a distributable tarball (TODO: Cross-platform paths)
125+
rootdir = os.path.join(os.path.sep, 'gnu', 'store')
126+
regex = re.compile('.*-metacall-.*')
127+
128+
for root, dirs, _ in os.walk(rootdir):
129+
for folder in dirs:
130+
if regex.match(folder) and not folder.endswith('R'):
131+
sys.path.append(os.path.join(rootdir, folder, 'lib'))
121132

122133
# Find if module is installed
123134
if sys.version_info[0] < 3:
@@ -149,29 +160,36 @@
149160
py_port = importlib.util.find_spec("_py_portd")
150161
port_installed = py_port is not None
151162

152-
if port_installed == True:
153-
# Exclude helper package if port is already installed
154-
exclude_packages.append('helper')
155-
else:
156-
# List run-time dependencies here. These will be installed by pip when
157-
# your project is installed. For an analysis of "install_requires" vs pip's
158-
# requirements files see:
159-
# https://packaging.python.org/en/latest/requirements.html
160-
options['install_requires'] = ['peppercorn', 'requests']
161-
162-
# Define install hooks
163-
# TODO
164-
165-
# To provide executable scripts, use entry points in preference to the
166-
# "scripts" keyword. Entry points provide cross-platform support and allow
167-
# pip to create the appropriate form of executable for the target platform.
168-
options['entry_points'] = {
169-
'console_scripts': [
170-
'metacall-install=helper:install',
171-
'metacall-uninstall=helper:uninstall_prompt',
172-
'metacall-update=helper:update'
173-
],
174-
}
163+
# TODO: This code is very interesting for providing commands to the end user.
164+
# pip cannot execute arbitrary code as pre/post install hook when the package is being installed.
165+
# So it is impossible to install the binaries unless we add extra commands after install.
166+
# At this moment there is a common solution for installing binaries depending on Bash/PowerShell
167+
# that is OS dependant and not language dependant. By the moment we will use the new way of install
168+
# instead of the old one, but we keep the ./helper folder in order to provide future support for
169+
# extra commands, although the main idea is to keep the OS dependant install, this can be useful
170+
# for updating or doing Python related things. Meanwhile, it will be avoided.
171+
exclude_packages.append('helper')
172+
173+
# if port_installed == True:
174+
# # Exclude helper package if port is already installed
175+
# exclude_packages.append('helper')
176+
# else:
177+
# # List run-time dependencies here. These will be installed by pip when
178+
# # your project is installed. For an analysis of "install_requires" vs pip's
179+
# # requirements files see:
180+
# # https://packaging.python.org/en/latest/requirements.html
181+
# options['install_requires'] = ['peppercorn', 'requests']
182+
183+
# # To provide executable scripts, use entry points in preference to the
184+
# # "scripts" keyword. Entry points provide cross-platform support and allow
185+
# # pip to create the appropriate form of executable for the target platform.
186+
# options['entry_points'] = {
187+
# 'console_scripts': [
188+
# 'metacall-install=helper:install',
189+
# 'metacall-uninstall=helper:uninstall_prompt',
190+
# 'metacall-update=helper:update'
191+
# ],
192+
# }
175193

176194
# Define required packages
177195
options['packages'] = find_packages(exclude=exclude_packages)

source/ports/py_port/package/upload.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@
1919
# limitations under the License.
2020
#
2121

22-
# Install dependencies
23-
python3 -m pip install --user --upgrade twine setuptools wheel
22+
# TODO: Update version in setup.py
23+
# TODO: Automate for CD/CI
2424

25-
# Upload MetaCall package
26-
python3 setup.py sdist bdist_wheel
27-
python3 -m twine check dist/*
28-
python3 -m twine upload dist/*
25+
# Define exit code
26+
fail=0
27+
28+
# Install dependencies and upload MetaCall package
29+
python3 -m pip install --user --upgrade twine setuptools wheel \
30+
&& python3 setup.py sdist bdist_wheel \
31+
&& python3 -m twine check dist/* \
32+
&& python3 -m twine upload dist/* || fail=1
2933

3034
# Delete output
31-
rm -rf dist/*
32-
rm -rf build/*
35+
rm -rf dist/* build/* || fail=1
36+
37+
# Exit
38+
exit ${fail}

0 commit comments

Comments
 (0)