Skip to content

Commit 3b77eae

Browse files
committed
first release
1 parent 714a670 commit 3b77eae

24 files changed

Lines changed: 5794 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Run Tests
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
- 'releases/**'
10+
11+
env:
12+
CARGO_NET_GIT_FETCH_WITH_CLI: 'true'
13+
GIT_SSH_COMMAND: 'ssh -o UserKnownHostsFile=/github/home/.ssh/known_hosts -o StrictHostKeyChecking=yes'
14+
15+
jobs:
16+
ci:
17+
name: CI - Node.js ${{ matrix.node-version }} & Python ${{ matrix.python-version }}
18+
runs-on: ubuntu-latest
19+
container:
20+
image: python:${{ matrix.python-version }}-slim
21+
options: --user 0
22+
strategy:
23+
matrix:
24+
node-version: [22, 24]
25+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14-rc']
26+
timeout-minutes: 25
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Install base packages
31+
run: |
32+
apt-get update
33+
apt-get install -y --no-install-recommends \
34+
bash \
35+
ca-certificates \
36+
curl \
37+
gnupg \
38+
git \
39+
openssh-client \
40+
build-essential \
41+
pkg-config \
42+
gdb \
43+
binutils
44+
- name: Setup SSH Agent
45+
uses: webfactory/ssh-agent@v0.9.0
46+
with:
47+
ssh-private-key: |
48+
${{ secrets.SSH_PRIVATE_KEY }}
49+
${{ secrets.HTTP_HANDLER_ACCESS_TOKEN }}
50+
${{ secrets.HTTP_REWRITER_ACCESS_TOKEN }}
51+
- name: Trust internal SSH host aliases
52+
run: |
53+
set -e
54+
mkdir -p ~/.ssh
55+
chmod 700 ~/.ssh
56+
touch ~/.ssh/known_hosts
57+
chmod 644 ~/.ssh/known_hosts
58+
KEY_ENTRY=$(ssh-keyscan github.com 2>/dev/null)
59+
echo "$KEY_ENTRY" >> ~/.ssh/known_hosts
60+
echo "$KEY_ENTRY" | sed 's/^github\.com\([[:space:]]\)/github.com-http-handler\1/' >> ~/.ssh/known_hosts
61+
echo "$KEY_ENTRY" | sed 's/^github\.com\([[:space:]]\)/github.com-http-rewriter\1/' >> ~/.ssh/known_hosts
62+
- uses: actions/setup-node@v5
63+
with:
64+
node-version: ${{ matrix.node-version }}
65+
- name: Restore cached dependencies
66+
uses: actions/cache@v4
67+
with:
68+
path: ~/.pnpm-store
69+
key: node-modules-${{ hashFiles('package.json') }}
70+
- name: Setup pnpm
71+
uses: pnpm/action-setup@v4
72+
with:
73+
version: latest
74+
- name: Set private package config
75+
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
76+
env:
77+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
78+
- name: Configure Python ${{ matrix.python-version }}
79+
run: |
80+
set -euxo pipefail
81+
python --version
82+
python -m ensurepip --upgrade
83+
python -m pip install --upgrade pip
84+
python -m pip --version
85+
echo "PYO3_PYTHON=$(which python)" >> $GITHUB_ENV
86+
- name: Install dependencies
87+
run: pnpm install
88+
- name: Install Rust toolchain
89+
run: |
90+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
91+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
92+
# TODO: remove when using published dependency
93+
- name: Build python-node manually
94+
run: |
95+
# Configure git to use SSH host aliases for private repos (needed by cargo)
96+
git config --global url."ssh://git@github.com-http-handler/platformatic/http-handler".insteadOf "ssh://git@github.com/platformatic/http-handler"
97+
git config --global url."ssh://git@github.com-http-handler/platformatic/http-handler.git".insteadOf "ssh://git@github.com/platformatic/http-handler.git"
98+
git config --global url."ssh://git@github.com-http-rewriter/platformatic/http-rewriter".insteadOf "ssh://git@github.com/platformatic/http-rewriter"
99+
git config --global url."ssh://git@github.com-http-rewriter/platformatic/http-rewriter.git".insteadOf "ssh://git@github.com/platformatic/http-rewriter.git"
100+
101+
cd node_modules/@platformatic/python-node
102+
pnpm install --ignore-scripts
103+
pnpm run build
104+
pnpm run build:wasm
105+
pnpm run build:fix
106+
- name: Run isolated debug test
107+
shell: bash
108+
run: |
109+
export NODE_OPTIONS="--trace-warnings --trace-uncaught --trace-exit --max-old-space-size=4096"
110+
export DEBUG="*"
111+
export NODE_OPTIONS="--trace-warnings --trace-uncaught --trace-exit --max-old-space-size=4096"
112+
export DEBUG="*"
113+
ulimit -c unlimited
114+
sysctl -w kernel.core_pattern=/tmp/core || true
115+
rm -rf core-dumps
116+
mkdir -p core-dumps
117+
set +e
118+
node --trace-warnings --trace-uncaught --trace-exit ./test/debug-isolated.js
119+
status=$?
120+
set -e
121+
if [ "$status" -ne 0 ]; then
122+
echo "Isolated debug test failed with status $status"
123+
echo "Searching for core files..."
124+
find . -maxdepth 5 -type f -name 'core*' \
125+
! -path './core-dumps/*' \
126+
! -path './proc/*' \
127+
-print -exec cp -f {} core-dumps/ \; || true
128+
find /tmp -maxdepth 1 -type f -name 'core*' \
129+
! -path '/tmp/core-dumps/*' \
130+
-print -exec cp -f {} core-dumps/ \; || true
131+
echo "Reproducing crash under gdb for stack trace..."
132+
gdb --batch \
133+
-ex "set pagination off" \
134+
-ex "run" \
135+
-ex "thread apply all bt" \
136+
-ex "generate-core-file core-dumps/core-gdb" \
137+
--args node --trace-warnings --trace-uncaught --trace-exit ./test/debug-isolated.js || true
138+
exit "$status"
139+
fi
140+
- name: Run Full Test Suite
141+
shell: /bin/bash --noprofile --norc -eo pipefail {0}
142+
run: |
143+
set -eux
144+
export NODE_OPTIONS="--trace-warnings --trace-uncaught --trace-exit --max-old-space-size=4096"
145+
export DEBUG="*"
146+
ulimit -c unlimited
147+
sysctl -w kernel.core_pattern=/tmp/core || true
148+
pnpm test || {
149+
echo "Checking for core dumps..."
150+
find . -maxdepth 5 -type f -name 'core*' \
151+
! -path './core-dumps/*' \
152+
! -path './proc/*' \
153+
-print -exec cp -f {} core-dumps/ \; || true
154+
find /tmp -maxdepth 1 -type f -name 'core*' \
155+
! -path '/tmp/core-dumps/*' \
156+
-print -exec cp -f {} core-dumps/ \; || true
157+
echo "Reproducing crash under gdb for stack trace..."
158+
gdb --batch \
159+
-ex "set pagination off" \
160+
-ex "run" \
161+
-ex "thread apply all bt" \
162+
-ex "generate-core-file core-dumps/core-gdb" \
163+
--args node --trace-warnings --trace-uncaught --trace-exit ./test/debug-isolated.js || true
164+
exit 1
165+
}
166+
- name: Upload crash dumps
167+
if: failure()
168+
uses: actions/upload-artifact@v4
169+
with:
170+
name: crash-dumps-${{ matrix.node-version }}-${{ matrix.python-version }}
171+
path: core-dumps
172+
if-no-files-found: warn

