Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/2026-12-06-device-send-windows-paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Developer tools: `scripts/device-send.py` now reaches the unit queue on Windows when Node or the repository sits in a folder with a space (such as `C:\Users\Jo Doe`). It used to stop with `Cannot find module` because Windows passed the path to Node split in two.
14 changes: 12 additions & 2 deletions scripts/device-send.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
if not node:
raise SystemExit('The unit queue needs Node on PATH (scripts/unit-queue.mjs); for an emulator, set MODWERK_UNIT=emulator.')
here = os.path.abspath(__file__)
os.execv(node, [node, os.path.join(os.path.dirname(here), 'unit-queue.mjs'), 'run', '--unit', 'octatrack', '--note', ('device-send ' + line)[:120],
'--expect', '2m', '--steps', line, '--', sys.executable, '-B', here] + sys.argv[1:])
command = [node, os.path.join(os.path.dirname(here), 'unit-queue.mjs'), 'run', '--unit', 'octatrack', '--note', ('device-send ' + line)[:120],
'--expect', '2m', '--steps', line, '--', sys.executable, '-B', here] + sys.argv[1:]
if os.name != 'nt':
os.execv(node, command)
# Windows execv joins the arguments unquoted, so a path with a space ("C:\Users\Jo Doe") reaches Node split in two.
import subprocess
child = subprocess.Popen(command)
while True:
try:
raise SystemExit(child.wait())
except KeyboardInterrupt:
pass # Ctrl+C reaches the queue as well: it rolls back the trial and ends in its own time.
path = os.environ.get('MODWERK_DEV_SOCKET', '/tmp/modwerk-dev.sock')
# A port number is TCP on this computer (Windows Python has no AF_UNIX), anything else a Unix socket.
s = socket.socket(socket.AF_INET) if path.isdigit() else socket.socket(socket.AF_UNIX)
Expand Down
33 changes: 33 additions & 0 deletions scripts/device-send.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { spawnSync } from 'node:child_process'
import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'

const python = process.platform === 'win32' ? 'python' : 'python3'
const source = fileURLToPath(new URL('./device-send.py', import.meta.url))
let root

afterEach(() => { if (root) rmSync(root, { recursive: true, force: true }) })

describe('device-send.py', () => {
// Windows os.execv joins its arguments unquoted: from a folder with a space ("C:\Users\Jo Doe") Node got a split path.
it('hands its line to the unit queue intact from a path with a space, and ends with the queue\'s code', () => {
root = mkdtempSync(join(tmpdir(), 'device send '))
const scripts = join(root, 'with space', 'scripts')
mkdirSync(scripts, { recursive: true })
copyFileSync(source, join(scripts, 'device-send.py'))
writeFileSync(join(scripts, 'unit-queue.mjs'), 'console.log(JSON.stringify(process.argv.slice(2))); process.exit(3)\n')
const env = { ...process.env }
delete env.MODWERK_UNIT_TURN
delete env.MODWERK_UNIT
const result = spawnSync(python, ['-B', join(scripts, 'device-send.py'), 'press PLAY', 'a "quoted" word'], { encoding: 'utf8', env })
expect(result.stderr).toBe('')
expect(result.status).toBe(3)
const args = JSON.parse(result.stdout)
expect(args.slice(0, 4)).toEqual(['run', '--unit', 'octatrack', '--note'])
expect(args).toContain('press PLAY a "quoted" word')
expect(args.slice(args.indexOf('--') + 2)).toEqual(['-B', join(scripts, 'device-send.py'), 'press PLAY', 'a "quoted" word'])
})
})
Loading