YouTubeDownloader v1.1.2
YouTube content downloader
Loading...
Searching...
No Matches
check_included_packages.py
Go to the documentation of this file.
1"""!
2********************************************************************************
3@file check_included_packages.py
4@brief Utility script to list and check if the build executable
5 contains only specified third party packages
6********************************************************************************
7"""
8
9import logging
10import re
11from bs4 import BeautifulSoup
12
13from Source.version import __title__
14
15log = logging.getLogger("CheckIncludedPackages")
16
17# List of third party packages that may be contained in the PyInstaller executable.
18# Has to be manually extended if a new package gets added to the tool.
19L_ALLOWED_THIRD_PARTY_PACKAGES = [
20 # not possible to exclude
21 "PyInstaller",
22 # clipboard
23 "clipboard",
24 "pyperclip",
25 # youtube downloader
26 "pytubefix",
27 "customtkinter",
28 "darkdetect",
29 "packaging",
30 "openpyxl",
31 "et_xmlfile",
32 # colored log
33 "colorama"
34]
35
36S_RELATIVE_PATH = fr"build\{__title__}\xref-{__title__}.html"
37
38
39def check_included_packages() -> list[str]:
40 """!
41 @brief Check included packages
42 @return status if included packages are okay
43 """
44 d_third_party = {}
45 d_buildin = {}
46 d_own_packs = {}
47
48 # Regular Expressions
49 regex_third_party = re.compile(r".venv\/lib\/site-packages.*.py", re.IGNORECASE)
50 regex_third_party_name = re.compile(r"(?<=site-packages\/).*", re.IGNORECASE)
51 regex_builtin = re.compile(r".venv\/lib\/.*.py", re.IGNORECASE)
52 regex_builtin_name = re.compile(r"(?<=lib\/).*", re.IGNORECASE)
53 regex_own_packs = re.compile(fr"{__title__}\/.*")
54
55 # read PyInstaller modulegraph cross reference HTML
56 with open(S_RELATIVE_PATH, mode="r", encoding="utf-8") as o_html_file:
57 soup = BeautifulSoup(o_html_file, "html.parser")
58
59 # parse HTML
60 l_nodes = soup.find_all("div", class_="node")
61 for o_node in l_nodes:
62 l_targets = o_node.find_all("a", target="code")
63 for o_target in l_targets:
64 s_package_path = o_target["href"]
65 if regex_third_party.search(s_package_path):
66 matches = regex_third_party_name.search(s_package_path)
67 if matches is not None:
68 d_third_party[matches.group().split("/", maxsplit=1)[0].replace(".py", "")] = ""
69 elif regex_builtin.search(s_package_path):
70 matches = regex_builtin_name.search(s_package_path)
71 if matches is not None:
72 d_buildin[matches.group().replace(".py", "")] = ""
73 elif regex_own_packs.search(s_package_path):
74 matches = regex_own_packs.search(s_package_path)
75 if matches is not None:
76 d_own_packs[matches.group()] = ""
77
78 # print included packages
79 log.debug("\nThird party packages:")
80 log.debug("\n".join(list(d_third_party.keys())))
81 log.debug("\nOwn packages:")
82 log.debug("\n".join(list(d_own_packs.keys())))
83 log.debug("\nPython buildin packages:")
84 log.debug("\n".join(list(d_buildin.keys())))
85
86 # check third party packages
87 l_not_allowed_packages = []
88 for s_package in list(d_third_party.keys()):
89 if s_package not in L_ALLOWED_THIRD_PARTY_PACKAGES:
90 l_not_allowed_packages.append(f"ERROR PyInstaller included an unknown package in the executable: \'{s_package}\'")
91 return l_not_allowed_packages
list[str] check_included_packages()
Check included packages.