@@ -26,7 +26,7 @@ import {
2626 writeFileSync ,
2727} from "node:fs" ;
2828import { tmpdir } from "node:os" ;
29- import { basename , dirname , join , normalize , resolve } from "node:path" ;
29+ import { basename , dirname , join , normalize , resolve , sep } from "node:path" ;
3030import { fileURLToPath } from "node:url" ;
3131import { readZipEntries } from "./lib/archive.mjs" ;
3232import { backendPath } from "./lib/backend.mjs" ;
@@ -308,6 +308,34 @@ try {
308308 }
309309
310310 const pluginManifest = JSON . parse ( readFileSync ( join ( unpackedPluginDir , "plugin.json" ) , "utf8" ) ) ;
311+ const dependencyCommand = pluginManifest . buildSystems . find ( ( { id } ) => id === "python" ) . dependencies ;
312+ const dependencyArguments = ( outputFile ) => dependencyCommand . arguments . map ( ( arg ) =>
313+ arg . replace ( "${pluginDir}" , unpackedPluginDir ) . replace ( "${outputFile}" , outputFile ) ) ;
314+
315+ await check ( "dependency command skips user-site startup hooks" , ( ) => {
316+ const environment = join ( scratch , "dependency environment with shared site" ) ;
317+ run ( pythonCmd , [ "-I" , "-B" , "-m" , "venv" , "--without-pip" , "--system-site-packages" , environment ] ) ;
318+ const python = process . platform === "win32"
319+ ? join ( environment , "Scripts" , "python.exe" )
320+ : join ( environment , "bin" , "python" ) ;
321+ const userBase = join ( scratch , "dependency user base" ) ;
322+ const env = { ...process . env , PYTHONUSERBASE : userBase } ;
323+ const userSite = run ( python , [ "-E" , "-B" , "-c" , "import site; assert site.ENABLE_USER_SITE; print(site.getusersitepackages())" ] , {
324+ cwd : scratch , env,
325+ } ) . trim ( ) ;
326+ assert . ok ( userSite . startsWith ( userBase + sep ) , "expected a user site under the test's PYTHONUSERBASE" ) ;
327+ mkdirSync ( userSite , { recursive : true } ) ;
328+ writeFileSync ( join ( userSite , "usercustomize.py" ) , [
329+ "from pathlib import Path" ,
330+ 'Path(__file__).with_name("user-site-hook-ran").touch()' ,
331+ "" ,
332+ ] . join ( "\n" ) ) ;
333+
334+ const treeFile = join ( scratch , "isolated-dependencies.json" ) ;
335+ run ( python , dependencyArguments ( treeFile ) , { cwd : scratch , env } ) ;
336+ assert . equal ( existsSync ( join ( userSite , "user-site-hook-ran" ) ) , false , "usercustomize.py was executed" ) ;
337+ assert . equal ( JSON . parse ( readFileSync ( treeFile , "utf8" ) ) . format , "litheDependencies" ) ;
338+ } ) ;
311339
312340 await check ( "dependency command reads installed packages from a pip-free Python environment" , ( ) => {
313341 const environment = join ( scratch , "dependency environment" ) ;
@@ -335,12 +363,9 @@ try {
335363 metadata ( "CycleB" , "5.0" , [ "CycleA" ] ) ;
336364
337365 const treeFile = join ( scratch , "dependencies.json" ) ;
338- const declaration = pluginManifest . buildSystems . find ( ( { id } ) => id === "python" ) . dependencies ;
339- assert . equal ( declaration . output , "outputFile" ) ;
340- assert . equal ( declaration . decoder , "litheDependencies" ) ;
341- const args = declaration . arguments . map ( ( arg ) =>
342- arg . replace ( "${pluginDir}" , unpackedPluginDir ) . replace ( "${outputFile}" , treeFile ) ) ;
343- run ( python , args , { cwd : scratch } ) ;
366+ assert . equal ( dependencyCommand . output , "outputFile" ) ;
367+ assert . equal ( dependencyCommand . decoder , "litheDependencies" ) ;
368+ run ( python , dependencyArguments ( treeFile ) , { cwd : scratch } ) ;
344369 const leaf = ( name , version , children = [ ] ) => ( { name, version, children } ) ;
345370 assert . deepEqual ( JSON . parse ( readFileSync ( treeFile , "utf8" ) ) , {
346371 format : "litheDependencies" , version : 0 , dependencies : [
0 commit comments