Skip to content

Commit 2690737

Browse files
authored
Merge pull request #29 from arduino/skip-unix-packages
Exclude unix packages
2 parents 15943aa + 44c988f commit 2690737

File tree

2 files changed

+88
-194
lines changed

2 files changed

+88
-194
lines changed

micropython-lib.yaml

-162
Original file line numberDiff line numberDiff line change
@@ -647,165 +647,3 @@ packages:
647647
index: https://micropython.org/pi/v2
648648
author: MicroPython
649649
description: Compression and decompression using the deflate algorithm
650-
- name: cgi
651-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/cgi
652-
index: https://micropython.org/pi/v2
653-
author: MicroPython
654-
- name: email.charset
655-
docs: >-
656-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.charset
657-
index: https://micropython.org/pi/v2
658-
author: MicroPython
659-
- name: email.encoders
660-
docs: >-
661-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.encoders
662-
index: https://micropython.org/pi/v2
663-
author: MicroPython
664-
- name: email.errors
665-
docs: >-
666-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.errors
667-
index: https://micropython.org/pi/v2
668-
author: MicroPython
669-
- name: email.feedparser
670-
docs: >-
671-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.feedparser
672-
index: https://micropython.org/pi/v2
673-
author: MicroPython
674-
- name: email.header
675-
docs: >-
676-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.header
677-
index: https://micropython.org/pi/v2
678-
author: MicroPython
679-
- name: email.internal
680-
docs: >-
681-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.internal
682-
index: https://micropython.org/pi/v2
683-
author: MicroPython
684-
- name: email.message
685-
docs: >-
686-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.message
687-
index: https://micropython.org/pi/v2
688-
author: MicroPython
689-
- name: email.parser
690-
docs: >-
691-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.parser
692-
index: https://micropython.org/pi/v2
693-
author: MicroPython
694-
- name: email.utils
695-
docs: >-
696-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/email.utils
697-
index: https://micropython.org/pi/v2
698-
author: MicroPython
699-
- name: fcntl
700-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/fcntl
701-
index: https://micropython.org/pi/v2
702-
author: MicroPython
703-
- name: ffilib
704-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/ffilib
705-
index: https://micropython.org/pi/v2
706-
author: MicroPython
707-
description: >-
708-
MicroPython FFI helper module to easily interface with underlying shared
709-
libraries
710-
- name: getopt
711-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/getopt
712-
index: https://micropython.org/pi/v2
713-
author: MicroPython
714-
- name: gettext
715-
docs: >-
716-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/gettext
717-
index: https://micropython.org/pi/v2
718-
author: MicroPython
719-
- name: glob
720-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/glob
721-
index: https://micropython.org/pi/v2
722-
author: MicroPython
723-
- name: html.entities
724-
docs: >-
725-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/html.entities
726-
index: https://micropython.org/pi/v2
727-
author: MicroPython
728-
- name: html.parser
729-
docs: >-
730-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/html.parser
731-
index: https://micropython.org/pi/v2
732-
author: MicroPython
733-
- name: http.client
734-
docs: >-
735-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/http.client
736-
index: https://micropython.org/pi/v2
737-
author: MicroPython
738-
- name: json
739-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/json
740-
index: https://micropython.org/pi/v2
741-
author: MicroPython
742-
- name: machine
743-
docs: >-
744-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/machine
745-
index: https://micropython.org/pi/v2
746-
author: MicroPython
747-
- name: multiprocessing
748-
docs: >-
749-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/multiprocessing
750-
index: https://micropython.org/pi/v2
751-
author: MicroPython
752-
- name: os
753-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/os
754-
index: https://micropython.org/pi/v2
755-
author: MicroPython
756-
- name: pwd
757-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/pwd
758-
index: https://micropython.org/pi/v2
759-
author: MicroPython
760-
- name: pyusb
761-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/pyusb
762-
index: https://micropython.org/pi/v2
763-
author: MicroPython
764-
- name: re
765-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/re
766-
index: https://micropython.org/pi/v2
767-
author: MicroPython
768-
- name: select
769-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/select
770-
index: https://micropython.org/pi/v2
771-
author: MicroPython
772-
- name: signal
773-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/signal
774-
index: https://micropython.org/pi/v2
775-
author: MicroPython
776-
- name: socket
777-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/socket
778-
index: https://micropython.org/pi/v2
779-
author: MicroPython
780-
- name: sqlite3
781-
docs: >-
782-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/sqlite3
783-
index: https://micropython.org/pi/v2
784-
author: MicroPython
785-
- name: test.support
786-
docs: >-
787-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/test.support
788-
index: https://micropython.org/pi/v2
789-
author: MicroPython
790-
- name: time
791-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/time
792-
index: https://micropython.org/pi/v2
793-
author: MicroPython
794-
- name: timeit
795-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/timeit
796-
index: https://micropython.org/pi/v2
797-
author: MicroPython
798-
- name: tty
799-
docs: https://github.com/micropython/micropython-lib/tree/master/unix-ffi/tty
800-
index: https://micropython.org/pi/v2
801-
author: MicroPython
802-
- name: ucurses
803-
docs: >-
804-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/ucurses
805-
index: https://micropython.org/pi/v2
806-
author: MicroPython
807-
- name: urllib.parse
808-
docs: >-
809-
https://github.com/micropython/micropython-lib/tree/master/unix-ffi/urllib.parse
810-
index: https://micropython.org/pi/v2
811-
author: MicroPython

