import { Aspect , FP , sha256 , } from "@atomist/sdm-pack-fingerprint" ; const PythonDirectDepType = "python-direct-dep" ; export interface PythonDependency { libraryName : string ; requirementLine : string ; } /**
 * Find Python dependencies in requirements.txt
 *
 * Use this to find out what Python dependencies are declared
 * in your project, and what versions are specified.
 *
 * This fingerprints each line that looks like a dependency.
 * The entire line becomes the data of the fingerprint.
 *
 * The displayed value is the whole line, minus the name.
 *
 * The data is the requirements line.
 */ export const PythonDependencies = { name : PythonDirectDepType , displayName : "Python dependencies" , extract : async ( p ) => { const requirementsFile = await p . getFile ( "requirements.txt" ) ; if ( ! requirementsFile ) { return undefined ; } const requirementsFileContent = await requirementsFile . getContent ( ) ; const allDeps = findDependenciesFromRequirements ( requirementsFileContent ) ; return allDeps . map ( depToFingerprint ) ; } , toDisplayableFingerprintName : name => name , toDisplayableFingerprint : fp => { const version = fp . data . replace ( fp . name , "" ) ; return version ; } , documentationUrl : "https://atomist-blogs.github.io/org-visualizer/modules/_lib_feature_python_pythondependenciesfeature_.html#pythondependenciesfeature" , } ; export function findDependenciesFromRequirements ( requirementsTxt ) { const r = /^([a-zA-Z0-9][A-Za-z0-9._-]*).*$/mg ; const results = [ ] ; let v ; while ( ( v = r . exec ( requirementsTxt ) ) !== null ) { const requirementLine = v [ 0 ] . replace ( /\s+#.*$/ , "" ) . replace ( /\s+/g , "" ) ; results . push ( { libraryName : v [ 1 ] , requirementLine , } ) ; } return results ; } function depToFingerprint ( pd ) { const data = pd . requirementLine ; return { type : PythonDirectDepType , name : pd . libraryName , abbreviation : "pydep" , version : "0.1.0" , data , sha : sha256 ( data ) , } ; }