GithubHelp home page GithubHelp logo

shakfu / py-js Goto Github PK

View Code? Open in Web Editor NEW
88.0 6.0 5.0 19.02 MB

Python3 externals for Max / MSP

License: MIT License

C 25.04% Max 21.70% Python 7.76% Makefile 4.13% Shell 1.01% JavaScript 0.78% Cython 11.70% CMake 1.06% C++ 26.07% HTML 0.60% CSS 0.10% D2 0.03% TeX 0.01%
maxmsp c maxmsp-external max python python3 cpp

py-js's Introduction

py-js: python3 objects for max

Simple (and extensible) python3 externals for MaxMSP.

Cross-platform: currently builds 'natively' on macOS (x86_64 or arm64) and Windows (with MSVC).

repo - https://github.com/shakfu/py-js

py-js test

Preface

This project started out as an attempt (during a covid-19 lockdown) to develop a basic python3 external for Max/MSP. It then evolved into an umbrella project for exploring different ways of using python3 in max.

Along the way, a number of externals have been developed for use in a live Max environment:

Python3 Externals:

name sdk lang description
py max-sdk c well-featured, many packaging options + cython api
pyjs max-sdk c js-friendly -- written as a Max javascript-extension
mamba max-sdk c single-header c library to nest a python3 interpreter in any external
krait max-sdk c++ single-header c++ library to nest a python3 interpreter in any external
cobra max-sdk c python3 external providing deferred and clocked function execution
mxpy max-sdk c a translation of pdpython into Max
zedit max-sdk c a web-based python editor using codemirror and the mongoose embedded webserver.
pymx [2] min-devkit c++ concise, modern, using pybind11

[1] pymx has been moved to its own github project because it uses the min-devkit sdk.

Alternative Python Implementation Externals:

name sdk lang description
pktpy max-sdk c++ uses the pocketpy single-header c++ library
mpy [2] max-sdk c a proof-of-concept embedding micropython

[2] mpy is not enabled by default since it is still in early stages and requires a download of its source. To build it use the -DBUILD_MICROPYTHON_EXTERNAL option with cmake.

ZeroMQ-related Externals

name sdk lang description
jmx max-sdk c explore how to embed a jupyter client or kernel in an external
zpy max-sdk c uses zeromq for 2way-comms with an external python process
zthread max-sdk c exploration of zeromq and Max threads

Note: zeromq externals are not enabled by default since they require zeromq libraries to be installed. To build them use the -DBUILD_ZEROMQ_EXTERNALS option with cmake.

The common objective in these externals is to help use and distribute python code and libraries in Max applications. Many can be considered experimental, with 80% of development time going to the first two externals (py and pyjs). Please see below for an overview and feature comparison.

At the time of this writing, and since the switch to the new max-sdk-base, the project has the following compatibility:

  • macOS: both x86_64 and Apple Silicon compatible. Note that the project intentionally only produces 'native' (x86_64 xor arm64) externals with no current plans for 'fat' or universal externals to serve both architectures. You can download codesigned, notarized x86_64-based and arm64-based python3 externals from the releases section.

  • Windows: windows support was recently provided, and currently all Python3 externals and also the pktpy projects build without issues on Windows. The only caveat is that as of this writing python3 externals are dynamically linked to the local Python3 .dll and are therefore not relocatable. This constraint will be hopefully addressed in future iterations. The pktpy external, however, is fully portable and self-contained.

This README will mostly cover the first two mature externals (py.mxo and pyjs.mxo) and their many build variations available via a custom python-based build system which was specifically developed to cater for different scenerios of packaging and deploying the externals in Max packages and standalones.

If you are interested in any of the other subprojects, please look into the respective folder in the py-js/source/projects section.

The Quickstart section below covers general setup for all of the externals, and will get you up and running with the py and pyjs externals. The Building Experimental Externals using Cmake section provides additional info to build the other remaining externals, and the Building self-contained Python3 Externals for Packages and Standalones section covers more advanced building and deployment scenarios.

Please feel free to ask questions or make suggestions via the project's github issue tracker.

The py and pyjs python3 externals

The following will give you a sense of the feature differences between the two core python3 max externals:

py

A general purpose Max external which embeds a python3 interpreter and is made up of three integrated parts which make it quite straightforward to extend:

  1. The py Max external which is written in c using both the Max c-api and the Python3 c-api.

  2. A pure python module, py_prelude.py which is converted to py_prelude.h and compiled with py and then pre-loaded into the globals() namespace of every py instance.

  3. A builtin api module which is derived from a cython-based wrapper of a subset of the Max c-api.

The following provides a brief view of key attributes and methods:

globals
    obj_count                    : number of active py objects
    registry                     : global registry to lookup object names

patchers
    subpatchers
        py_repl                  : a basic single line repl for py
        py_repl_plus             : embeds a py object in a py_repl

py max external
    attributes
        name                     : unique object name
        file                     : file to load into editor
        autoload                 : load file at start
        pythonpath               : add path to python sys.path
        debug                    : switch debug logging on/off

    methods (messages) 
        core
            import <module>      : python import to object namespace
            eval <expression>    : python 'eval' semantics
            exec <statement>     : python 'exec' semantics
            execfile <path>      : python 'execfile' semantics
        
        extra
            assign <var> [arg]   : max-friendly msg assignments to py object namespace
            call <pyfunc> [arg]  : max-friendly python function calling
            pipe <arg> [pyfunc]  : process py/max value(s) via a pipe of py funcs
            fold <f> <n> [arg]   : applies a two-arg function cumulatively to a sequence
            code <expr|stmt>     : alternative way to eval or exec py code
            anything <expr|stmt> : anything version of the code method 

        time-based
            sched <t> <fn> [arg] : defer a python function call by t millisecs

        code editor
            read <path>          : read text file into editor
            load <path>          : combo of read <path> -> execfile <path>
            run                  : run the current code in the editor
     
        interobject
            scan                 : scan patcher and store names of child objects
            send <msg>           : send an arbitrary message to a named object

        meta
            count                : give a int count of current live py objects

    inlets
        single inlet             : primary input (anything)

    outlets
        left outlet              : primary output (anything)
        middle outlet            : bang on failure
        right outlet             : bang on success 

py-js test_py

pyjs external

General purpose python3 jsextension, which means that it's a c-based Max external which can only be accessed via the javascript js interface.