.gitignore

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
.DS_Store
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
.pnpm-debug.log*
11+
12+
# Diagnostic reports (https://nodejs.org/api/report.html)
13+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# Snowpack dependency directory (https://snowpack.dev/)
48+
web_modules/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional stylelint cache
60+
.stylelintcache
61+
62+
# Microbundle cache
63+
.rpt2_cache/
64+
.rts2_cache_cjs/
65+
.rts2_cache_es/
66+
.rts2_cache_umd/
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variable files
78+
.env
79+
.env.development.local
80+
.env.test.local
81+
.env.production.local
82+
.env.local
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
out
91+
92+
# Nuxt.js build / generate output
93+
.nuxt
94+
dist
95+
96+
# Gatsby files
97+
.cache/
98+
# Comment in the public line in if your project uses Gatsby and not Next.js
99+
# https://nextjs.org/blog/next-9-1#public-directory-support
100+
# public
101+
102+
# vuepress build output
103+
.vuepress/dist
104+
105+
# vuepress v2.x temp and cache directory
106+
.temp
107+
.cache
108+
109+
# vitepress build output
110+
**/.vitepress/dist
111+
112+
# vitepress cache directory
113+
**/.vitepress/cache
114+
115+
# Docusaurus cache and generated files
116+
.docusaurus
117+
118+
# Serverless directories
119+
.serverless/
120+
121+
# FuseBox cache
122+
.fusebox/
123+
124+
# DynamoDB Local files
125+
.dynamodb/
126+
127+
# TernJS port file
128+
.tern-port
129+
130+
# Stores VSCode versions used for testing VSCode extensions
131+
.vscode-test
132+
133+
# yarn v2
134+
.yarn/cache
135+
.yarn/unplugged
136+
.yarn/build-state.yml
137+
.yarn/install-state.gz
138+
.pnp.*
139+
plt-python
140+
wordpress
141+
142+
package-lock.json
143+
pnpm-lock.yaml
144+
yarn.lock

