Skip to content

Commit 9c55af3

Browse files
committed
refactor: read whole scaffold object instead of only dtypes
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 6dc4f19 commit 9c55af3

File tree

5 files changed

+315
-186
lines changed

5 files changed

+315
-186
lines changed

lib/node_modules/@stdlib/math/special/fibonacci/scripts/script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
var join = require( 'path' ).join;
2626
var readJSON = require( '@stdlib/fs/read-json' ).sync;
2727
var db = require( '@stdlib/math/special/scripts/function_database.json' );
28-
var dtypesDatabase = require( '@stdlib/math/special/scripts/dtypes_database.json' );
28+
var scaffoldDatabase = require( '@stdlib/math/special/scripts/scaffold_database.json' );
2929
var dtypes = require( '@stdlib/ndarray/dtypes' );
3030
var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' );
3131
var mostlySafeCasts = require( '@stdlib/ndarray/mostly-safe-casts' );
@@ -118,8 +118,8 @@ function selectKernelName( inputDtype, outputDtype, scalarKernel, kernelList ) {
118118
* scalarKernel = '@stdlib/math/base/special/cfloorf'
119119
*/
120120

121-
scalarKernelInputDtype = dtypesDatabase[ scalarKernel ].input[ 0 ]; // dtypesDatabase[ '@stdlib/math/base/special/cfloorf' ].input[ 0 ] => 'complex64'
122-
scalarKernelOutputDtype = dtypesDatabase[ scalarKernel ].output[ 0 ]; // dtypesDatabase[ '@stdlib/math/base/special/cfloorf' ].output[ 0 ] => 'complex64'
121+
scalarKernelInputDtype = scaffoldDatabase[ scalarKernel ].parameters[ 0 ].type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].parameters[ 0 ].type.dtype => 'complex64'
122+
scalarKernelOutputDtype = scaffoldDatabase[ scalarKernel ].returns.type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].returns.type.dtype => 'complex64'
123123