pyjs max external (jsextension)
    attributes
        name                     : unique object name
        file                     : file to load in object namespace
        pythonpath               : add path to python sys.path
        debug                    : switch debug logging on/off
    
    methods 
        core (messages)
            import <module>      : python import to object namespace
            eval <expression>    : python 'eval' semantics
            exec <stmnt>         : python 'exec' semantics
            execfile <path>      : python 'execfile' semantics
        
        extra
            code <expr|stmt>     : eval/exec/import python code (see above)
            

        in-code (non-message)
            eval_to_json <expr>  : python 'eval' returns json

Quickstart

Windows

Since Windows support still is relatively new, no releases have been made pending further testing.

Currently, the externals which are enabled by default in this project can be built with only a few requirements:

  1. Install Visual Studio Community Edition or use the commercial versions as you like.

  2. Install Python3 for Windows from python.org

  3. (Optional) since Visual Studio has its captive cmake, you can use that, but it is preferable to install cmake independently.

After installation of the above you can build the externals inside your Documents/Max 8/Packages folder as follows:

git clone https://github.com/shakfu/py-js
cd py-js
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release

Open one of the .maxhelp files or any of the files in the patchers folders to see how things work.

macOS

As mentioned earlier, the py and pyjs objects are the most mature and best documented of the collection. Happily, there is also no need to compile them as they are available for download, fully codesigned and notarized, from the releases section.

If you'd rather build them or any of the other externals yourself then the process is straightforward:

  1. You should have a modern python3 cpython implementation installed on your Mac: preferably either from python.org or from Homebrew. Note that even system python3 provided by Apple will work in a number of cases. Python versions from 3.8 to 3.11 are tested and known to work.

  2. Make sure you also have Xcode installed.

  3. Git clone the py-js repo to a path without a space and without possible icloud syncing (i.e don't clone to $HOME/Documents/Max 8/Packages) [?] and run the following in the cloned repo:

    make setup

    The above will initialize and update the required git submodules and symlink the repo to $HOME/Documents/Max 8/Packages/py-js to install it as a Max Package and enable you to test the externals and run the patches.

    [?] It is possible to install py-js directly into $HOME/Documents/Max 8/Packages, but it requires moving the place of compilation to a location in your filesystem that is not exposed to errors due to icloud syncing or spaces in the path. This split is possible, but it is not recommended for the purposes of this quickstart.

  4. Install cython via pip3 install cython, required for translating the cython-based api.pyx, which wraps the the Max c-api, to c.

  5. To build only the py and pyjs externals, type the following in the root directory of the py-js project (other installation options are detailed below):

    make

Note that typing make here is the same as typing make default or make all. This will create two externals py.mxo and pyjs.mxo in your externals folder. These are relatively small in size and are linked to your system python3 installation. This has the immediate benefit that you have access to your curated collection of existing python packages. The tradeoff is that these externals are dynamically linked with local dependencies and therefore not usable in standalones and relocatable Max packages.

No worries, if you need portable relocatable python3 externals for your package or standalone then make sure to read the Building self-contained Python3 Externals for Packages and Standalones section

Open up any of the patch files in the patchers directory of the repo or the generated Max package, and also look at the .maxhelp patchers to understand how the py and the pyjs objects work.

Building Experimental Externals using Cmake

You can also use cmake to build all externals using similar methods to the max-sdk.

First make sure you have completed the Quickstart section above. Next you will install cmake if necessary and a couple of additional dependencies for some of the subprojects. Of course, skip what is already installed:

brew install cmake zmq czmq

Now you can build all externals (including py and pyjs) in one shot using cmake:

make projects

After doing the above, the recommended iterative development workflow is to make changes to the source code in the respective project and then cd py-js/build and cmake --build .. This will cause cmake to only build modified projects efficiently.

Note that for some of the less developed externals and more experimental features please don't be surprised if Max seg-faults (especially if you start experimenting with the cython wrapped api module which operates on the c-level of the Max SDK).

Also note that for py and pyjs externals the cmake build method described does not yet create self-contained python externals which can be used in Max Packages and Standalones.

The following section addresses this requirement.

Building self-contained Python3 Externals for Packages and Standalones

Currently, the py and pyjs externals can be additionally custom-built for the express purpose of packaging these for standalone and Max packages using a custom python build manager. This allows highly-customized build variants to be produced.

The Makefile in the project root provides a simplified interface to this builder. See the Current Status of Builders section for further information.

idx command type format py size pyjs size
1 make static-ext static external 9.0 8.8
2 make static-tiny-ext static external 6.7 6.2 [2]
3 make shared-ext shared external 16.4 15.8
4 make shared-tiny-ext shared external 6.7 6.2 [2]
5 make framework-pkg framework package 22.8 22.8 [3]

[2] These 'tiny' variants are intended to be the smallest possible portable pyjs externals. In this table, size figures are for python 3.10.x but for python 3.11.4 they increase to 8.5 MB and 8.1 respectively. Generally, external size increases with each new python version as features are added, but this is also somewhat mitigated by the removal of deprecated builtin packages and extensions. If you want to achieve the theoreticla minimal size for the py and pyjs externals, use python 3.8.x and/or a tiny variant (with a more recent version). Another option, if you need circa 1 MB size for a self-contained external, look at the pktpy subproject in this repo.

[3] Size, in this case, is not the individual external but the uncompressed size of the package which includes patches, help files and both externals. This can also vary by python version used to compile the external.

This section assumes that you have completed the Quickstart above and have a recent python3 installation (python.org, homebrew or otherwise).

Again, if you'd rather not compile anything there are self-contained python3 externals which can be included in standalones in the releases section.

If you don't mind compiling (and have xcode installed) then pick one of the following options:

  1. To build statically-compiled self-contained python3 externals:

    make static-ext

    You may also prefer the tiny variant:

    make static-tiny-ext
  2. To build self-contained python3 exernals which include a dynamically linked libpythonX.Y.dylib:

    make shared-ext

    or for the corresponding tiny variant:

    make shared-tiny-ext
  3. To build python3 externals in a package, linked to a python installation in its support folder

    make framework-pkg

With all of the above options, a python3 source distribution (matching your own python3 version) is automatically downloaded from python.org with dependencies, and then compiled into a static or shared version of python3 which is then used to compile the externals.

At the end of this process you should find two externals in the py-js/externals folder: py.mxo and pyjs.mxo.

Although the above options deliver somewhat different products (see below for details), with options (1) and (2) the external 'bundle' contains an embedded python3 interpreter with a zipped standard library in the Resources folder and also has a site-packages directory for your own code; with option (3), the externals are linked to, and have been compiled against, a relocatable python3 installation in the support folder.

Depending on your choice above, the python interpreter in each external is either statically compiled or dynamically linked, and in all three cases we have a self-contained and relocatable structure (external or package) without any non-system dependencies. This makes it appropriate for use in Max Packages and Standalones.

There are other build variations which are discussed in more detail below. You can always see which ones are available via typing make help in the py-js project folder:

$ make help

>>> general
make projects             : build all subprojects using standard cmake process

>>> pyjs targets
make                      : non-portable pyjs externals linked to your system
make homebrew-pkg         : portable package w/ pyjs (requires homebrew python)
make homebrew-ext         : portable pyjs externals (requires homebrew python)
make shared-pkg           : portable package with pyjs externals (shared)
make shared-ext           : portable pyjs externals (shared)
make shared-tiny-ext      : tiny portable pyjs externals (shared)
make static-ext           : portable pyjs externals (static)
make static-tiny-ext      : tiny portable pyjs externals (static)
make framework-pkg        : portable package with pyjs externals (framework)
make framework-ext        : portable pyjs externals (framework)
make relocatable-pkg      : portable package w/ more custom options (framework)

>>> python targets
make python-shared        : minimal shared python build
make python-shared-ext    : minimal shared python build for externals
make python-shared-pkg    : minimal shared python build for packages
make python-static        : minimal statically-linked python build
make python-framework     : minimal framework python build
make python-framework-ext : minimal framework python build for externals
make python-framework-pkg : minimal framework python build for packages
make python-relocatable   : custom relocatable python framework build

Automated Test of Build Variations

If you would like to see which build variations are compatible with your current setup, there's an automated test which attempts to compile all build variations in sequence and will log all results to a logs directory:

make test

This can take a long time, but it is worth doing to understand which variants work on your particular setup.

If you want to test or retest one individual variant, just prefix test- to the name of variant as follows:

make test-shared-pkg

Using Self-contained Python Externals in a Standalone (macOS only)

If you have downloaded any pre-built externals from releases or if you have built self-contained python externals as per the methods above, then you should be ready to use these in a standalone.

To release externals in a standalone they must be codesigned and notarized. To this end, there are scripts in py-js/source/projects/py/scripts to make this a little easier.

py.mxo

If you included py.mxo as an external in your standalone, then you should have no issue as Max will install it automatically during its build-as-standalone process.

You can test if it works without issues by building either of these two example patcher documents, included in py-js/patchers, as a max standalone:

  1. py_test_standalone_info_py.maxpat

  2. py_test_standalone_only_py.maxpat

Open the resulting standalone and test that the py object works as expected.

To demonstrate the above, a pre-built standalone that was built using exactly the same steps as above is in the releases section: py_test_standalone_demo.zip.

pyjs.mxo

If you opted to include pyjs.mxo as an external in your standalone, then it may be a litte more involved:

You can first test if it works without issues by building 'a max standalone' from the py_test_standalone_only_pyjs.maxpat patcher whici is included in py-js/patchers.

Open the resulting standalone and test that the pyjs object works as expected. If it doesn't then try the following workaround:

To fix a sometimes recurrent issue where the standalone build algorithm doesn't pick up pyjs.mxo: if you look inside the built standalone bundle, py_test_standalone_only_pyjs.app/Contents/Resources/C74/externals you may not find pyjs.mxo. This is likely a bug in Max 8 but easily resolved. Fix it by manually copying the pyjs.mxo external into this folder and then copy the javascript and jsextensions folders from the root of the py-js project and place them into the pyjs_test_standalone.app/Contents/Resources/C74 folder. Now re-run the standalone app again and now the pyjs external should work. A script is provided in py-js/source/projects/py/scripts/fix-pyjs-standalone.sh to do the above in an automated way.

Please read on for further details about what the py-js externals can do.

Have fun!

Overview

This overview will cover the following two external implementations:

  1. The py external provides a more featureful two-way interface between Max and python in a way that feels natural to both languages.

  2. The pyjs max external/jsextension provides a PyJS class and a minimal subset of the py external's features which work well with the Max js object and javascript code (like returning json directly from evaluations of python expressions).

Both externals have access to builtin python modules and the whole universe of 3rd party modules, and further have the option of importing a builtin api module which uses cython to wrap selective portions of the max c-api. This allows regular python code to directly access the max-c-api and script Max objects.

There are 3 general deployment scenarios:

  1. Linked to system python. Linking the externals to your system python (homebrew, built from source, etc.) This has the benefit of re-using your existing python modules and is the default option.

  2. Embedded in package. Embedding the python interpreter 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) and is linked to the py external or pyjs extension (or both). This makes it size efficient and usable in standalones.

  3. Embedded in external. The external itself as a container for the python interpreter: a custom python distribution (zipped or otherwise) is stored inside the external bundle itself, which can make it portable and usable in standalones.

