Skip to content

Commit

Permalink
ADD pythonRequirementsInstalled
Browse files Browse the repository at this point in the history
  • Loading branch information
tomitomas committed Aug 28, 2024
1 parent 0f16fa9 commit 8776f43
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/tomitomasEqLogicTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,35 @@ public static function getPreformattedText($string) {
return '<br/>```text<br/>' . str_replace(array('<b>', '</b>', '&nbsp;'), array('', '', ' '), $string) . '<br/>```<br/>';
}

public static function backupExclude() {
return [
'resources/venv'
];
}

private static function pythonRequirementsInstalled(string $pythonPath, string $requirementsPath) {
if (!file_exists($pythonPath) || !file_exists($requirementsPath)) {
return false;
}
exec("{$pythonPath} -m pip freeze", $packages_installed);
$packages = join("||", $packages_installed);
exec("cat {$requirementsPath}", $packages_needed);
foreach ($packages_needed as $line) {
if (preg_match('/([^\s]+)[\s]*([>=~]=)[\s]*([\d+\.?]+)$/', $line, $need) === 1) {
if (preg_match('/' . $need[1] . '==([\d+\.?]+)/', $packages, $install) === 1) {
if ($need[2] == '==' && $need[3] != $install[1]) {
return false;
} elseif (version_compare($need[3], $install[1], '>')) {
return false;
}
} else {
return false;
}
}
}
return true;
}

/**
******************** LOGS FUNCTIONS
*/
Expand Down

0 comments on commit 8776f43

Please sign in to comment.