124124
// Exact match:
125125
if ( inputDtype === scalarKernelInputDtype && outputDtype === scalarKernelOutputDtype ) {

lib/node_modules/@stdlib/math/special/floor/scripts/script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
var join = require( 'path' ).join;
2626
var readJSON = require( '@stdlib/fs/read-json' ).sync;
2727
var db = require( '@stdlib/math/special/scripts/function_database.json' );
28-
var dtypesDatabase = require( '@stdlib/math/special/scripts/dtypes_database.json' );
28+
var scaffoldDatabase = require( '@stdlib/math/special/scripts/scaffold_database.json' );
2929
var dtypes = require( '@stdlib/ndarray/dtypes' );
3030
var dtypeChar = require( '@stdlib/ndarray/base/dtype-char' );
3131
var mostlySafeCasts = require( '@stdlib/ndarray/mostly-safe-casts' );
@@ -118,8 +118,8 @@ function selectKernelName( inputDtype, outputDtype, scalarKernel, kernelList ) {
118118
* scalarKernel = '@stdlib/math/base/special/cfloorf'
119119
*/
120120

121-
scalarKernelInputDtype = dtypesDatabase[ scalarKernel ].input[ 0 ]; // dtypesDatabase[ '@stdlib/math/base/special/cfloorf' ].input[ 0 ] => 'complex64'
122-
scalarKernelOutputDtype = dtypesDatabase[ scalarKernel ].output[ 0 ]; // dtypesDatabase[ '@stdlib/math/base/special/cfloorf' ].output[ 0 ] => 'complex64'
121+
scalarKernelInputDtype = scaffoldDatabase[ scalarKernel ].parameters[ 0 ].type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].parameters[ 0 ].type.dtype => 'complex64'
122+
scalarKernelOutputDtype = scaffoldDatabase[ scalarKernel ].returns.type.dtype; // scaffoldDatabase[ '@stdlib/math/base/special/cfloorf' ].returns.type.dtype => 'complex64'
123123

124124
// Exact match:
125125
if ( inputDtype === scalarKernelInputDtype && outputDtype === scalarKernelOutputDtype ) {

lib/node_modules/@stdlib/math/special/scripts/dtypes_database.json

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

lib/node_modules/@stdlib/math/special/scripts/generate_dtypes_database.js renamed to lib/node_modules/@stdlib/math/special/scripts/generate_scaffolds_database.js

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,76 +29,49 @@ var writeFile = require( '@stdlib/fs/write-file' ).sync;
2929
var exists = require( '@stdlib/fs/exists' ).sync;
3030
var objectKeys = require( '@stdlib/utils/keys' );
3131
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
32-
var isArray = require( '@stdlib/assert/is-array' );
33-
var functionDatabase = require( './function_database.json' );
32+
var functionDatabase = require( '@stdlib/math/special/scripts/function_database.json' );
3433

3534

3635
// FUNCTIONS //
3736

3837
/**
39-
* Extracts dtypes from a package's package.json file.
38+
* Extracts scaffold metadata from a package's package.json file.
4039
*
4140
* @private
4241
* @param {string} pkgPath - package path
43-
* @returns {Array} array containing input and output dtypes
42+
* @returns {Object} scaffold object
4443
*
4544
* @example
46-
* var dtypes = extractDtypes( '@stdlib/math/base/special/sqrt' );
47-
* // returns [ ['float64'], ['float64'] ]
45+
* var scaffold = extractScaffold( '@stdlib/math/base/special/sqrt' );
46+
* // returns { 'parameters': [...], 'returns': {...} }
4847
*/
49-
function extractDtypes( pkgPath ) {
48+
function extractScaffold( pkgPath ) {
5049
var packageJsonPath;
51-
var outputDtypes;
52-
var inputDtypes;
53-
var scaffold;
5450
var content;
55-
var param;
5651
var path;
5752
var pkg;
58-
var i;
5953

6054
// Convert @stdlib/math/base/special/sqrt to lib/node_modules/@stdlib/math/base/special/sqrt:
6155
path = pkgPath.replace( '@stdlib/', '' );
6256
packageJsonPath = join( resolve( __dirname, '../../..' ), path, 'package.json' );
6357

6458
if ( !exists( packageJsonPath ) ) {
65-
return [];
59+
return {};
6660
}
6761

6862
content = readFile( packageJsonPath, 'utf8' );
6963
if ( content instanceof Error ) {
70-
return [];
64+
return {};
7165
}
7266

7367
pkg = JSON.parse( content );
7468

75-
// Look for dtypes in __stdlib__.scaffold:
69+
// Return the complete scaffold object:
7670
if ( pkg[ '__stdlib__' ] && pkg[ '__stdlib__' ].scaffold ) {
77-
scaffold = pkg[ '__stdlib__' ].scaffold;
78-
inputDtypes = [];
79-
outputDtypes = [];
80-
81-
// Extract input dtypes:
82-
if ( scaffold.parameters && isArray( scaffold.parameters ) ) {
83-
for ( i = 0; i < scaffold.parameters.length; i++ ) {
84-
param = scaffold.parameters[ i ];
85-
if ( param.type && param.type.dtype ) {
86-
inputDtypes.push( param.type.dtype );
87-
}
88-
}
89-
}
90-
91-
// Extract output dtypes:
92-
if ( scaffold.returns && scaffold.returns.type ) {
93-
if ( scaffold.returns.type.dtype ) {
94-
outputDtypes.push( scaffold.returns.type.dtype );
95-
}
96-
}
97-
98-
return [ inputDtypes, outputDtypes ];
71+
return pkg[ '__stdlib__' ].scaffold;
9972
}
10073

101-
return [];
74+
return {};
10275
}
10376

10477

@@ -111,19 +84,19 @@ function extractDtypes( pkgPath ) {
11184
*/
11285
function main() {
11386
var scalarKernelNames;
114-
var dtypesDatabase;
87+
var scaffoldDatabase;
11588
var scalarKernels;
11689
var jsonContent;
11790
var outputPath;
11891
var functions;
92+
var scaffold;
11993
var pkgPath;
120-
var dtypes;
12194
var func;
12295
var pkg;
12396
var i;
12497
var j;
12598

126-
dtypesDatabase = {};
99+
scaffoldDatabase = {};
127100

128101
// Get all function names:
129102
functions = objectKeys( functionDatabase );
@@ -139,24 +112,21 @@ function main() {
139112
pkgPath = scalarKernels[ pkg ];
140113

141114
// Skip if we already processed this package:
142-
if ( hasOwnProp( dtypesDatabase, pkgPath ) ) {
115+
if ( hasOwnProp( scaffoldDatabase, pkgPath ) ) {
143116
continue;
144117
}
145118

146-
dtypes = extractDtypes( pkgPath );
119+
scaffold = extractScaffold( pkgPath );
147120

148-
if ( dtypes.length > 0 ) {
149-
dtypesDatabase[ pkgPath ] = {
150-
'input': dtypes[ 0 ],
151-
'output': dtypes[ 1 ]
152-
};
121+
if ( scaffold ) {
122+
scaffoldDatabase[ pkgPath ] = scaffold;
153123
}
154124
}
155125
}
156126

157127
// Write the dtypes database to file:
158-
outputPath = join( __dirname, 'dtypes_database.json' );
159-
jsonContent = JSON.stringify( dtypesDatabase, null, 2 );
128+
outputPath = join( __dirname, 'scaffold_database.json' );
129+
jsonContent = JSON.stringify( scaffoldDatabase, null, 2 );
160130

161131
writeFile( outputPath, jsonContent );
162132
}

0 commit comments

Comments
 (0)