CLAUDE.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is `@platformatic/python` - a Python stackable for Watt that integrates Python applications with the Platformatic framework. It enables serving Python ASGI applications through a Fastify server with proper request/response handling.
8+
9+
## Development Commands
10+
11+
- `npm test` - Run tests using Node.js built-in test runner
12+
- `npm run build` - Generate schema.json and config.d.ts from schema definitions
13+
- `npm run ci` - Run linting and tests (assumes lint script exists)
14+
15+
## Architecture
16+
17+
The project follows Platformatic's stackable pattern:
18+
19+
### Core Components
20+
21+
- **lib/index.js** - Main stackable export with configuration and plugin registration
22+
- **lib/plugin.js** - Fastify plugin that handles Python request routing and execution
23+
- **lib/generator.js** - Code generator for creating new Python stackable projects
24+
- **lib/schema.js** - JSON schema definitions for configuration validation
25+
26+
### Key Architecture Patterns
27+
28+
1. **Stackable Integration**: Extends `@platformatic/service` with Python-specific functionality
29+
2. **Request Handling**: All HTTP methods are captured by wildcard routes and forwarded to Python via `@platformatic/python-node`
30+
3. **Static File Serving**: Non-Python files in docroot are served statically with `@fastify/static`
31+
4. **Header Processing**: HTTP headers are capitalized for Python compatibility
32+
5. **Configuration Schema**: Uses JSON schema with automatic TypeScript generation
33+
34+
### Generated Project Structure
35+
36+
When using the generator, projects include:
37+
- `public/` directory as Python docroot with `main.py` containing a basic ASGI app
38+
- `platformatic.json` configuration file
39+
- `.env` and `.env.sample` for environment variables
40+
- Node.js v22.18.0+ and Python 3.8+ requirements
41+
42+
### Testing Approach
43+
44+
- Uses Node.js built-in test runner (`node --test`)
45+
- Tests cover generator functionality, configuration validation, and file generation
46+
- Test fixtures in `test/fixtures/` for integration testing

0 commit comments

Comments
 (0)