Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/python-setup/extractor_version.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Marco Gario <marcogario@github.com>
executable file
52 lines (39 sloc)
1.46 KB
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
#!/usr/bin/env python | |
# A quick hack to get package installation for Code Scanning to work, | |
# since it needs to know which version we're going to analyze the project as. | |
# This file needs to be placed next to `python_tracer.py`, so in | |
# `<codeql-path>/python/tools/` | |
from __future__ import print_function, division | |
import os | |
import sys | |
from contextlib import contextmanager | |
@contextmanager | |
def suppress_stdout_stderr(): | |
# taken from | |
# https://thesmithfam.org/blog/2012/10/25/temporarily-suppress-console-output-in-python/ | |
with open(os.devnull, "w") as devnull: | |
old_stdout = sys.stdout | |
old_stderr = sys.stderr | |
sys.stdout = devnull | |
sys.stderr = devnull | |
try: | |
yield | |
finally: | |
sys.stdout = old_stdout | |
sys.stderr = old_stderr | |
def get_extractor_version(codeql_base_dir: str, quiet: bool = True) -> int: | |
extractor_dir = os.path.join(codeql_base_dir, 'python', 'tools') | |
sys.path = [extractor_dir] + sys.path | |
from python_tracer import getzipfilename | |
zippath = os.path.join(extractor_dir, getzipfilename()) | |
sys.path = [zippath] + sys.path | |
import buildtools.discover | |
if quiet: | |
with suppress_stdout_stderr(): | |
return buildtools.discover.get_version() | |
else: | |
return buildtools.discover.get_version() | |
if __name__ == "__main__": | |
codeql_base_dir = sys.argv[1] | |
version = get_extractor_version(codeql_base_dir) | |
print('{!r}'.format(version)) |