import * as Collections from 'typescript-collections' ; import * as vscode from 'vscode' ; import { ComponentDetails } from 'jfrog-client-js' ; import { DependenciesTreeNode } from '../dependenciesTreeNode' ; import { TreesManager } from '../../treesManager' ; import { GeneralInfo } from '../../../types/generalInfo' ; import { ScanUtils } from '../../../utils/scanUtils' ; import { PypiUtils } from '../../../utils/pypiUtils' ; import { RootNode } from './rootTree' ; /**
 * Pypi packages can be installed in two different ways:
 * 1. 'pip install [Path to setup.py]' - With this method, the top level in the tree would be the project name.
 * 2. 'pip install -r [Path to requirements.txt]' - With this method, the top level in the tree would be the dependencies of the project.
 */ export class PypiTreeNode extends RootNode { private static readonly COMPONENT_PREFIX : string = 'pypi://' ; constructor ( workspaceFolder , private _componentsToScan , private _treesManager , private _pythonPath , parent ? ) { super ( workspaceFolder , parent ) ; } public async refreshDependencies ( quickScan ) { let pypiList ; try { pypiList = JSON . parse ( ScanUtils . executeCmd ( this . _pythonPath + ' ' + PypiUtils . PIP_DEP_TREE_SCRIPT + ' --json-tree' , this . workspaceFolder ) . toString ( ) ) ; this . generalInfo = new GeneralInfo ( this . workspaceFolder . replace ( /^.*[\\/]/ , '' ) , '' , [ 'None' ] , this . workspaceFolder , PypiUtils . PKG_TYPE ) ; } catch ( error ) { this . _treesManager . logManager . logError ( < any > error , ! quickScan ) ; } this . label = this . generalInfo . artifactId ; this . populateDependenciesTree ( this , pypiList , quickScan ) ; } private populateDependenciesTree ( dependenciesTreeNode , dependencies , quickScan ) { if ( ! dependencies ) { return ; } for ( let key in dependencies ) { let dependency = dependencies [ key ] ; let version = dependency . installed_version ; if ( version ) { let childDependencies = dependency . dependencies ; let generalInfo = new GeneralInfo ( dependency . key , version , [ 'None' ] , '' , PypiUtils . PKG_TYPE ) ; let treeCollapsibleState = childDependencies && childDependencies . length > 0 ? vscode . TreeItemCollapsibleState . Collapsed : vscode . TreeItemCollapsibleState . None ; let child = new DependenciesTreeNode ( generalInfo , treeCollapsibleState , dependenciesTreeNode ) ; let componentId = dependency . key + ':' + version ; if ( ! quickScan || ! this . _treesManager . scanCacheManager . isValid ( componentId ) ) { this . _componentsToScan . add ( new ComponentDetails ( PypiTreeNode . COMPONENT_PREFIX + componentId ) ) ; } this . populateDependenciesTree ( child , childDependencies , quickScan ) ; } } } }