Skip to content

Commit

Permalink
tools: Check project requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Jul 7, 2023
1 parent 69607f6 commit 21bc641
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
libclang
pefile
pyxbe
libclang~=16.0.0
pefile~=2023.2.7
pyxbe~=1.0.2
33 changes: 33 additions & 0 deletions tools/check_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path
import logging

import pkg_resources

import color

log = logging.getLogger(__name__)


def check_requirements() -> None:
requirements_path = Path(__file__).parent.with_name("requirements.txt")

with open(requirements_path, "r", encoding="utf-8") as f:
requirements = f.readlines()

try:
pkg_resources.require(requirements)
except pkg_resources.DistributionNotFound as e:
log.error("Required package '%s' is not installed. Please install project requirements via requirements.txt.", e.req)
exit(1)
except pkg_resources.VersionConflict as e:
log.error("There is a package version conflict. '%s' is installed, but '%s' is required. Please install project requirements via requirements.txt.", e.dist, e.req)
exit(1)


def main():
check_requirements()


if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, handlers=[color.ColorLogHandler()])
main()
4 changes: 4 additions & 0 deletions tools/knowledge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python3
if __name__ == "__main__":
from check_requirements import check_requirements
check_requirements()

import json
from collections import defaultdict
from typing import Sequence, Union, Optional
Expand Down
4 changes: 4 additions & 0 deletions tools/maintain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python3
if __name__ == "__main__":
from check_requirements import check_requirements
check_requirements()

import argparse
import logging
import os
Expand Down
4 changes: 4 additions & 0 deletions tools/patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env python3
if __name__ == "__main__":
from check_requirements import check_requirements
check_requirements()

import itertools
import struct
import subprocess
Expand Down

0 comments on commit 21bc641

Please sign in to comment.