-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1514 from mikel-brostrom/refactor-reqs-checker
Refactor reqs checker
- Loading branch information
Showing
13 changed files
with
61 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
# Mikel Broström 🔥 Yolo Tracking 🧾 AGPL-3.0 license | ||
|
||
import subprocess | ||
|
||
import pkg_resources | ||
import logging | ||
from pathlib import Path | ||
import pip | ||
|
||
from boxmot.utils import REQUIREMENTS, logger | ||
|
||
logger = logging.getLogger(__name__) | ||
REQUIREMENTS = Path('requirements.txt') | ||
|
||
class TestRequirements(): | ||
class RequirementsChecker: | ||
|
||
def check_requirements(self): | ||
requirements = pkg_resources.parse_requirements(REQUIREMENTS.open()) | ||
self.check_packages(requirements) | ||
|
||
def check_packages(self, requirements, cmds=''): | ||
"""Test that each required package is available.""" | ||
# Ref: https://stackoverflow.com/a/45474387/ | ||
|
||
s = '' # missing packages | ||
missing_packages = [] | ||
for r in requirements: | ||
r = str(r) | ||
try: | ||
pkg_resources.require(r) | ||
pkg_resources.require(str(r)) | ||
except Exception as e: | ||
logger.error(f'{e}') | ||
s += f'"{r}" ' | ||
if s: | ||
logger.warning(f'\nMissing packages: {s}\nAtempting installation...') | ||
try: | ||
subprocess.check_output(f'pip install --no-cache {s} {cmds}', shell=True, stderr=subprocess.STDOUT) | ||
except Exception as e: | ||
logger.error(e) | ||
exit() | ||
logger.success('All the missing packages were installed successfully') | ||
missing_packages.append(str(r)) | ||
|
||
if missing_packages: | ||
self.install_packages(missing_packages, cmds) | ||
|
||
def install_packages(self, packages, cmds=''): | ||
try: | ||
logger.warning(f'\nMissing packages: {", ".join(packages)}\nAttempting installation...') | ||
pip_args = ['install', '--no-cache-dir'] + packages + cmds.split() | ||
pip.main(pip_args) | ||
logger.info('All the missing packages were installed successfully') | ||
except Exception as e: | ||
logger.error(f'Failed to install packages: {e}') | ||
exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters