Skip to content

Commit 3e6c5a3

Browse files
committed
more docs for pyjs
1 parent 4f4e9e8 commit 3e6c5a3

File tree

2 files changed

+59
-27
lines changed

2 files changed

+59
-27
lines changed

README.md

+58-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# py: minimal python3 object for max
1+
# py/js: python3 objects for max
22

3-
An attempt to make a simple (and extensible) max external for python3
3+
Simple (and extensible) python3 externals for max accessible via patch or js objects
44

5-
repo - https://github.com/shakfu/py
5+
repo - https://github.com/shakfu/py-js
66

77

88
## Summary
@@ -17,9 +17,9 @@ patchers
1717
py_repl : a basic single line repl for py
1818
py_repl_plus : embeds a py object in a py_repl
1919
20-
py interpreter object
20+
py max external
2121
attributes
22-
name : unique name
22+
name : unique object name
2323
file : file to load into editor
2424
autoload : load file at start
2525
pythonpath : add path to python sys.path
@@ -57,27 +57,56 @@ py interpreter object
5757
left outlet : primary output (anything)
5858
middle outlet : bang on failure
5959
right outlet : bang on success
60+
61+
62+
pyjs max external (jsextension)
63+
attributes
64+
name : unique object name
65+
file : file to load in object namespace
66+
pythonpath : add path to python sys.path
67+
debug : switch debug logging on/off
68+
69+
methods
70+
core
71+
code <expr|stmt> : eval/exec/import python code (see above)
72+
execfile <path> : python 'execfile' semantics
73+
74+
6075
```
6176

6277
## Overview
6378

64-
The `py` object provides a minimal, high level two-way interface between max and python in a way that feels natural to both languages.
79+
`py/js`, started out as an attempt (during a covid-19 lockdown), to get a basic python3 external for max, and then evolved into a flexible framework for using python3 in max.
80+
81+
There are two implementation 'flavours':
82+
83+
1. The `py` external provides a minimal, high level two-way interface between max and python in a way that feels natural to both languages.
84+
85+
2. The `pyjs` max jsextension provides a `PyJS` class for the `js` object, which makes available a python intepreter which works nicely with javascript code. This 'flavour' is new, and still under development, so documentation will be minimal. The
86+
87+
In addition there are essentially 3 deployment variations:
88+
89+
1. `py` external or `pyjs` jsextension which links to a system installed python (homebrew, builtin python, or custom system installed.) This has the benefit of re-using your existing libraries. This is the default option.
6590

66-
It really is conceived as a flexible framework which can be customized depending on the requirement.
91+
2. `py` external or `pyjs` jsextension in a Max package: in this variation, a dedicated python distribution (zipped or otherwise is placed in the `support` folder of the `py/js` package (or any other package) is linked to the `py` external or `pyjs` extension (or both). This can possibly make it usable in standalones (untested).
6792

68-
To this end there are essentially 3 deployment flavours:
93+
3. `py` external or `pyjs` jsextension as a container for a python distribution. In this variation, a whole python distribution (zipped or otherwise) is stored inside the external/jsextension object, which can makes it very portable and usable in standalones.
6994

70-
1. `py` external which links to a system installed python (homebrew, builtin python, or custom system installed.) This has the benefit of re-using your existing libraries. This is the default option.
7195

72-
2. `py` external in a Max package: in this variation, a dedicated python distribution (zipped or otherwise is placed in the `support` folder of the `py` package (or any other package) is linked to the `py` external. This can possibly make it usable in standalones (untested).
96+
Deployment Scenario | `py` | `pyjs`
97+
:------------------- | :--: | :--------:
98+
Link to sys python | x | x
99+
Embed in package | x | untested
100+
Embed in external | x | untested
73101

74-
3. `py` external as a container for a python distribution. In this variation, a whole python distribution (zipped or otherwise) is stored inside the external object, which can make it very portable and usable in standalones.
102+
In addition, to the deployment variations above, onc can choose to use the cython-generated max c-api wrapper or not, which allows regular python code to directly access the max-c-api and script Max objects.
75103

76104

77-
In addition, to the variations above, onc can choose to use the cython-generated max c-api wrapper or not, which allows regular python to script Max objects.
78105

79-
Otherwise using plain-vanilla python in Max is also quite usable due to the availability of the following methods:
106+
### Key Features
107+
80108

109+
The more mature `py` external has the following c-level methods:
81110

82111
category | method | param(s) | in/out | can change ns
83112
:------- | :--------| :------------ | :----: | :------------:
@@ -97,7 +126,14 @@ interobj | send | name, msg, .. | n/a | no
97126
meta | count | | n/a | no
98127

99128

100-
### Key Features
129+
The more recently developed `pyjs` external implements the following c-level methods:
130+
131+
category | method | param(s) | in/out | can change ns
132+
:------- | :--------| :------------ | :----: | :------------:
133+
core | code | expr or stmt | out? | yes
134+
core | execfile | file | in | yes
135+
136+
The `code` method (also available the `py` object in a more experimental category) which can import/exec/eval python code is 'core' in this implementation.
101137

102138

103139
#### Core
@@ -300,7 +336,10 @@ The style used in this project is specified in the `.clang-format` file.
300336

301337
## BUGS
302338

303-
- [ ] Sending from the `api` can make max unstable. Keep it simple and investigate.
339+
- [ ] no-return ops in`pyjs` such as `exec` and `import` somehow make java assume an error has occured.
340+
341+
- [ ] `api` object won't reload if a patch is closed (i.e. PyFinalize) and new one opened. Requires a restart of Max. (Python bug which is being worked on).
342+
304343

305344
## TODO
306345

@@ -309,6 +348,7 @@ The style used in this project is specified in the `.clang-format` file.
309348

310349
- [ ] enhance `call` to allow kwargs [call fn x1 x2 y1=z1 y2=z2]
311350

351+
312352
### Extension
313353

314354
- [ ] add more api wrappers.
@@ -329,12 +369,8 @@ The style used in this project is specified in the `.clang-format` file.
329369

330370
### Future Experiments
331371

332-
- [ ] Convert `py` into a `js` extension class
333-
- proof of concept done, but requires a different 'nobox' type of class and data passing via arrays and attributes instead of outlets. But can be done!
334-
335-
- [ ] Try to launch an ipython shell somehow
372+
- [ ] Try to integrate an ipython shell somehow
336373

337-
- [ ] try to build a cython extension type as a max external class (-:
338374

339375
## CHANGELOG
340376

@@ -347,6 +383,8 @@ The style used in this project is specified in the `.clang-format` file.
347383

348384
##### Core
349385

386+
- [x] Convert `py` into a `jsextension` class
387+
350388
- [x] create new `py_anything` with heuristics to decide whether to delegate to `py_call` or `py_code`.
351389

352390
- [x] add `autoload` attribute to trigger autoload (`load` msg) of code editor code

jsextensions/maxclasswrap.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/*
22
3-
This is a just a placeholder.
4-
5-
Wrapping an external for js usage requires that the output
6-
function is changed to returm arrays instead of pushing to
7-
outlets.
8-
9-
TBD later (maybe)
3+
Wraps the pyjs external for use by the js object in max
104
115
*/
126

0 commit comments

Comments
 (0)