MCPcopy Create free account
hub / github.com/vercel/vercel / listInstalledPythons

Method listInstalledPythons

packages/python/src/uv.ts:78–129  ·  view source on GitHub ↗

* List installed Python versions managed by uv. * Excludes system Python.

()

Source from the content-addressed store, hash-verified

76 * Excludes system Python.
77 */
78 listInstalledPythons(): Set<string> {
79 let output: string;
80 try {
81 output = execFileSync(
82 this.uvPath,
83 ['python', 'list', '--only-installed', '--output-format', 'json'],
84 {
85 encoding: 'utf8',
86 stdio: ['pipe', 'pipe', 'pipe'],
87 shell: isWin,
88 }
89 );
90 } catch (err) {
91 throw new Error(
92 `Failed to run 'uv python list': ${err instanceof Error ? err.message : String(err)}`
93 );
94 }
95
96 if (!output || output.trim() === '' || output.trim() === '[]') {
97 return new Set();
98 }
99
100 let pyList: UvPythonEntry[];
101 try {
102 pyList = JSON.parse(output);
103 } catch (err) {
104 throw new Error(
105 `Failed to parse 'uv python list' output: ${err instanceof Error ? err.message : String(err)}`
106 );
107 }
108
109 // Only apply the startsWith filter when in Vercel Build Image
110 // (local builds use system Python paths, not /uv/python/)
111 if (process.env.VERCEL_BUILD_IMAGE) {
112 pyList = pyList.filter(
113 entry =>
114 entry.path !== null &&
115 entry.path.startsWith(UV_PYTHON_PATH_PREFIX) &&
116 entry.implementation === 'cpython'
117 );
118 } else {
119 pyList = pyList.filter(
120 entry => entry.path !== null && entry.implementation === 'cpython'
121 );
122 }
123
124 return new Set(
125 pyList.map(
126 entry => `${entry.version_parts.major}.${entry.version_parts.minor}`
127 )
128 );
129 }
130
131 async sync(options: {
132 venvPath: string;

Callers 1

getInstalledPythonsFunction · 0.95

Calls 2

filterMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected