-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathpep723.ts
More file actions
24 lines (23 loc) · 1003 Bytes
/
pep723.ts
File metadata and controls
24 lines (23 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as fse from 'fs-extra';
/**
* Checks if a Python script file uses PEP 723 inline script metadata.
*
* PEP 723 scripts declare their own Python version and dependency requirements
* via a `# /// script` block and should be run with `uv run <script>` without
* specifying a `--python` interpreter — uv resolves and manages the environment
* itself based on the inline metadata.
*
* @param filePath - Absolute path to the Python script file to inspect.
* @returns True if the file contains a PEP 723 `# /// script` opening marker,
* false if the marker is absent or the file cannot be read.
*/
export async function isPep723Script(filePath: string): Promise<boolean> {
try {
const content = await fse.readFile(filePath, 'utf-8');
// A PEP 723 script tag opens with a line that is exactly `# /// script`
// (optional trailing whitespace permitted).
return /^# \/\/\/ script\s*$/m.test(content);
} catch {
return false;
}
}