As of this writing all three deployment scenarios are availabe, however it is worth looking more closely into the tradeoffs in each case, and a number of build variations exist. This topic is treated in more detail below (see Build Variations)

Deployment Scenario py pyjs
Linked to sys python yes yes
Embeddded in package yes yes
Embeddded in external yes yes

Key Features

The py external has the following c-level methods:

category method param(s) in/out can change ns
core import module in yes
core eval expression out no
core exec statement in yes
core execfile file in yes
extra assign var, data in yes
extra call var(s), data out no
extra code expr or stmt out? yes
extra anything expr or stmt out? yes
extra pipe var, funcs out no
extra fold f, n, args out no
time sched ms, fun, args out no
editor read file n/a no
editor load file n/a no
interobj scan n/a no
interobj send name, msg, .. n/a no
meta count n/a no

The pyjs external implements the following c-level methods:

category method param(s) in/out can change ns
core import module in yes
core eval expression out no
core exec statement in yes
core execfile file in yes
extra code expr or stmt out? yes
in-code eval_to_json expression out no

In both cases, the code method allows for import/exec/eval of python code, which can be said to make those 'fit-for-purpose' methods redundant. However, I have retained them since they are stricter in what they allow and further provide a helpful prefix in messages which indicates message intent.

Core

py/js's core features have a one-to-one correspondance to python's very high layer as specified here. In the following, when we refer to object, we refer to instances of either the py or pyjs externals. A note of differences between the variations will be provided below.

  • Per-object namespaces. Each object has a unique name (which is provided automatically or can be set by the user), and responds to an import <module> message which loads the specified python module in its namespace (essentially a globals dictionary). Notably, namespaces can be different for each instance.

  • Eval Messages. Responds to an eval <expression> message in the left inlet which is evaluated in the context of the namespace. py objects output results to the left outlet, send a bang from the right outlet upon success or a bang from the middle outlet upon failure. pyjs objects just return an atomarray of the results.

  • Exec Messages. Responds to an exec <statement> message and an execfile <filepath> message which executes the statement or the file's code in the object's namespace. For py objects, this produces no output from the left outlet, sends a bang from the right outlet upon success or a bang from the middle outlet upon failure. For pyjs objects no output is given.

