Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add egg updater script which fixes pytest initialization issue #672

Merged
merged 14 commits into from
May 19, 2020
30 changes: 18 additions & 12 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@

# Python 2 compatibility stuff
from __future__ import print_function
import sys

import argparse
import logging
import multiprocessing
import os
import csv
import platform
import subprocess
import logging
import argparse
import sys
import textwrap
import threading
import pkg_resources
import multiprocessing
from collections import defaultdict

from .version import VERSION
from .util import DirWalk, inpath
from .extractor import Extractor
from .strings import Strings
from .file import is_binary
from .OutputEngine import OutputEngine
import pkg_resources

from .OutputEngine import OutputEngine
from .cvedb import CVEDB, OLD_CACHE_DIR
from .egg_updater import IS_DEVELOP, update_egg
from .extractor import Extractor
from .file import is_binary
from .log import LOGGER
from .strings import Strings
from .util import DirWalk, inpath
from .version import VERSION

try:
import queue
Expand All @@ -55,6 +56,11 @@ class Scanner(object):
def __init__(self, cvedb, checkers=None, logger=None):
if logger is None:
logger = LOGGER.getChild(self.__class__.__name__)
# Update egg if installed in development mode
if IS_DEVELOP():
logger.info("Updating egg_info")
update_egg()
Niraj-Kamdar marked this conversation as resolved.
Show resolved Hide resolved

# Load checkers if not given
if checkers is None:
checkers = self.load_checkers()
Expand Down
63 changes: 63 additions & 0 deletions cve_bin_tool/egg_updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import sys
from io import StringIO

from setuptools.dist import Distribution


def IS_DEVELOP():
return any(
list(
map(
os.path.isfile,
list(
map(
lambda syspath: os.path.join(syspath, "cve-bin-tool.egg-link"),
sys.path,
)
),
)
)
)


def update_egg():
with StringIO() as f:
cwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
sys.stdout = f
dist = Distribution(
dict(
script_name="setup.py",
script_args=["egg_info"],
name="cve-bin-tool",
entry_points={
"cve_bin_tool.checker": [
"{} = cve_bin_tool.checkers.{}:{}".format(
filename.replace(".py", ""),
filename.replace(".py", ""),
"".join(
(filename.replace(".py", "") + " checker")
.replace("_", " ")
.title()
.split()
),
)
for filename in os.listdir(
os.path.join(
os.path.abspath(os.path.dirname(__file__)), "checkers",
)
)
if filename.endswith(".py") and "__init__" not in filename
],
},
)
)
dist.parse_command_line()
dist.run_commands()
sys.stdout = sys.__stdout__
os.chdir(cwd)


if __name__ == "__main__":
update_egg()