Update build requirements, and add script to patch magic library for Windows.
This commit is contained in:
27
PatchMagicWin.py
Normal file
27
PatchMagicWin.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# This file patches the magic library on Windows so that it works properly after being compiled.
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
magicLibPath = Path.cwd() / "buildEnv" / "Lib" / "site-packages" / "magic" / "loader.py"
|
||||
|
||||
with open(magicLibPath, 'r') as magicLibFile:
|
||||
magicLines = magicLibFile.readlines()
|
||||
|
||||
# Find out what level of indentation is used, in case it changes in the future.
|
||||
lineIndent = None
|
||||
for line in magicLines:
|
||||
if line.startswith(' '):
|
||||
lineIndent = len(re.split(r'\S', line)[0])
|
||||
break
|
||||
|
||||
magicLines.insert(0, 'from pathlib import Path\n')
|
||||
|
||||
funcIndex = magicLines.index('def _lib_candidates():\n')
|
||||
|
||||
# This patch is only done on Windows, so we can safely 'hardcode' the path to the dll, since we're the ones
|
||||
# providing it.
|
||||
magicLines.insert(funcIndex + 1, ' ' * lineIndent + 'yield str(Path(__file__).parent / "libmagic-1.dll")\n')
|
||||
|
||||
with open(magicLibPath, 'w') as magicLibFile:
|
||||
magicLibFile.writelines(magicLines)
|
||||
3
build.sh
3
build.sh
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copy the Modules, Resources and Core directories, as well as Icon.ico, LinkScope.py and requirements.txt to a new directory along with this file.
|
||||
# Copy the Modules, Resources and Core directories, as well as Icon.ico, LinkScope.py and requirements.txt
|
||||
# to a new directory along with this file.
|
||||
# Then, run the script.
|
||||
|
||||
PYTHON_VER=3.9
|
||||
|
||||
29
buildWin.bat
29
buildWin.bat
@@ -1,9 +1,14 @@
|
||||
@ECHO OFF
|
||||
|
||||
:: Copy the Modules, Resources and Core directories, as well as Icon.ico, LinkScope.py and requirements.txt to a new directory along with this file.
|
||||
:: NOTE: Need to compile versions of the magic library for windows from here: https://github.com/nscaife/file-windows.git
|
||||
:: Then, put everything in the output folder (i.e. 'dist') in the magic folder.
|
||||
:: Make sure that the libmagic dll actually has the name 'libmagic-1.dll'.
|
||||
|
||||
:: Copy the Modules, Resources, Core and magic directories, as well as Icon.ico, LinkScope.py, requirements.txt,
|
||||
:: PatchMagicWin.py to a new directory along with this file.
|
||||
:: Then, run the script.
|
||||
|
||||
SET /A PYTHON_VER = 3.9
|
||||
SET PYTHON_VER=3.9
|
||||
|
||||
python -m venv buildEnv
|
||||
|
||||
@@ -15,23 +20,27 @@ python -m pip cache purge
|
||||
|
||||
python -m pip install -r requirements.txt
|
||||
|
||||
:: Patch magic library with our own binaries
|
||||
python PatchMagicWin.py
|
||||
|
||||
:: Stop snscrape from messing with directories that will not exist in the final build.
|
||||
echo "" > "buildEnv\Lib\site-packages\snscrape\modules\__init__.py"
|
||||
|
||||
set PLAYWRIGHT_BROWSERS_PATH=0
|
||||
SET PLAYWRIGHT_BROWSERS_PATH=0
|
||||
playwright install
|
||||
|
||||
SET /A FIREFOX_VER = (`python -c 'from pathlib import Path;x=Path("buildEnv\Lib\site-packages\playwright\driver\package\.local-browsers");print(list(x.glob("firefox*\firefox"))[0].parent.name.split("-")[1])'`)
|
||||
FOR /F "usebackq" %%L in (`python -c "from pathlib import Path;x=Path('buildEnv\Lib\site-packages\playwright\driver\package\.local-browsers');print(list(x.glob('firefox*/firefox'))[0].parent.name.split('-')[1])"`) DO SET FIREFOX_VER=%%L
|
||||
|
||||
:: Just in case this was not uncommented in the requirements.txt file.
|
||||
python -m pip install --upgrade python-magic-bin
|
||||
|
||||
python -m nuitka --follow-imports --standalone --noinclude-pytest-mode=nofollow --noinclude-setuptools-mode=nofollow ^
|
||||
--noinclude-custom-mode=setuptools:error --noinclude-IPython-mode=nofollow --enable-plugin=pyside6 ^
|
||||
--enable-plugin=numpy --enable-plugin=trio --assume-yes-for-downloads --remove-output --disable-console ^
|
||||
--include-data-dir="Resources=Resources" --include-plugin-directory=Modules --include-plugin-directory=Core ^
|
||||
--warn-unusual-code --show-modules --include-data-files="Icon.ico=Icon.ico" --windows-icon-from-ico="Icon.ico" ^
|
||||
--windows-company-name=AccentuSoft --windows-product-name=LinkScope --windows-product-version="1.3.8.0" --onefile-tempdir-spec='%TEMP%\LinkScope_%PID%_%TIME%' ^
|
||||
--include-data-dir="Resources=Resources" --include-plugin-directory=Modules --include-package=Core ^
|
||||
--include-data-dir="Core\Entities=Core\Entities" --include-data-dir="Core\Resolutions\Core=Core\Resolutions\Core" ^
|
||||
--include-data-dir="Modules=Modules" --warn-unusual-code --show-modules --include-data-files="Icon.ico=Icon.ico" ^
|
||||
--windows-icon-from-ico=".\Icon.ico" --include-data-dir="magic=magic" --windows-company-name=AccentuSoft ^
|
||||
--windows-product-name="LinkScope Client" --windows-product-version="1.3.8.0" ^
|
||||
--windows-file-description="LinkScope Client Software" ^
|
||||
--include-package-data=playwright ^
|
||||
--include-package-data=folium --include-package-data=branca ^
|
||||
--include-package=social-analyzer --include-package-data=langdetect --include-package-data=tld ^
|
||||
@@ -45,6 +54,6 @@ python -m nuitka --follow-imports --standalone --noinclude-pytest-mode=nofollow
|
||||
--include-package=ipwhois ^
|
||||
--include-package=tweepy ^
|
||||
--include-data-dir="buildEnv\Lib\site-packages\playwright\driver\package\.local-browsers\firefox-%FIREFOX_VER%\firefox=playwright\driver\package\.local-browsers\firefox-%FIREFOX_VER%\firefox" ^
|
||||
--include-package "python-magic-bin" ".\LinkScope.py"
|
||||
".\LinkScope.py"
|
||||
|
||||
call buildEnv\Scripts\deactivate.bat
|
||||
@@ -4,8 +4,6 @@ PySide6
|
||||
# For python-magic, the following packages may be required:
|
||||
## Linux:
|
||||
### sudo apt-get install libmagic1
|
||||
## Windows:
|
||||
### pip install python-magic-bin
|
||||
python-magic
|
||||
|
||||
# The graphviz package is required.
|
||||
|
||||
Reference in New Issue
Block a user