Skip to content

Commit

Permalink
fix(Package): defer pip install
Browse files Browse the repository at this point in the history
  • Loading branch information
BotellaA committed Oct 20, 2020
1 parent 936a2e0 commit 400b4b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
58 changes: 28 additions & 30 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ var archiver = require('archiver');
var version = require('./version.json');
const fetch = require('node-fetch');
const {Octokit} = require('@octokit/rest');
const mkdirp = require('mkdirp')
const extract = require('extract-zip')
const {exec} = require('child_process');
const {execSync} = require('child_process');
const rimraf = require('rimraf').sync;

function pip(pipDestination, extractedDirectory) {
console.log('PIP to:', pipDestination);
execSync(
'python -m pip install --upgrade -r ' +
path.join(
extractedDirectory,
'server/requirements.txt') +
' -t ' + pipDestination,
{stdio: 'inherit'});
}

const dir = 'GeodePackage' +
'-' + process.argv[2] + '-' + process.argv[3];
mkdirp.sync(dir);
fs.mkdirSync(dir);
const pipDestination = path.join(dir, 'server');
fs.mkdirSync(pipDestination);
const owner = 'Geode-solutions'

var octokit = new Octokit({auth: process.env.TOKEN});
Expand Down Expand Up @@ -67,36 +78,17 @@ function getRelease(repo, version, isModule) {
extract(outputFile, {
dir: path.resolve(outputDirectory)
}).then(() => {
let extractedDirectory = '';
if (isModule) {
const extractedName = asset.name.slice(0, -4);
extractedDirectory =
path.join(outputDirectory, repo);
rimraf(extractedDirectory);
fs.renameSync(
path.join(outputDirectory, extractedName),
extractedDirectory);
}
else {
extractedDirectory = dir;
const extractedName = asset.name.slice(0, -4);
const extractedDirectory =
path.join(outputDirectory, repo);
rimraf(extractedDirectory);
fs.renameSync(
path.join(outputDirectory, extractedName),
extractedDirectory);
}
console.log('Unzip to:', repo);
const pipDestination = path.join(dir, 'server');
if (!fs.existsSync(pipDestination)) {
fs.mkdirSync(pipDestination);
}
console.log('PIP to:', pipDestination);
exec(
'python -m pip install --upgrade -r ' +
path.join(
extractedDirectory,
'server/requirements.txt') +
' -t ' + pipDestination,
(err, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
resolve();
});
resolve();
});
} catch (error) {
reject(error);
Expand All @@ -123,6 +115,12 @@ for (let [repo, tag] of Object.entries(version.modules)) {
fs.writeFileSync(path.join(dir, 'config.json'), JSON.stringify(config));

Promise.all(promises).then(() => {
pip(pipDestination, dir);
for (let [repo, tag] of Object.entries(version.modules)) {
const repoGeode = repo.concat('.geode');
pip(pipDestination, path.join(dir, 'modules', repoGeode));
}

// create a file to stream archive data to.
const outputName = path.join(__dirname, dir + '.zip');
console.log('Output: ', outputName);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@octokit/rest": "^17.11.2",
"archiver": "^4.0.2",
"extract-zip": "^2.0.1",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.1",
"rimraf": "^3.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"geode": "1.2.6",
"modules": {
"OpenGeode": "1.1.7",
"OpenGeode": "1.2.3",
"OpenGeode-IO": "1.0.4",
"OpenGeode-Geosciences": "1.0.2",
"OpenGeode-GeosciencesIO": "1.0.1"
Expand Down

0 comments on commit 400b4b6

Please sign in to comment.