Extra

The extra category of methods makes the py or pyjs object play nice with the max/msp ecosystem:

Implemented for py objects at present:

  • Assign Messages. Responds to an assign <varname> [x1, x2, ..., xN] which is equivalent to <varname> = [x1, x2, ..., xN] in the python namespace. This is a way of creating variables in the object's python namespace using max message syntax. This produces no output from the left outlet, a bang from the right outlet upon success, or a bang from the middle outlet upon failure.

  • Call Messages. Responds to a call <func> arg1 arg2 ... argN kind of message where func is a python callable in the py object's namespace. This corresponds to the python callable(*args) syntax. This makes it easier to call python functions in a max-friendly way. If the callable does not have variable arguments, it will alternatively try to apply the arguments as a list i.e. call func(args). Future work will try make call correspond to a python generic function call: <callable> [arg1 arg2 ... arg_n] [key1=val1 key2=val2 ... keyN=valN]. This outputs results to the left outlet, a bang from the right outlet upon success, or a bang from the middle outlet upon failure.

  • Pipe message. Like a call in reverse, responds to a pipe <arg> <f1> <f2> ... <fN> message. In this sense, a value is piped through a chain of python functions in the objects namespace and returns the output to the left outlet, a bang from the right outlet upon success, or a bang from the middle outlet upon failure.

Implemented for both py and pyjs objects:

  • Code or Anything Messages. Responds to a code <expression || statement> or (anything) <expression || statement> message. Arbitrary python code (expression or statement) can be used here, because the whole message body is converted to a string, the complexity of the code is only limited by Max's parsing and excaping rules. (EXPERIMENTAL and evolving).

Implemented for pyjs objects only:

  • Evaluate to JSON. Can be used in javascript code only to automatically serialize the results of a python expression as a json string as follows: evaluate_to_json <expression> -> JSON.

Interobject Communication

Implemented for py objects only:

  • Scan Message. Responds to a scan message with arguments. This scans the parent patcher of the object and stores scripting names in the global registry.

  • Send Message. Responds to a send <object-name> <msg> <msg-body> message. Used to send typed messages to any named object. Evokes a scan for the patcher's objects if a registry of names is empty.

Editing Support

Implemented for py objects only.

  • Line REPL. The py object has two bpatcher line repls: one, py_repl_plux.maxpat which embeds a py object and another, py_repl.maxpat which has an outlet to connect to one. The repls include a convenient menu with all of the py object's methods and also feature coll-based history via arrow-up/arrow-down recall of entries in a session. A coll can made to save all commands if required.

  • Multiedit REPL. Another bpatcher, py_multiedit.maxpat, combines a textedit object for writing multiliine python code to be executed in the respective py external's namespace, and a simple line repl strictly for evaluating objects in the namespace.

  • External Editor Filewatcher. py_extedit.maxpat is a bpatcher which wraps the filewatcher object and opens a watched file in an external editor. If the file is saved by the editor, it will be sent out as text via the outlet and can be received, for example, by the py object's inlet, to enable a kind of load-on-save workflow.

  • Code Editor. Double-clicking on the py object opens a code-editor. This is populated by a read message which reads a file into the editor and saves the filepath to the external's attribute. A load message also reads the file followed by execfile. Saving the text in the editor uses the attribute filepath and execs the saved code to the object's namespace.

  • Experimental Remote Console. A method (due to Iain Duncan) of sending code to the py node via udp has been implemented and allows for send-from-editor and send-from-interactive-console capabilities. The clients are still in their infancy, but this method looks promising since you get syntax highlighting, syntax checking, and other features. It assumes you want to treat your py nodes as remotely accessible server/interpreters-in-max.

zedit: [python interpreter / web server] <-> [web-editor / web-console]
  • zedit: a python3 external with an embedded web server. zedit is a python3-enabled external by virtue of using the mamba single-header library and also embeds the mongoose embedded webserver. On the frontend, it uses modern javascript, jquery-terminal and the widely-used code-mirror web text editor widget to create a web-editor / web-console which can be accessed from a browser and which communicates via the mongoose webserver with the underlying python interpreter.

For pyjs objects, code editing is already provided by the js Max object.

Scripting Max with Python via the builtin api module

A subset of the Max c-api is wrapped by the cython-based api module (api.pyx). Prior to compilation it is converted to c and then compiled into the external. This exposes a Python builtin module called api to all python code running on py objects.

The api module includes functions and cython extension classes which make it relatively easy to call Max c-api methods from python. This is without doubt the most powerful feature of the py external.

As of this writing the following extension classes which wrap their corresponding Max datastructures are included in the api module: Atom, AtomArray, Table, Buffer, Dictionary, Database, Linklist, Binbuf, Hashtab and Patcher.

In addition, a cython extension class, PyExternal, gives python code access to the c-based py external's data and methods.

To give a sense of the level of integration which is possible as a result of this module, the following example demonstrates how numpy and scipy.signal can be used to read and write to and from a live Max buffer~ object using the api module's Buffer extension class:

import api

import numpy as np
from scipy import signal

def get_buffer_samples(name: str, sample_file: str) -> np.array:
    buf = api.create_buffer(name, sample_file)
    xs = np.array(buf.get_samples())
    assert len(xs) == buf.n_samples
    api.post(f"get {n_samples} samples from buffer {name}")
    return xs


def set_buffer_samples(name: str, duration_ms: int):
    buf = api.create_empty_buffer(name, duration_ms)
    t = np.linspace(0, 1, buf.n_samples, endpoint=False, dtype=np.float64)
    xs = signal.sawtooth(2 * np.pi * 5 * t)
    buf.set_samples(xs)
    api.post(f"set {buf.n_samples} samples to buffer {name}")

See the examples/tests folder and the patchers/tests folder for more examples.

Packaging

As mentioned previously, the py-js builder subproject be used to build customized python distributions for python3 externals. In addition, it can also package, sign, notarize and deploy the same externals for distribution.

These features are implemented in py-js/source/project/py/builder/packaging.py and are exposed via two interfaces:

The argparse-based interface of builder:

$ python3 -m builder package --help
usage: builder package [-h] [-v VARIANT] [-d] [-k KEYCHAIN_PROFILE]
                           [-i DEV_ID]
                           ...

options:
  -h, --help            show this help message and exit
  -v VARIANT, --variant VARIANT
                        build variant name
  -d, --dry-run         run without actual changes.
  -k KEYCHAIN_PROFILE, --keychain-profile KEYCHAIN_PROFILE
                        Keychain Profile
  -i DEV_ID, --dev-id DEV_ID
                        Developer ID

package subcommands:
  package, sign and release external

                        additional help
    collect_dmg         collect dmg
    dist                create project distribution folder
    dmg                 package distribution folder as .dmg
    notarize_dmg        notarize dmg
    sign                sign all required folders recursively
    sign_dmg            sign dmg
    staple_dmg          staple dmg

The Project's Makefile frontend:

Since the Makefile frontend basically just calls the builder interface in a simplified way, we will use it to explain the basic sequential packaging steps.

  1. Recursively sign all externals in the external folder and/or binaries in the support folder

    make sign
  2. Gather all project resources into a distribution folder and then convert it into a .dmg

    make dmg
  3. Sign the DMG

    make sign-dmg
  4. Notarize the DMG (send it to Apple for validation and notarization)

make notarize-dmg
  1. Staple a valid notarization ticket to the DMG
make staple-dmg
  1. Zip the DMG and collect into in the $HOME/Downloads/PY-JS folder
make collect-dmg

Note that it is important to sign externals (this is done by Xcode automatically) if you want to to distribute to others (or in the case of Apple Silicon, even use yourself). If the externals are signed, then you can proceed to the notarization step if you have an Apple Developer License (100 USD/year) or, alternatively, you can ask users to remove the product's quarantine state or let Max do this automatically on opening the external.

Github Actions

There are a number of Github actions in the project which basically automate the packaging, signing and notarization steps described above.

The only issue is that currently Github only provide x86_64 runners so one has to build for arm64 on a dedicated machine.

Caveats

  • The externals in this project have been mostly developed on MacOS and have not yet been extensively tested on Windows.

  • Despite their relative maturity, the py and pyjs objects are still only v0.2.x and still need further unit/functional/integration/field testing!

  • As of this writing, the api module, does not (like apparently all 3rd party python c-extensions) unload properly between patches and requires a restart of Max to work after you close the first patch which uses it. Unfortunately, this is a known bug in python which is being worked on and may be fixed in future versions (python 3.13 perhaps?).

  • Numpy, the popular python numerical analysis package, falls in the above category. As of python 3.9.x, it thankfully doesn't crash but gives the following error:

[py __main__] import numpy: SystemError('Objects/structseq.c:401: bad argument to internal function')

This just means that the user opened a patch with a py-js external that imports numpy, then closed the patch and (in the same Max session) re-opened it, or created a new patch importing numpy again.

To fix it, just restart Max and use it normally in your patch. Treat each patch as a session and restart Max after each session. It's a pain, but unfortunately a limitation of current python c-extensions.

  • core features relying on pure python code are supposed to be the most stable, and should not crash under most circumstances, extra features are less stable since they are more experimental, etc..

  • The api module is the most experimental and evolving part of this project, and is completely optional. If you don't want to use it, don't import it.

Current Status of Builders

As mentioned earlier, as of this writing this project uses a combination of a Makefile in the project root, a basic cmake build option and a custom python build system, builder, which resides in the py-js/source/py/builder package. The Makefile is a kind of 'frontend' to the more complex python build system. The latter can be used directly of course. A view into its many options can be obtained by typing the following:

cd py-js/source/py
python3 -m builder --help

builder was developed to handle the more complex case of downloading the source code of python (from python.org) and its dependencies from their respective sites and then building custom python binaries with which to reliably compile python3 externals which are portable, relocatable, self-contained, small-in-size, and usable in Max Packages and Standalones.

Build Variations

One of the objectives of this project is to cater to a number of build variations. As of this writing, the following table gives an overview of the different builds and their differences:

There is generally tradeoff of size vs. portability:

build command format size_mb deploy_as pip portable numpy isolated
make framework 0.3 external yes [1] no yes yes
make brew-ext hybrid [3] 13.6 external no yes yes no
make brew-pkg hybrid [3] 13.9 package yes yes yes yes
make static-ext static 9.0 external no yes no [2] yes
make shared-ext shared 15.7 external no yes yes no
make shared-pkg shared 18.7 package yes no [4] yes yes
make framework-ext framework 16.8 external no yes yes no
make framework-pkg framework 16.8 package yes yes yes yes

[1] has automatic access to your system python's site-packages

[2] current static external implementation does not work with numpy due to symbol access issues.

[3] hybrid means that the source system was a framework and the destination system is shared.

[4] the shared-pkg variant does build a compliant 'Framework-type' bundle and hence cannot be notarized.

  • pip: the build allows or provides for pip installation

  • portable: the externals can be deployed as portable packages or standalones

  • numpy: numpy compatibility

  • isolated: if yes, then different external types can run concurrently without issue

Python Version Compatibility

py-js testing

[1] Homebrew only tested on current relase (3.9.10), other versions are expected to work without issues.

[2] Relocatable python can select its own version of python (Only tested with python 3.9.10, other versions should work without issues)

Packages vs Self-contained Externals

The Max package format is a great way to move a bunch of related patches and externals around. This format also makes a lot of sense for py-js, giving a number of advantages over other alternatives:

  1. Portable: Relocatable, you can move it around and it still works.

  2. Extendable: Can include a full fit-for-purpse python3 installation in the support directory with its own site-packages. Packages can be pip installed and all of the site-packages is automatically made available to the thin 'client' python3 externals in the package's externals folder.

  3. Size-efficient, since you don't need to duplicate functionality in each external

  4. Standalone installable: Recent changes in Max have allowed for this to work in standalones. Just create your standalone application from a patcher which which includes the py and pyjs objects. Once it is built into a <STANDALONE> then copy the whole aforementioned py package to <STANDALONE>/Contents/Resources/C74/packages and delete the redundant py.mxo in <STANDALONE>/Contents/Resources/C74/externals since it already exists in the just-copied package.

  5. Better for codesigning / notarizing scenarios since Packages are not sealed bundles like externals.

On the other hand, sometimes you just want an external which embeds a python distribution and custom extensions and code:

  1. Portable: Relocatable, you can move it around and it still works.

  2. Extendable: Can include new pure python code and be provided with new additionas to sys.path

  3. Size-efficient and fit-for-purpose

  4. Standalone installable. Easiest to install in standalones

  5. Can be codesigned and notarized relatively easily. [1]

