Skip to content

Commit 60a3e97

Browse files
Merge pull request #12 from transitive-bullshit/feature/sklearn-1.5.2
2 parents 9b4e40a + a70e2a8 commit 60a3e97

File tree

867 files changed

+123178
-155221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

867 files changed

+123178
-155221
lines changed

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"root": true,
3+
"extends": ["@fisch0920/eslint-config/node"],
4+
"ignorePatterns": ["packages/sklearn/src/generated"],
5+
"rules": {
6+
"unicorn/no-array-reduce": "off",
7+
"unicorn/filename-case": "off",
8+
"array-callback-return": "off"
9+
}
10+
}

.github/workflows/test.yml

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,20 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
node-version:
13-
- 19
14-
- 18
15-
- 16
12+
node-version: [lts/*]
1613
python-version:
17-
- '3.11'
14+
- '3.13'
1815

1916
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v4
22-
23-
- name: Install Node.js
24-
uses: actions/setup-node@v3
25-
with:
26-
node-version: ${{ matrix.node-version }}
27-
28-
- name: Install pnpm
29-
uses: pnpm/action-setup@v2
30-
id: pnpm-install
17+
- uses: actions/checkout@v4
18+
- uses: pnpm/action-setup@v4
3119
with:
32-
version: 8
20+
version: 9
3321
run_install: false
34-
35-
- name: Get pnpm store directory
36-
id: pnpm-cache
37-
shell: bash
38-
run: |
39-
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
40-
41-
- uses: actions/cache@v3
42-
name: Setup pnpm cache
22+
- uses: actions/setup-node@v4
4323
with:
44-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
45-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
46-
restore-keys: |
47-
${{ runner.os }}-pnpm-store-
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'pnpm'
4826

4927
- name: Install Python
5028
uses: actions/setup-python@v4
@@ -56,7 +34,7 @@ jobs:
5634
run: pip install numpy scikit-learn
5735

5836
- name: Install Node.js dependencies
59-
run: pnpm install --frozen-lockfile
37+
run: pnpm install --frozen-lockfile --strict-peer-dependencies
6038

6139
- name: Run test
62-
run: pnpm run test
40+
run: pnpm test

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
enable-pre-post-scripts=true
22
ignore-workspace-root-check=true
3+
package-manager-strict=false

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ node_modules/
66
.vercel/
77
third-party/
88
out/
9-
packages/sklearn/src/generated/
9+
packages/sklearn/src/generated/

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"singleQuote": true,
3+
"jsxSingleQuote": true,
4+
"semi": false,
5+
"useTabs": false,
6+
"tabWidth": 2,
7+
"bracketSpacing": true,
8+
"bracketSameLine": false,
9+
"arrowParens": "always",
10+
"trailingComma": "none"
11+
}

.prettierrc.cjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

bin/generate-sklearn.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'node:fs/promises'
22
import path from 'node:path'
33

4-
import mkdir from 'mkdirp'
54
import pMap from 'p-map'
65

76
import { formatSource } from '../src/formatter'
@@ -13,7 +12,7 @@ import {
1312

1413
async function main() {
1514
const outDir = path.join('packages', 'sklearn', 'src', 'generated')
16-
await mkdir(outDir)
15+
await fs.mkdir(outDir, { recursive: true })
1716

1817
// 487 total definitions
1918
// 228 functions
@@ -24,8 +23,8 @@ async function main() {
2423
// console.log(JSON.stringify(scikitDocUrls, null, 2))
2524

2625
const sources = scikitDocUrls.filter((url) => {
27-
const nameParts = url.split('/').slice(-1)[0].split('.')
28-
const name = nameParts.slice(-2)[0]
26+
const nameParts = url.split('/').at(-1).split('.')
27+
const name = nameParts.at(-2)
2928
if (name.toLowerCase() === name) {
3029
// TODO: likely a function
3130
// console.log('skipping', nameParts.slice(0, -1).join('.'))
@@ -38,12 +37,14 @@ async function main() {
3837
// return
3938

4039
// const sources = [
41-
// 'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html'
40+
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html'
41+
// 'https://scikit-learn.org/stable/modules/generated/sklearn.utils.metadata_routing.MetadataRouter.html'
42+
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html',
4243
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html',
4344
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html',
4445
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html',
4546
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html',
46-
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html'
47+
// // 'https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html'
4748
// ]
4849

4950
console.log(`\nfetching ${sources.length} docs...\n`)
@@ -74,12 +75,12 @@ async function main() {
7475
console.log(`\nprocessing ${docs.length} docs...\n`)
7576
// console.log(
7677
// JSON.stringify(
77-
// docs.map((doc) => doc.name.split('.').slice(-1)[0]),
78+
// docs.map((doc) => doc.name.split('.').at(-1)),
7879
// null,
7980
// 2
8081
// )
8182
// )
82-
// // console.log(JSON.stringify(docs[0], null, 2))
83+
// console.log(JSON.stringify(docs[0], null, 2))
8384

8485
const errors: string[] = []
8586
const generatedDirs: any = {}
@@ -99,10 +100,10 @@ async function main() {
99100
const fileName = `${doc.name}.ts`
100101
const namespaceDirs = doc.namespace.split('.').slice(1)
101102
const destDir = path.join(outDir, ...namespaceDirs)
102-
await mkdir(destDir)
103+
await fs.mkdir(destDir, { recursive: true })
103104

104105
const filePath = path.join(destDir, fileName)
105-
await fs.writeFile(filePath, source, 'utf-8')
106+
await fs.writeFile(filePath, source, 'utf8')
106107

107108
let generatedDir = generatedDirs
108109
for (const dir of namespaceDirs) {
@@ -158,7 +159,7 @@ async function main() {
158159
const source = await formatSource(indexFileSource)
159160
const fileName = 'index.ts'
160161
const filePath = path.join(destDir, fileName)
161-
await fs.writeFile(filePath, source, 'utf-8')
162+
await fs.writeFile(filePath, source, 'utf8')
162163
console.log(filePath)
163164
}
164165

@@ -179,7 +180,7 @@ If you found this project helpful, please consider [donating to the official sci
179180

180181
const fileName = 'readme.md'
181182
const filePath = path.join(destDir, fileName)
182-
await fs.writeFile(filePath, readmeFileSource, 'utf-8')
183+
await fs.writeFile(filePath, readmeFileSource, 'utf8')
183184
console.log(filePath)
184185
}
185186
}
@@ -195,4 +196,4 @@ If you found this project helpful, please consider [donating to the official sci
195196
)
196197
}
197198

198-
main()
199+
await main()

bin/playground.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as sklearn from 'sklearn'
33
async function main() {
44
const py = await sklearn.createPythonBridge()
55

6-
const v = [
6+
const _v = [
77
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
88
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
99
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
@@ -52,4 +52,4 @@ async function main() {
5252
await py.disconnect()
5353
}
5454

55-
main()
55+
await main()

bin/transform-docs.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import fs from 'node:fs/promises'
22
import path from 'node:path'
33

44
import { globby } from 'globby'
5-
import mkdir from 'mkdirp'
65
import pMap from 'p-map'
76

87
async function main() {
98
const srcDocsDir = path.join('packages', 'sklearn', 'docs')
109
const outDir = path.join('docs', 'pages', 'docs')
11-
await mkdir(outDir)
10+
await fs.mkdir(outDir, { recursive: true })
1211

1312
const docs = (
1413
await globby('**/*.md', {
@@ -45,7 +44,7 @@ async function main() {
4544
async (doc) => {
4645
console.log(`processing ${doc.relativePath}`)
4746

48-
let out = await fs.readFile(doc.srcPath, 'utf-8')
47+
let out = await fs.readFile(doc.srcPath, 'utf8')
4948

5049
out =
5150
out
@@ -54,11 +53,16 @@ async function main() {
5453
'Defined in: $1'
5554
)
5655
// TODO: handle relative links
57-
.replaceAll(/\[([^\]]+)\]\((\.\.[^\)]+)\)/g, '$1')
56+
.replaceAll(/\[([^\]]+)]\((\.\.[^)]+)\)/g, '$1')
5857
.replaceAll('[Readme](readme.md)', '')
58+
.replaceAll(/#+ Parameters/g, '**Parameters**')
59+
.replaceAll(/#+ Returns\n\n/gm, '**Returns** ')
60+
.replaceAll(/#+ Defined in\n\n/gm, '**Defined in** ')
61+
.replaceAll(/#+ Get Signature/g, '**Get Signature**')
62+
.replaceAll(/#+ Set Signature/g, '**Set Signature**')
5963
.trim() + '\n'
6064

61-
if (doc.relativePath === 'modules.md') {
65+
if (doc.relativePath === 'globals.md') {
6266
out = out.replaceAll(/### Variables\b/g, '### Constants')
6367
}
6468

@@ -74,62 +78,55 @@ async function main() {
7478
metaMap.variables.push(doc.relativePath)
7579
}
7680

77-
await mkdir(path.dirname(doc.destPath))
78-
await fs.writeFile(doc.destPath, out, 'utf-8')
81+
await fs.mkdir(path.dirname(doc.destPath), { recursive: true })
82+
await fs.writeFile(doc.destPath, out, 'utf8')
7983
},
8084
{
8185
concurrency: 8
8286
}
8387
)
8488

8589
{
86-
// top-level nextra _meta.json file
90+
// top-level nextra _meta.ts file
8791
const docsMeta = {
88-
modules: 'Table of Contents',
92+
globals: 'Table of Contents',
8993
classes: 'Classes',
9094
functions: 'Functions',
91-
interfaces: {
92-
title: 'Interfaces',
95+
'type-aliases': 'Types',
96+
variables: 'Constants',
97+
README: {
9398
display: 'hidden'
94-
},
95-
types: 'Types',
96-
variables: 'Constants'
99+
}
97100
}
98101

99102
await fs.writeFile(
100-
path.join(outDir, '_meta.json'),
101-
JSON.stringify(docsMeta, null, 2),
102-
'utf-8'
103+
path.join(outDir, '_meta.ts'),
104+
`export default ${JSON.stringify(docsMeta, null, 2)}`,
105+
'utf8'
103106
)
104107
}
105108

106-
// sub nextra _meta.json files
109+
// sub nextra _meta.ts files
107110
await pMap(
108111
Object.keys(metaMap),
109112
async (key) => {
110113
const values = metaMap[key]
111-
.map((value) => value.split('/').slice(-1)[0].split('.')[0].trim())
114+
.map((value) => value.split('/').at(-1).split('.')[0].trim())
112115
.filter(Boolean)
113116
.sort((a, b) => a.localeCompare(b))
114117

115118
if (!values.length) {
116119
return
117120
}
118121

119-
const meta = values.reduce(
120-
(acc, value) => ({
121-
...acc,
122-
[value]: value
123-
}),
124-
{}
125-
)
122+
const meta = Object.fromEntries(values.map((value) => [value, value]))
126123

127124
const destDir = path.join(outDir, key)
128125

129126
await fs.writeFile(
130-
path.join(path.join(destDir, '_meta.json')),
131-
JSON.stringify(meta, null, 2),
132-
'utf-8'
127+
path.join(path.join(destDir, '_meta.ts')),
128+
`export default ${JSON.stringify(meta, null, 2)}`,
129+
'utf8'
133130
)
134131
},
135132
{
@@ -138,4 +135,4 @@ async function main() {
138135
)
139136
}
140137

141-
main()
138+
await main()

contributing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Contributing
2+
3+
## TODO
4+
5+
## Node.js
6+
7+
- install pnpm
8+
9+
## Python
10+
11+
- install poetry
12+
13+
https://scipy.github.io/devdocs/building/index.html#system-level-dependencies
14+
15+
```sh
16+
brew install scipy
17+
```
18+
19+
```sh
20+
poetry install
21+
```

0 commit comments

Comments
 (0)