@atomist/org-visualizer
Version:
Organization Visualizer using Atomist project scanning
85 lines • 3.51 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const sdm_pack_fingerprints_1 = require("@atomist/sdm-pack-fingerprints");
const PythonDirectDepType = "python-direct-dep";
/**
* 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.
*/
exports.PythonDependencies = {
name: PythonDirectDepType,
displayName: "Python dependencies",
extract: (p) => __awaiter(this, void 0, void 0, function* () {
const requirementsFile = yield p.getFile("requirements.txt");
if (!requirementsFile) {
return undefined;
}
const requirementsFileContent = yield 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",
};
function findDependenciesFromRequirements(requirementsTxt) {
const r = /^([a-zA-Z0-9][A-Za-z0-9._-]*).*$/mg;
const results = [];
let v;
// tslint:disable-next-line:no-conditional-assignment
while ((v = r.exec(requirementsTxt)) !== null) {
// console.log(v[0]);
const requirementLine = v[0].replace(/\s+#.*$/, "").replace(/\s+/g, "");
results.push({
libraryName: v[1],
requirementLine,
});
}
return results;
}
exports.findDependenciesFromRequirements = findDependenciesFromRequirements;
function depToFingerprint(pd) {
const data = pd.requirementLine;
return {
type: PythonDirectDepType,
name: pd.libraryName,
abbreviation: "pydep",
version: "0.1.0",
data,
sha: sdm_pack_fingerprints_1.sha256(data),
};
}
//# sourceMappingURL=pythonDependencies.js.map