[1] If you want to codesign and notarize it for use in your standalone or package, the codesigning / notarization script and related entitlements file can be found in the source/py/scripts folder.

The relocatable-python variation

relocatable-python is Greg Neagle's excellent tool for building standalone relocatable Python.framework bundles.

It works so well, that its been included in the builder application as an external (embedded dependency).

It can be seen in the relocatable-pkg make option which will download a nice default Python.framework to the support directory used for compiled both py and pyjs externals:

make relocatable-pkg

More options are available if you use the builder package directly:

$ python3 -m builder pyjs relocatable_pkg --help
usage: __main__.py pyjs relocatable_pkg [-h] [--destination DESTINATION]
                                        [--baseurl BASEURL]
                                        [--os-version OS_VERSION]
                                        [--python-version PYTHON_VERSION]
                                        [--pip-requirements PIP_REQUIREMENTS]
                                        [--pip-modules PIP_MODULES]
                                        [--no-unsign] [--upgrade-pip]
                                        [--without-pip] [--release] [-b] [-i]
                                        [--dump]

optional arguments:
  -h, --help            show this help message and exit
  --destination DESTINATION
                        Directory destination for the Python.framework
  --baseurl BASEURL     Override the base URL used to download the framework.
  --os-version OS_VERSION
                        Override the macOS version of the downloaded pkg.
                        Current supported versions are "10.6", "10.9", and
                        "11". Not all Python version and macOS version
                        combinations are valid.
  --python-version PYTHON_VERSION
                        Override the version of the Python framework to be
                        downloaded. See available versions at
                        https://www.python.org/downloads/mac-osx/
  --pip-requirements PIP_REQUIREMENTS
                        Path to a pip freeze requirements.txt file that
                        describes extra Python modules to be installed. If not
                        provided, no modules will be installed.
  --pip-modules PIP_MODULES
                        list of extra Python modules to be installed.
  --no-unsign           Do not unsign binaries and libraries after they are
                        relocatablized.
  --upgrade-pip         Upgrade pip prior to installing extra python modules.
  --without-pip         Do not install pip.
  --release             set configuration to release
  -b, --build           build python
  -i, --install         install python to build/lib
  --dump                dump project and product vars

Sidenote about building on a Mac

If you are developing the package in $HOME/Documents/Max 8/Packages/py and you have your iCloud drive on for Documents, you will find that make or xcodebuild will reliably fail with 1 error during development, a codesigning error that is due to icloud sync creating detritus in the dev folder. This can be mostly ignored (unless your only focus is codesigning the external).

The solution is to move the external project folder to folder that's not synced-with-icloud (such as $HOME/Downloads for example) and then run xattr -cr . in the project directory to remove the detritus (which ironically Apple's system is itself creating) and then it should succeed (provided you have your Info.plist and bundle id correctly specified). Then just symlink the folder to $HOME/Documents/Max 8/Packages/ to prevent this from recurring.

I've tried this several times and and it works (for "sign to run locally" case and for the "Development" case).

Code Style

The coding style for this project can be applied automatically during the build process with clang-format. On OS X, you can easily install this using brew:

brew install clang-format

The style used in this project is specified in the .clang-format file.

Related projects

  • relocatable-python: A tool for building standalone relocatable Python.framework bundles. (used in this project)

  • python-build-standalone: Produce redistributable builds of Python. (Interesting but not used in this project)

  • Python Apple Support: A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project. (directly inspired static linking approach)

  • python-cmake-buildsystem: A cmake buildsystem for compiling Python. Not currently used in this project, but may be used in the future.

  • py2max : using python3 with Max in an offline capacity to generate max patches.

  • maxutils : scripts and utilities to help with codesigning and notarization of Max standalones and externals.

  • pocketpy: C++17 header-only Python interpreter for game engines.

  • micropython: a lean and efficient Python implementation for microcontrollers and constrained systems

Prior Art and Thanks

py-js testing

I was motivated to start this project because I found myself recurrently wanting to use some python libraries or functions in Max.

Looking around for a python max external I found the following:

  • Thomas Grill's py/pyext โ€“ Python scripting objects for Pure Data and Max is the most mature Max/Python implementation and when I was starting this project, it seemed very promising but then I read that the 'available Max port is not actively maintained.' I also noted that it was written in C++ and that it needed an additional c++ flext layer to compile. I was further dissuaded from diving in as it supported, at the time, only python 2 which seemed difficult to swallow considering Python2 is basically not developed anymore. Ironically, this project has become more active recently, and I finally was persuaded to go back and try to compile it and finally got it running. I found it to be extremely technically impressive work, but it had probably suffered from the burden of having to maintain several moving dependencies (puredata, max, python, flext, c++). The complexity probably put off some possible contributors which would have made the maintenance of the project easier for Thomas. In any case, it's an awesome project and it would be great if this project could somehow help py/ext in some way or the other.

  • max-py -- Embedding Python 2 / 3 in MaxMSP with pybind11. This looks like a reasonable effort, but only 9 commits and no further commits for 2 years as of this writing.

  • nt.python_for_max -- Basic implementation of python in max using a fork of Graham Wakefield's old c++ interface. Hasn't really been touched in 3 years.

  • net.loadbang.jython -- A jython implementation for Max which uses the MXJ java interface. It's looks like a solid effort using Jython 2.7 but the last commit was in 2015.

Around the time of the beginning of my first covid-19 lockdown, I stumbled upon Iain Duncan's Scheme for Max project, and I was quite inspired by his efforts and approach to embed a scheme implementation into a Max external.

So it was decided, during a period with less distractions than usual, to try to make a minimal python3 external, learn the max sdk, the python c-api, and also how to write more than a few lines of c that didn't crash.

It's been an education and I have come to understand precisely a quote I remember somewhere about the c language: that it's "like a scalpel". I now understand this to mean that in skilled hands it can do wonders, otherwise you almost always end up killing the patient.

Thanks to Luigi Castelli for his help with Max/MSP questions, to Stefan Behnel for his help with Cython questions, and to Iain Duncan for providing the initial inspiration and for saving me time with some great implementation ideas.

Thanks to Greg Neagle for zeroing in on the relocatability problem and sharing his elegant solution for Python frameworks via his relocatable-python project on Github.

py-js's People

Contributors

omarcostahamido avatar shakeeb avatar shakfu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

py-js's Issues