tools/create-index.mjs

+88-32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import path from 'path';
33
import { execSync } from 'child_process';
44
import yaml from 'js-yaml';
55

6+
/**
7+
* Clones a Git repository to a specified directory
8+
* @param {string} url The URL of the Git repository
9+
* @param {string} directory The target directory to clone the repository to
10+
* @returns
11+
*/
612
const cloneRepository = (url, directory) => {
713
try {
814
// Clone the repository
@@ -14,6 +20,12 @@ const cloneRepository = (url, directory) => {
1420
}
1521
};
1622

23+
/**
24+
* Gets the GitHub URL of a Git repository from the local filesystem
25+
* @param {string} rootPath The root path of the Git repository
26+
* @returns {string} The GitHub URL of the repository
27+
* @returns {null} If an error occurs
28+
*/
1729
const getGitHubUrl = (rootPath) => {
1830
try {
1931
// Get the GitHub repository URL
@@ -29,6 +41,12 @@ const getGitHubUrl = (rootPath) => {
2941
}
3042
};
3143

44+
/**
45+
* Gets the current Git branch of a local repository
46+
* @param {string} rootPath The root path of the Git repository
47+
* @returns {string} The name of the current branch
48+
* @returns {null} If an error occurs
49+
*/
3250
const getCurrentBranch = (rootPath) => {
3351
try {
3452
// Get the current branch name
@@ -40,42 +58,95 @@ const getCurrentBranch = (rootPath) => {
4058
}
4159
};
4260

43-
const getRepositoryRoot = (rootPath) => {
61+
/**
62+
* Gets the root folder of a Git repository (the one containing the .git folder)
63+
* @param {string} aPath The path to a file or directory within the repository
64+
* @returns {string} The root folder of the repository
65+
* @returns {null} If an error occurs
66+
*/
67+
const getRepositoryRoot = (aPath) => {
4468
try {
4569
// Get the root folder of the repository
46-
const repositoryRoot = execSync('git rev-parse --show-toplevel', { cwd: rootPath, encoding: 'utf-8' }).trim();
70+
const repositoryRoot = execSync('git rev-parse --show-toplevel', { cwd: aPath, encoding: 'utf-8' }).trim();
4771
return repositoryRoot;
4872
} catch (error) {
4973
console.error(`Error getting repository root: ${error.message}`);
5074
return null;
5175
}
5276
};
5377

54-
const searchPackages = (directory, outputFilename, indexUrl) => {
78+
/**
79+
* Constructs a GitHub URL for a specific directory in a Git repository.
80+
* @param {string} baseUrl The base URL of the GitHub repository
81+
* @param {string} branch The current branch of the repository
82+
* @param {string} repositoryRoot The root folder of the repository
83+
* @param {string} dirPath The path to the directory within the repository
84+
* @returns {string} The GitHub URL for the directory
85+
*/
86+
const constructGitHubUrl = (baseUrl, branch, repositoryRoot, dirPath) => {
87+
const relativePath = path.relative(repositoryRoot, dirPath);
88+
const normalizedPath = relativePath.replace(/\\/g, '/'); // Normalize path separators for Windows
89+
90+
return `${baseUrl}/tree/${branch}/${normalizedPath}`;
91+
};
92+
93+
/**
94+
* Extracts the description from a manifest.py file
95+
* @param {string} filePath The path to the manifest.py file
96+
* @returns {string} The description extracted from the file
97+
* @returns {null} If an error occurs
98+
*/
99+
function extractDescription(filePath) {
100+
try {
101+
const content = fs.readFileSync(filePath, 'utf8');
102+
const descriptionMatch = /description="(.*?)"/.exec(content);
103+
104+
if (descriptionMatch && descriptionMatch[1]) {
105+
return descriptionMatch[1];
106+
}
107+
} catch (error) {
108+
console.error(`Error reading ${filePath}: ${error.message}`);
109+
return null;
110+
}
111+
}
112+
113+
/**
114+
* Generates a list of packages from directories containing a package.json file
115+
* @param {string} directory The starting directory to search for packages
116+
* @param {string} indexUrl The URL of the package index to be assigned to each package
117+
* @param {RegExp} excludePattern A regular expression to exclude certain directories
118+
* @returns {string} A YAML representation of the package list as a string
119+
*/
120+
const generatePackageList = (directory, indexUrl, excludePattern) => {
55121
const result = { packages: [] };
56122

57123
const repositoryRoot = getRepositoryRoot(directory);
124+
console.log(`Repository root: ${repositoryRoot} from ${directory}`);
58125
const gitHubUrl = getGitHubUrl(repositoryRoot);
59126
const currentBranch = getCurrentBranch(repositoryRoot);
60127

61128
if (!repositoryRoot || !gitHubUrl || !currentBranch) {
62129
return;
63130
}
64131

65-
const search = (dir, rootPath) => {
132+
const collectPackages = (dir, rootPath) => {
66133
const files = fs.readdirSync(dir);
67134

68135
for (const file of files) {
69136
const filePath = path.join(dir, file);
70137
const isDirectory = fs.statSync(filePath).isDirectory();
71138

72139
if (isDirectory) {
73-
search(filePath, rootPath);
140+
collectPackages(filePath, rootPath);
74141
} else {
75142
const isPackageJson = file === 'package.json';
76143
const isManifestPy = file === 'manifest.py';
77144
const packageName = path.basename(dir);
78145

146+
if (excludePattern && excludePattern.test(dir)) {
147+
continue; // Skip excluded packages
148+
}
149+
79150
if(packageName.startsWith("_")) {
80151
continue; // Skip "private" packages
81152
}
@@ -89,16 +160,8 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
89160
};
90161

91162
if (isManifestPy) {
92-
try {
93-
const content = fs.readFileSync(filePath, 'utf8');
94-
const descriptionMatch = /description="(.*?)"/.exec(content);
95-
96-
if (descriptionMatch && descriptionMatch[1]) {
97-
packageInfo.description = descriptionMatch[1];
98-
}
99-
} catch (error) {
100-
console.error(`Error reading ${file}: ${error.message}`);
101-
}
163+
const description = extractDescription(filePath, packageInfo, file);
164+
packageInfo.description = description;
102165
}
103166

104167
result.packages.push(packageInfo);
@@ -107,22 +170,8 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
107170
}
108171
};
109172

110-
const constructGitHubUrl = (baseUrl, branch, repositoryRoot, dirPath) => {
111-
const relativePath = path.relative(repositoryRoot, dirPath);
112-
const normalizedPath = relativePath.replace(/\\/g, '/'); // Normalize path separators for Windows
113-
114-
return `${baseUrl}/tree/${branch}/${normalizedPath}`;
115-
};
116-
117-
search(directory, repositoryRoot);
118-
119-
try {
120-
const yamlData = yaml.dump(result);
121-
fs.writeFileSync(outputFilename, `---\n${yamlData}`);
122-
console.log(`YAML file saved to ${outputFilename}`);
123-
} catch (error) {
124-
console.error(`Error writing YAML file: ${error.message}`);
125-
}
173+
collectPackages(directory, repositoryRoot);
174+
return yaml.dump(result);
126175
};
127176

128177
// Check if command line arguments are provided
@@ -142,6 +191,13 @@ if (process.argv.length < 3) {
142191
const directory = "build/micropython-lib";
143192
const indexUrl = "https://micropython.org/pi/v2";
144193
const outputFilename = process.argv[2];
194+
const excludePattern = /\/unix-ffi\//; // Skip Unix-specific packages
145195

146-
searchPackages(directory, outputFilename, indexUrl);
196+
const packageList = generatePackageList(directory, indexUrl, excludePattern);
197+
try {
198+
fs.writeFileSync(outputFilename, `---\n${packageList}`);
199+
console.log(`YAML file saved to ${outputFilename}`);
200+
} catch (error) {
201+
console.error(`Error writing YAML file: ${error.message}`);
202+
}
147203
}

0 commit comments

Comments
 (0)