Python script to collect environment for debugging issues (#989)

* Tested on Mac, Windows & Rocky Linux OS
* Updated README to include bugs reporting script
This commit is contained in:
Ronny H 2023-08-02 22:54:43 +00:00 committed by GitHub
parent 719e15e7fe
commit 7a05ef2cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 258 additions and 4 deletions

View File

@ -19,10 +19,9 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. windows, mac, linux]
- Browser [e.g. chrome, safari]
- Python version [e.g. 3.8.15]
**Environment Info**
Please run `python scripts/collect_env.py` and paste the output here.
This will help us understand more about the environment in which the bug occurred.
**Additional context**
Add any other context about the problem here.

View File

@ -278,6 +278,10 @@ file-specific partitioning functions.
See our [security policy](https://github.com/Unstructured-IO/unstructured/security/policy) for
information on how to report security vulnerabilities.
## :bug: Reporting Bugs
Encountered a bug? Please create a new [GitHub issue](https://github.com/Unstructured-IO/unstructured/issues/new/choose) and use our bug report template to describe the problem. To help us diagnose the issue, use the `python scripts/collect_env.py` command to gather your system's environment information and include it in your report. Your assistance helps us continuously improve our software - thank you!
## :books: Learn more
| Section | Description |

251
scripts/collect_env.py Normal file
View File

@ -0,0 +1,251 @@
import platform
import shutil
import subprocess
import pkg_resources
from unstructured.utils import dependency_exists
def command_exists(command):
"""
Check if a command exists in the system
Args:
command (str): The command to check
Returns:
bool: True if command exists, False otherwise
"""
return shutil.which(command) is not None
def get_python_version():
"""
Get the current Python version
Returns:
str: The current Python version
"""
return platform.python_version()
def get_os_version():
"""
Get the current operating system version
Returns:
str: The current operating system version
"""
return platform.platform()
def is_python_package_installed(package_name):
"""
Check if a Python package is installed
Args:
package_name (str): The Python package to check
Returns:
bool: True if package is installed, False otherwise
"""
result = subprocess.run(
["pip", "list"],
stdout=subprocess.PIPE,
text=True,
check=True,
)
for line in result.stdout.splitlines():
if line.lower().startswith(package_name.lower()):
return True
return False
def is_brew_package_installed(package_name):
"""
Check if a Homebrew package is installed
Args:
package_name (str): The package to check
Returns:
bool: True if package is installed, False otherwise
"""
if not command_exists("brew"):
return False
result = subprocess.run(
["brew", "list"],
stdout=subprocess.PIPE,
text=True,
check=True,
)
for line in result.stdout.splitlines():
if line.lower().startswith(package_name.lower()):
return True
result = subprocess.run(
["brew", "list", "--cask"],
stdout=subprocess.PIPE,
text=True,
check=True,
)
for line in result.stdout.splitlines():
if line.lower().startswith(package_name.lower()):
return True
return False
def get_python_package_version(package_name):
"""
Get the version of a Python package
Args:
package_name (str): The Python package to check
Returns:
str: Version of the package, None if package is not installed
"""
try:
return pkg_resources.get_distribution(package_name).version
except pkg_resources.DistributionNotFound:
return None
def get_brew_package_version(package_name):
"""
Get the version of a Homebrew package
Args:
package_name (str): The package to check
Returns:
str: Version of the package, None if package is not installed
"""
if not command_exists("brew"):
return None
result = subprocess.run(
["brew", "info", package_name],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
)
for line in result.stdout.splitlines():
return line
return None
def get_libmagic_version():
"""
Get the version of libmagic
Returns:
str: Version of libmagic, None if libmagic is not installed
"""
result = subprocess.run(
["file", "--version", "--headless"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
return result.stdout.strip()
def get_libreoffice_version():
"""
Get the version of LibreOffice
Returns:
str: Version of LibreOffice, None if LibreOffice is not installed
"""
result = subprocess.run(
["libreoffice", "--version", "--headless"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
return result.stdout.strip()
def main():
"""
The main function to run all checks
"""
print("OS version: ", get_os_version())
print("Python version: ", get_python_version())
if dependency_exists("unstructured"):
print("unstructured version: ", get_python_package_version("unstructured"))
else:
print("unstructured is not installed")
if dependency_exists("unstructured_inference"):
print(
"unstructured-inference version: ",
get_python_package_version("unstructured-inference"),
)
else:
print("unstructured-inference is not installed")
if dependency_exists("pytesseract"):
print(
"pytesseract version: ",
get_python_package_version("pytesseract"),
)
else:
print("pytesseract is not installed")
if dependency_exists("torch"):
print("Torch version: ", get_python_package_version("torch"))
else:
print("Torch is not installed")
if dependency_exists("detectron2"):
print("Detectron2 version: ", get_python_package_version("detectron2"))
else:
print("Detectron2 is not installed")
if is_python_package_installed("paddlepaddle") or is_python_package_installed(
"paddleocr",
):
print(
"PaddleOCR version: ",
get_python_package_version("paddlepaddle")
or get_python_package_version("paddleocr"),
)
else:
print("PaddleOCR is not installed")
if is_brew_package_installed("libmagic"):
print("Libmagic version: ", get_brew_package_version("libmagic"))
else:
libmagic_version = get_libmagic_version()
if libmagic_version:
print(f"Libmagic version: {libmagic_version}")
else:
print("Libmagic is not installed")
if platform.system() != "Windows":
if is_brew_package_installed("libreoffice"):
print("LibreOffice version: ", get_brew_package_version("libreoffice"))
else:
libreoffice_version = get_libreoffice_version()
if libreoffice_version:
print("LibreOffice version: ", libreoffice_version)
else:
print("LibreOffice is not installed")
if __name__ == "__main__":
main()