errors in compilation of py-js on Mac M1

Dear Shakeeb,
first of all thank you so much for this project. It is really cool! I have a problem in compiling py using my loaded python3 installation (numpy and other packages that I use routinely) but I am running into errors that I am not sure are related to the platform (Mac Book Pro M1) or my not understanding of the process. I am attaching a log of the error, and the slightly modified Makefile (with updated variables for my configuration).
Any help is greatly appreciated!
Thanks,
marco (@marcobn)

Marco Buongiorno Nardelli (he/him)
log.txt
Makefile.txt

Regents Professor, University of North Texas
External Professor, Santa Fe Institute
CEMI, Center for Experimental Music and Intermedia
iARTA, Initiative for Advanced Research in Technology and the Arts
ArtSciLab, ATEC @ the University of Texas at Dallas

http://ermes.unt.edu/
http://www.materialssoundmusic.com/

A more general question on the builder

hi @shakfu!

Came here from our conversation in unloop, which I unfortunately have had to slow down on due to other work I've had to do for grad school.

I wanted to ask about your relocatable python builder (I think it's referred to as relocatable-python by the makefile entrypoint). More specifically, I'd like to be able to build a portable python distribution that I can embed into a VST3 plugin so I can call the gradio-client from the plugin (similar to what I wanted to do with unloop). My VST3 is built using JUCE, using CMake to take care of the build process?

I was wondering if you could point me in the right direction to see if it's possible to embed python in a C++ app w/ a Cmake build system using your builder?

Thanks in advance!

error "make projects" - when building project (after installation)

I followed the Quickstart seemingly successfully.

Then I followed the "Building Experimental Externals using Cmake"

Some externals are successfully build but I also
get the following errors (I include all the execution):

py-js % make projects
Makefile:454: warning: overriding commands for target check' Makefile:248: warning: ignoring old commands for target check'
~/Unity_projects/py-js /Unity_projects/py-js
-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_OSX_ARCHITECTURES set to x86_64
CMAKE_SOURCE_DIR/source/projects/cmx: /Users/soklamon/Unity_projects/py-js/source/projects/cmx
CMAKE_BINARY_DIR}/include: /Users/soklamon/Unity_projects/py-js/build/include
-- Found Python3: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 (found version "3.11.4") found components: Interpreter Development Development.Module Development.Embed
CMAKE_LIBRARY_OUTPUT_DIRECTORY: /Users/soklamon/Unity_projects/py-js/source/projects/py/../../../externals
CMAKE_CURRENT_BINARY_DIR: /Users/soklamon/Unity_projects/py-js/build/source/projects/py
Python3_VERSION: 3.11.4
Python3_VERSION_MAJOR: 3
Python3_VERSION_MINOR: 11
Python3_FOUND: TRUE
Python3_Interpreter_FOUND: TRUE
Python3_Development_FOUND: TRUE
Python3_EXECUTABLE: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
Python3_INTERPRETER_ID: Python
Python3_STDARCH: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11
Python3_STDLIB: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11
Python3_SITELIB: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
Python3_SITEARCH: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages
Python3_SOABI: cpython-311-darwin
Python3_LIBRARIES: /Library/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib
Python3_INCLUDE_DIRS: /Library/Frameworks/Python.framework/Versions/3.11/include/python3.11
Python3_LINK_OPTIONS: LINKER:-rpath,/Library/Frameworks
Python3_LIBRARY_DIRS: /Library/Frameworks/Python.framework/Versions/3.11/lib
Python3_RUNTIME_LIBRARY_DIRS: /Library/Frameworks/Python.framework/Versions/3.11/lib
using standard local configuration
using standard local configuration
-- Configuring done (4.5s)
-- Generating done (0.2s)
-- Build files have been written to: /Users/soklamon/Unity_projects/py-js/build
[ 3%] Building C object source/projects/cmx/CMakeFiles/cmx.dir/cmx.c.o
[ 6%] Linking C static library libcmx.a
[ 6%] Built target cmx
[ 10%] Building C object source/projects/demo/CMakeFiles/demo.dir/demo.c.o
[ 13%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/demo.mxo/Contents/MacOS/demo
Copy PkgInfo
[ 13%] Built target demo
[ 17%] Building CXX object source/projects/krait/CMakeFiles/krait.dir/krait.cpp.o
[ 20%] Linking CXX CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/krait.mxo/Contents/MacOS/krait
Copy PkgInfo
[ 20%] Built target krait
[ 24%] Building C object source/projects/mamba/CMakeFiles/mamba.dir/mamba.c.o
[ 27%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/mamba.mxo/Contents/MacOS/mamba
Copy PkgInfo
[ 27%] Built target mamba
[ 31%] Building C object source/projects/mxpy/CMakeFiles/mxpy.dir/mxpy.c.o
[ 34%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/mxpy.mxo/Contents/MacOS/mxpy
Copy PkgInfo
[ 34%] Built target mxpy
[ 37%] Building CXX object source/projects/pktpy/CMakeFiles/pktpy.dir/pktpy.cpp.o
[ 41%] Linking CXX CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/pktpy.mxo/Contents/MacOS/pktpy
Copy PkgInfo
[ 41%] Built target pktpy
[ 41%] Built target api_c
[ 44%] Building C object source/projects/py/CMakeFiles/py.dir/py.c.o
[ 48%] Building C object source/projects/py/CMakeFiles/py.dir/api.c.o
/Users/soklamon/Unity_projects/py-js/source/projects/py/api.c:26131:21: warning: fallthrough annotation in unreachable code [-Wunreachable-code-fallthrough]
CYTHON_FALLTHROUGH;
^
/Users/soklamon/Unity_projects/py-js/source/projects/py/api.c:345:34: note: expanded from macro 'CYTHON_FALLTHROUGH'
#define CYTHON_FALLTHROUGH attribute((fallthrough))
^
/Users/soklamon/Unity_projects/py-js/source/projects/py/api.c:26142:21: warning: fallthrough annotation in unreachable code [-Wunreachable-code-fallthrough]
CYTHON_FALLTHROUGH;
^
/Users/soklamon/Unity_projects/py-js/source/projects/py/api.c:345:34: note: expanded from macro 'CYTHON_FALLTHROUGH'
#define CYTHON_FALLTHROUGH attribute((fallthrough))
^
2 warnings generated.
[ 51%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/py.mxo/Contents/MacOS/py
Copy PkgInfo
[ 55%] Built target py
[ 58%] Building C object source/projects/pyjs/CMakeFiles/pyjs.dir/pyjs.c.o
[ 62%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/pyjs.mxo/Contents/MacOS/pyjs
Copy PkgInfo
[ 62%] Built target pyjs
[ 65%] Building CXX object source/projects/shell/CMakeFiles/shell.dir/shell.cpp.o
[ 68%] Linking CXX CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/shell.mxo/Contents/MacOS/shell
Copy PkgInfo
[ 68%] Built target shell
[ 72%] Building C object source/projects/zpy/CMakeFiles/zpy.dir/zpy.c.o
[ 75%] Building C object source/projects/zpy/CMakeFiles/zpy.dir///max-sdk-base/c74support/max-includes/common/commonsyms.c.o
[ 79%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/zpy.mxo/Contents/MacOS/zpy
ld: warning: dylib (/usr/local/lib/libczmq.dylib) was built for newer macOS version (13.0) than being linked (12.0)
ld: warning: dylib (/usr/local/lib/libzmq.dylib) was built for newer macOS version (13.0) than being linked (12.0)
ld: warning: dylib (/usr/local/lib/libsodium.dylib) was built for newer macOS version (13.0) than being linked (12.0)
Copy PkgInfo
[ 79%] Built target zpy
[ 82%] Building C object source/projects/zthread/CMakeFiles/zthread.dir/zthread.c.o
[ 86%] Building C object source/projects/zthread/CMakeFiles/zthread.dir///max-sdk-base/c74support/max-includes/common/commonsyms.c.o
[ 89%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/zthread.mxo/Contents/MacOS/zthread
ld: warning: dylib (/usr/local/lib/libzmq.dylib) was built for newer macOS version (13.0) than being linked (12.0)
ld: warning: dylib (/usr/local/lib/libsodium.dylib) was built for newer macOS version (13.0) than being linked (12.0)
Copy PkgInfo
[ 89%] Built target zthread
[ 93%] Building C object source/projects/zedit/CMakeFiles/zedit.dir/mongoose.c.o
[ 96%] Building C object source/projects/zedit/CMakeFiles/zedit.dir/zedit.c.o
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:113:23: warning: unused variable 'toggle' [-Wunused-variable]
t_object *toggle, *metro;
^
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:113:32: warning: unused variable 'metro' [-Wunused-variable]
t_object *toggle, *metro;
^
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:119:13: warning: code will never be executed [-Wunreachable-code]
newobject_fromboxtext(patcher, "cycle
440");
^~~~~~~~~~~~~~~~~~~~~
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:112:13: note: silence by adding parentheses to mark code as explicitly dead
if (1) {
^
/* DISABLES CODE / ( )
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:460:9: warning: code will never be executed [-Wunreachable-code]
systhread_mutex_lock(x->x_mutex);
^~~~~~~~~~~~~~~~~~~~
/Users/soklamon/Unity_projects/py-js/source/projects/zedit/zedit.c:34:20: warning: unused variable 's_enable_hexdump' [-Wunused-variable]
static const char
s_enable_hexdump = "no";
^
5 warnings generated.
[100%] Linking C CFBundle shared module /Users/soklamon/Unity_projects/py-js/externals/zedit.mxo/Contents/MacOS/zedit
Copy PkgInfo
[100%] Built target zedit
~/Unity_projects/py-js

Max crash while loading or executing Python scripts

Hi
Thanks for the amazing work. It's really something that is missing for Max users!

I have been playing around with the externals, either from package or compiled, on my 2015 MacBook with 10.15 (used make homebrew-ext). While sending messages to the py object, Max has crashed:

Max(45323,0x1119fbdc0) malloc: *** error for object 0x12695e1d0: pointer being freed was not allocated

The patch is pretty basic, just the minimum to test the possibilities of py-js and python.
Any hint is welcome.

py-js

feature request | buffer~ support

Hi,

This is quite literally insane work and very good. I've been trying it out and it's really nice having the ability to sign atoms as well as define handlers, much like js.

To me this is basically a Python object done right :)

One thing that for me would be especially useful for machine learning skullduggery would be a buffer~ interface to both read/write buffer data from Python. How feasible is something like this? Can I help in any way? Certainly not a C++ expert but if you point me in the right places I can certainly have a crack.

Py object not found

Hi there, I hope I shouldn't have commented in the closed thread because my issue would definitely be classified as newbie question. I've checked the other threads but unless I don't think I've seen a solution to the issue I'm having.

I am just trying to get the Py external installed but having problems. I am getting this error in the Max console and the Py object appears in an orange box.

'py: py: No such object'

I am using a 2020 M1 Macbook. I have tried using several different released versions of your externals. I also built my own but none of them are working. PyJS seems to be loading fine although I've not experimented with it yet. I'm probably making some minor rookie error but some guidance would be much appreciated. Thank you!

crash building from source and max 8.6

Hi again,

I go on holidays and wanted to do some experimentation with py-js. I just compiled from source 017400bf5971fe363b4687ece66c851c91e5651c and the object crashes as soon as I open the help file. Are you able to repro on your end?

newbie questions

Hi @shakfu
What a great repo!
I have some newbie questions if you don't mind me asking:

  • is this mac os only?
  • does it only work with homebrew python installation or vanilla python from python.org also works?
  • does it actually embeds python into the external or is the external connecting to local python installation?
  • could you add a simple list of dependencies to the readme?
  • any reason why you can't provide already compiled max externals?
    • I know you probably don't want to populate the repo history with it but you could always add them to a release?
  • does this work with python packages?
    • is it possible to provide an example that installs for example numpy and makes use of it?

Thank you for your attention and sorry for the long list of questions.
Best,
OCH

Compilation on Apple Silicon

Hi, great take with this package!
I tried recompiling the objects myself since I'm on ARM and the building script provided throws:

~/GitHub/py-js/source/py/pyjs.c:5:10: fatal error: 'Python.h' file not found #include <Python.h> ^~~~~~~~~~ 1 error generated.

I also tried regenerating the build files using cmake -g Xcode which gives the following error:

-- Updating Git Submodules building on Git rev : 259e877 Git tag : pre-release0 Generating Info.plist Generating: pymx -- Min-Lib found CMake Error at source/projects/pymx/CMakeLists.txt:10 (find_package): By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "pybind11", but CMake did not find one. Could not find a package configuration file provided by "pybind11" with any of the following names: pybind11Config.cmake pybind11-config.cmake Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set "pybind11_DIR" to a directory containing one of the above files. If "pybind11" provides a separate development package or SDK, be sure it has been installed. -- Configuring incomplete, errors occurred!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.