77 */
88
99import * as core from '../../core' ;
10-
11- import { IS_WINDOWS , getPythonExecutable , runCommand } from '../../misc' ;
12- import { PEPverToSemver , download , extractTarGz } from '../helpers' ;
10+ import * as helpers from '../helpers' ;
11+ import * as misc from '../../misc' ;
1312
1413import BaseStage from './base' ;
1514import fs from 'fs-plus' ;
@@ -39,7 +38,7 @@ export default class PlatformIOCoreStage extends BaseStage {
3938 async whereIsPython ( ) {
4039 let status = this . params . pythonPrompt . STATUS_TRY_AGAIN ;
4140 do {
42- const pythonExecutable = await getPythonExecutable ( this . params . useBuiltinPIOCore ) ;
41+ const pythonExecutable = await misc . getPythonExecutable ( this . params . useBuiltinPIOCore ) ;
4342 if ( pythonExecutable ) {
4443 return pythonExecutable ;
4544 }
@@ -68,7 +67,7 @@ export default class PlatformIOCoreStage extends BaseStage {
6867 // https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi
6968 const pythonArch = process . arch === 'x64' ? '.amd64' : '' ;
7069 const msiUrl = `https://www.python.org/ftp/python/${ PlatformIOCoreStage . pythonVersion } /python-${ PlatformIOCoreStage . pythonVersion } ${ pythonArch } .msi` ;
71- const msiInstaller = await download (
70+ const msiInstaller = await helpers . download (
7271 msiUrl ,
7372 path . join ( core . getCacheDir ( ) , path . basename ( msiUrl ) )
7473 ) ;
@@ -90,7 +89,7 @@ export default class PlatformIOCoreStage extends BaseStage {
9089
9190 // install virtualenv
9291 return new Promise ( resolve => {
93- runCommand (
92+ misc . runCommand (
9493 'pip' ,
9594 [ 'install' , 'virtualenv' ] ,
9695 ( ) => resolve ( pythonPath )
@@ -101,7 +100,7 @@ export default class PlatformIOCoreStage extends BaseStage {
101100 async installPythonFromWindowsMSI ( msiInstaller , targetDir , administrative = false ) {
102101 const logFile = path . join ( core . getCacheDir ( ) , 'python27msi.log' ) ;
103102 await new Promise ( ( resolve , reject ) => {
104- runCommand (
103+ misc . runCommand (
105104 'msiexec.exe' ,
106105 [ administrative ? '/a' : '/i' , `"${ msiInstaller } "` , '/qn' , '/li' , `"${ logFile } "` , `TARGETDIR="${ targetDir } "` ] ,
107106 ( code , stdout , stderr ) => {
@@ -142,14 +141,14 @@ export default class PlatformIOCoreStage extends BaseStage {
142141
143142 isCondaInstalled ( ) {
144143 return new Promise ( resolve => {
145- runCommand ( 'conda' , [ '--version' ] , code => resolve ( code === 0 ) ) ;
144+ misc . runCommand ( 'conda' , [ '--version' ] , code => resolve ( code === 0 ) ) ;
146145 } ) ;
147146 }
148147
149148 createVirtualenvWithConda ( ) {
150149 this . cleanVirtualEnvDir ( ) ;
151150 return new Promise ( ( resolve , reject ) => {
152- runCommand (
151+ misc . runCommand (
153152 'conda' ,
154153 [ 'create' , '--yes' , '--quiet' , 'python=2' , 'pip' , '--prefix' , core . getEnvDir ( ) ] ,
155154 ( code , stdout , stderr ) => {
@@ -168,7 +167,7 @@ export default class PlatformIOCoreStage extends BaseStage {
168167 this . cleanVirtualEnvDir ( ) ;
169168 try {
170169 result = await new Promise ( ( resolve , reject ) => {
171- runCommand (
170+ misc . runCommand (
172171 pythonExecutable ,
173172 [ '-m' , 'virtualenv' , '-p' , pythonExecutable , core . getEnvDir ( ) ] ,
174173 ( code , stdout , stderr ) => {
@@ -183,7 +182,7 @@ export default class PlatformIOCoreStage extends BaseStage {
183182 } catch ( err ) {
184183 this . cleanVirtualEnvDir ( ) ;
185184 result = await new Promise ( ( resolve , reject ) => {
186- runCommand (
185+ misc . runCommand (
187186 'virtualenv' ,
188187 [ '-p' , pythonExecutable , core . getEnvDir ( ) ] ,
189188 ( code , stdout , stderr ) => {
@@ -201,22 +200,22 @@ export default class PlatformIOCoreStage extends BaseStage {
201200
202201 async createVirtualenvWithDownload ( pythonExecutable ) {
203202 this . cleanVirtualEnvDir ( ) ;
204- const archivePath = await download (
203+ const archivePath = await helpers . download (
205204 PlatformIOCoreStage . virtualenvUrl ,
206205 path . join ( core . getCacheDir ( ) , 'virtualenv.tar.gz' )
207206 ) ;
208207 const tmpDir = tmp . dirSync ( {
209208 dir : core . getCacheDir ( ) ,
210209 unsafeCleanup : true
211210 } ) . name ;
212- const dstDir = await extractTarGz ( archivePath , tmpDir ) ;
211+ const dstDir = await helpers . extractTarGz ( archivePath , tmpDir ) ;
213212 const virtualenvScript = fs . listTreeSync ( dstDir ) . find (
214213 item => path . basename ( item ) === 'virtualenv.py' ) ;
215214 if ( ! virtualenvScript ) {
216215 throw new Error ( 'Can not find virtualenv.py script' ) ;
217216 }
218217 return new Promise ( ( resolve , reject ) => {
219- runCommand (
218+ misc . runCommand (
220219 pythonExecutable ,
221220 [ virtualenvScript , core . getEnvDir ( ) ] ,
222221 ( code , stdout , stderr ) => {
@@ -241,7 +240,7 @@ export default class PlatformIOCoreStage extends BaseStage {
241240
242241 installVirtualenvPackage ( pythonExecutable ) {
243242 return new Promise ( ( resolve , reject ) => {
244- runCommand (
243+ misc . runCommand (
245244 pythonExecutable ,
246245 [ '-m' , 'pip' , 'install' , 'virtualenv' ] ,
247246 ( code , stdout , stderr ) => {
@@ -267,11 +266,13 @@ export default class PlatformIOCoreStage extends BaseStage {
267266 try {
268267 await this . createVirtualenvWithDownload ( pythonExecutable ) ;
269268 } catch ( err ) {
269+ misc . reportError ( err ) ;
270270 console . warn ( err ) ;
271271 try {
272272 await this . installVirtualenvPackage ( pythonExecutable ) ;
273273 await this . createVirtualenvWithLocal ( pythonExecutable ) ;
274274 } catch ( err ) {
275+ misc . reportError ( err ) ;
275276 console . warn ( err ) ;
276277 throw new Error ( 'Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv' ) ;
277278 }
@@ -281,12 +282,12 @@ export default class PlatformIOCoreStage extends BaseStage {
281282
282283 async upgradePIP ( pythonExecutable ) {
283284 // we use manual downloading to resolve SSL issue with old `pip`
284- const pipArchive = await download (
285+ const pipArchive = await helpers . download (
285286 PlatformIOCoreStage . pipUrl ,
286287 path . join ( core . getCacheDir ( ) , path . basename ( PlatformIOCoreStage . pipUrl ) )
287288 ) ;
288289 return new Promise ( resolve => {
289- runCommand ( pythonExecutable , [ '-m' , 'pip' , 'install' , '-U' , pipArchive ] , ( code , stdout , stderr ) => {
290+ misc . runCommand ( pythonExecutable , [ '-m' , 'pip' , 'install' , '-U' , pipArchive ] , ( code , stdout , stderr ) => {
290291 if ( code !== 0 ) {
291292 console . warn ( stderr ) ;
292293 }
@@ -309,11 +310,11 @@ export default class PlatformIOCoreStage extends BaseStage {
309310 args . push ( 'platformio' ) ;
310311 }
311312 return new Promise ( ( resolve , reject ) => {
312- runCommand ( pythonExecutable , args , ( code , stdout , stderr ) => {
313+ misc . runCommand ( pythonExecutable , args , ( code , stdout , stderr ) => {
313314 if ( code === 0 ) {
314315 resolve ( stdout ) ;
315316 } else {
316- if ( IS_WINDOWS ) {
317+ if ( misc . IS_WINDOWS ) {
317318 stderr += '\n If you have antivirus software in a system, try to disable it for a while.' ;
318319 }
319320 reject ( `PIP: ${ stderr } ` ) ;
@@ -373,7 +374,7 @@ export default class PlatformIOCoreStage extends BaseStage {
373374 }
374375
375376 async check ( ) {
376- const coreVersion = PEPverToSemver ( await core . getVersion ( ) ) ;
377+ const coreVersion = helpers . PEPverToSemver ( await core . getVersion ( ) ) ;
377378
378379 if ( this . params . useBuiltinPIOCore ) {
379380 if ( ! fs . isDirectorySync ( core . getEnvBinDir ( ) ) ) {
0 commit comments