@@ -11,7 +11,7 @@ import * as pty from 'node-pty'
1111import tmp from 'tmp'
1212import yaml from 'js-yaml'
1313
14- import { home } from './boot'
14+ import { home } from './boot'
1515import spawn from './spawn'
1616import * as nix from './nix'
1717
@@ -49,6 +49,8 @@ export class SessionParameters {
4949 stdout : stream . Writable = process . stdout
5050}
5151
52+ let ENVIRONS_HOME = path . join ( home , 'envs' )
53+
5254/**
5355 * A computational environment
5456 */
@@ -101,11 +103,21 @@ export default class Environment {
101103 if ( read ) this . read ( )
102104 }
103105
106+ /**
107+ * Get or set the ome directory for environments
108+ *
109+ * @param value Value for home directory
110+ */
111+ static home ( value ?: string ) : string {
112+ if ( value ) ENVIRONS_HOME = value
113+ return ENVIRONS_HOME
114+ }
115+
104116 /**
105117 * Path to the environment specification files
106118 */
107119 path ( ) : string {
108- return path . join ( home , 'envs' , this . name + '.yaml' )
120+ return path . join ( Environment . home ( ) , this . name + '.yaml' )
109121 }
110122
111123 /**
@@ -125,7 +137,7 @@ export default class Environment {
125137 if ( this . adds && this . adds . length === 0 ) this . adds = undefined
126138 if ( this . removes && this . removes . length === 0 ) this . removes = undefined
127139
128- mkdirp . sync ( path . join ( home , 'envs' ) )
140+ mkdirp . sync ( Environment . home ( ) )
129141 const yml = yaml . safeDump ( this , { skipInvalid : true } )
130142 fs . writeFileSync ( this . path ( ) , yml )
131143 return this
@@ -168,7 +180,7 @@ export default class Environment {
168180 * List the environments on this machine
169181 */
170182 static async envs ( ) : Promise < Array < any > > {
171- const names = glob . sync ( '*.yaml' , { cwd : path . join ( home , 'envs' ) } ) . map ( file => file . slice ( 0 , - 5 ) )
183+ const names = glob . sync ( '*.yaml' , { cwd : Environment . home ( ) } ) . map ( file => file . slice ( 0 , - 5 ) )
172184 const envs = [ ]
173185 for ( let name of names ) {
174186 const env = new Environment ( name )
0 commit comments