philips / supernote-obsidian-plugin

Supernote A5, A5X, A6X, A6X2 (Nomad) integration for Obsidian. Generate markdown, capture screen mirror, and more.
MIT License
111 stars 5 forks source link

research: explore using pyodide and supernote-tool #2

Closed philips closed 5 months ago

philips commented 6 months ago

One idea to avoid porting all of @jya-dev 's work on https://github.com/jya-dev/supernote-tool is to use pyodide to pull the python libraries into WASM. It seems most of the dependencies work out of the box: https://github.com/philips/obsidian-plugin-supernote/compare/main...pyodide

philips commented 6 months ago

Hrm, two hurdles looking into this more:

philips commented 6 months ago

Some breadcrumbs from gemini and research:

While esbuild doesn't directly support Pyodide, here's a workaround approach to package your project:

1. Structure Your Project:

project_root/
├── package.json
├── pyodide-lock.json
├── pyodide/
│   ├── pyodide.asm.js
│   ├── pyodide.asm.wasm
│   ├── pyodide.js
│   ├── pyodide.mjs
│   └── python_stdlib.zip
├── src/   (JavaScript source files)
│   └── ...
└── build/ (Destination for bundled files)

2. Install esbuild:

npm install --save-dev esbuild

3. Create a Build Script:

import { build } from 'esbuild';

build({
  entryPoints: ['src/index.js'],  // Adjust based on your entry file
  bundle: true,
  outfile: 'build/bundle.js',
  format: 'esm',
  define: {
    // Define any necessary Pyodide-related globals
    PYODIDE: 'pyodide',  // Example if you're using Pyodide globally
  },
  external: [
    'pyodide/pyodide.asm.js',
    'pyodide/pyodide.asm.wasm',
    'pyodide/pyodide.js',
    'pyodide/pyodide.mjs',
    'pyodide/python_stdlib.zip',
  ],
});

4. Run the Build:

node build.js

5. Serve Bundled Files:

bundle.js
pyodide/
  └── ... (Pyodide files)

Key Considerations:

Esbuild currently doesn't have direct support for integrating Python wheels, including Pyodide wheels. Wheels are designed for installation within a Python environment, not directly in a JavaScript bundler like esbuild.

Here are some alternative approaches to consider:

  1. Serve Wheels Separately:
  1. Explore Alternative Bundlers:
  1. Future Developments:

Remember:

It's best to choose the approach that aligns best with your project's needs and your comfort level with different tools.

philips commented 5 months ago

This is probably not worthwhile now. Closing