From ccdfb098f6e96142282440905b0c462f697ff9e4 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 14:51:14 +0100 Subject: [PATCH 01/12] Create setup.py and fix building wheel --- MANIFEST.in | 8 ++ pyproject.toml | 3 + setup.py | 108 ++++++++++++++++++ src/run_tribler.py | 6 +- .../components/knowledge/restapi/__init__.py | 0 .../components/knowledge/rules/__init__.py | 0 .../knowledge_to_triblerdb/__init__.py | 0 .../core/upgrade/tribler_db/__init__.py | 0 .../tribler_db/scheme_migrations/__init__.py | 0 .../core/utilities/aiohttp/__init__.py | 0 10 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 MANIFEST.in create mode 100644 pyproject.toml create mode 100644 setup.py create mode 100644 src/tribler/core/components/knowledge/restapi/__init__.py create mode 100644 src/tribler/core/components/knowledge/rules/__init__.py create mode 100644 src/tribler/core/upgrade/knowledge_to_triblerdb/__init__.py create mode 100644 src/tribler/core/upgrade/tribler_db/__init__.py create mode 100644 src/tribler/core/upgrade/tribler_db/scheme_migrations/__init__.py create mode 100644 src/tribler/core/utilities/aiohttp/__init__.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000000..14d7ec9f894 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,8 @@ +include src/run_tribler.py +include src/tribler/core/components/libtorrent/download_manager/download_config.spec +include src/tribler/core/components/database/category_filter/category.conf +include src/tribler/core/components/database/category_filter/filter_terms.filter +include src/tribler/core/components/database/category_filter/level2.regex +recursive-include src/tribler/gui/qt_resources * +recursive-include src/tribler/gui/i18n * +recursive-include src/tribler/gui/images * \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..638dd9c54fc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py new file mode 100644 index 00000000000..9c6d739810d --- /dev/null +++ b/setup.py @@ -0,0 +1,108 @@ +import os +import re +import shutil + +from setuptools import setup, find_packages + +# Copy src/run_tribler.py --> src/tribler/run.py to make it accessible in entry_points scripts. +shutil.copy("src/run_tribler.py", "src/tribler/run.py") + + +def read_version_from_file(file_path): + with open(file_path, 'r') as file: + file_content = file.read() + # Use regular expression to find the version pattern + version_match = re.search(r"^version_id = ['\"]([^'\"]*)['\"]", file_content, re.M) + if version_match: + version_str = version_match.group(1) + return version_str.split("-")[0] + raise RuntimeError("Unable to find version string.") + + +version_file = os.path.join('src', 'tribler', 'core', 'version.py') +version = read_version_from_file(version_file) + + +setup( + name="Tribler", + version=version, + description="Privacy enhanced BitTorrent client with P2P content discovery", + long_description=open('README.rst').read(), + long_description_content_type="text/x-rst", + author="Tribler Team", + author_email="tribler@tribler.org", + url="https://www.tribler.org", + packages=find_packages(where="src"), + package_dir={"": "src"}, + include_package_data=True, + install_requires=[ + "aiohttp==3.9.0", + "aiohttp-apispec==2.2.3", + "anyio==3.7.1", + "chardet==5.1.0", + "configobj==5.0.8", + "cryptography==42.0.5", + "Faker==18.11.2", + "libnacl==1.8.0", + "lz4==4.3.2", + "marshmallow==3.19.0", + "networkx==3.1", + "pony==0.7.17", + "psutil==5.9.5", + "pydantic==1.10.11", + "PyOpenSSL==24.0.0", + "pyyaml==6.0", + "sentry-sdk==1.31.0", + "yappi==1.4.0", + "yarl==1.9.2", + "bitarray==2.7.6", + "pyipv8==2.13.0", + "libtorrent==1.2.19", + "file-read-backwards==3.0.0", + "Brotli==1.0.9", + "human-readable==1.3.2", + "colorlog==6.7.0", + "filelock==3.13.0", + "ipv8-rust-tunnels==0.1.17", + "Pillow==10.2.0", + "PyQt5==5.15.1", + "PyQt5-sip==12.8.1", + "pyqtgraph==0.12.3", + "PyQtWebEngine==5.15.2", + "setuptools==65.5.1; sys_platform == 'darwin'", + "text-unidecode==1.3; sys_platform == 'darwin'", + "defusedxml==0.7.1; sys_platform == 'linux2' or sys_platform == 'linux'", + "markupsafe==2.0.1; sys_platform == 'linux2' or sys_platform == 'linux'", + "PyGObject==3.44.1; sys_platform == 'linux2' or sys_platform == 'linux'", + "requests==2.31.0", + ], + extras_require={ + "dev": [ + "pytest==7.4.3", + "pytest-aiohttp==1.0.5", + "pytest-asyncio==0.21.1", + "pytest-randomly==3.15.0", + "pytest-timeout==2.2.0", + "pylint-pytest==1.1.7", + "coverage==7.3.2", + "looptime==0.2;sys_platform!='win32'", + "pytest-qt==4.2.0", + ], + }, + entry_points={ + "gui_scripts": [ + "tribler=tribler.run:main", + ] + }, + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: GPL-3.0 license", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Topic :: Internet :: File Sharing", + "Topic :: Security :: Cryptography", + "Operating System :: OS Independent", + ], +) diff --git a/src/run_tribler.py b/src/run_tribler.py index b0a2a20411f..51db913e779 100644 --- a/src/run_tribler.py +++ b/src/run_tribler.py @@ -77,7 +77,7 @@ def init_boot_logger(): logging.basicConfig(level=logging.INFO, stream=sys.stdout) -if __name__ == "__main__": +def main(): init_boot_logger() parsed_args = RunTriblerArgsParser().parse_args() @@ -117,3 +117,7 @@ def init_boot_logger(): init_sentry_reporter(gui_sentry_reporter) run_gui(api_port, api_key, root_state_dir, parsed_args) + + +if __name__ == "__main__": + main() diff --git a/src/tribler/core/components/knowledge/restapi/__init__.py b/src/tribler/core/components/knowledge/restapi/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/components/knowledge/rules/__init__.py b/src/tribler/core/components/knowledge/rules/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/upgrade/knowledge_to_triblerdb/__init__.py b/src/tribler/core/upgrade/knowledge_to_triblerdb/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/upgrade/tribler_db/__init__.py b/src/tribler/core/upgrade/tribler_db/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/upgrade/tribler_db/scheme_migrations/__init__.py b/src/tribler/core/upgrade/tribler_db/scheme_migrations/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/utilities/aiohttp/__init__.py b/src/tribler/core/utilities/aiohttp/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From 35844e2e33eb46446f7ff8439177bd0397d7a7ec Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 17:12:33 +0100 Subject: [PATCH 02/12] Address Codacy report on explicit file encoding --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9c6d739810d..c943fed9a99 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read_version_from_file(file_path): - with open(file_path, 'r') as file: + with open(file_path, "r", encoding="utf-8") as file: file_content = file.read() # Use regular expression to find the version pattern version_match = re.search(r"^version_id = ['\"]([^'\"]*)['\"]", file_content, re.M) From f20dc8d59bf8d15d8f5acd18f8f9e35dd5560de2 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 17:17:56 +0100 Subject: [PATCH 03/12] Address Codacy report on explicit file encoding --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c943fed9a99..92dd9601aba 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ import os import re import shutil +from pathlib import Path from setuptools import setup, find_packages @@ -27,7 +28,7 @@ def read_version_from_file(file_path): name="Tribler", version=version, description="Privacy enhanced BitTorrent client with P2P content discovery", - long_description=open('README.rst').read(), + long_description=Path('README.rst').read_text(), long_description_content_type="text/x-rst", author="Tribler Team", author_email="tribler@tribler.org", From a2bf36543a6ee5a29a2abc727185264739a748d7 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 17:24:30 +0100 Subject: [PATCH 04/12] Address Codacy report on explicit file encoding --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92dd9601aba..37bd62f255f 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def read_version_from_file(file_path): name="Tribler", version=version, description="Privacy enhanced BitTorrent client with P2P content discovery", - long_description=Path('README.rst').read_text(), + long_description=Path('README.rst').read_text(encoding="utf-8"), long_description_content_type="text/x-rst", author="Tribler Team", author_email="tribler@tribler.org", From c638fef8c5288945eaeb85b92a3e0091f437b628 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 17:32:32 +0100 Subject: [PATCH 05/12] Fix email address in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 37bd62f255f..17dd4c3e071 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def read_version_from_file(file_path): long_description=Path('README.rst').read_text(encoding="utf-8"), long_description_content_type="text/x-rst", author="Tribler Team", - author_email="tribler@tribler.org", + author_email="info@tribler.org", url="https://www.tribler.org", packages=find_packages(where="src"), package_dir={"": "src"}, From 7853c10b19de6b819fff87060132dc6c0cef8044 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 20 Mar 2024 10:08:57 +0100 Subject: [PATCH 06/12] Load setup.py install requirements from existing requirements file' --- MANIFEST.in | 3 ++- setup.py | 78 +++++++++++++++++------------------------------------ 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 14d7ec9f894..1d16829087d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,4 +5,5 @@ include src/tribler/core/components/database/category_filter/filter_terms.filter include src/tribler/core/components/database/category_filter/level2.regex recursive-include src/tribler/gui/qt_resources * recursive-include src/tribler/gui/i18n * -recursive-include src/tribler/gui/images * \ No newline at end of file +recursive-include src/tribler/gui/images * +include requirements*.txt diff --git a/setup.py b/setup.py index 17dd4c3e071..e38e7cce04d 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,28 @@ def read_version_from_file(file_path): version = read_version_from_file(version_file) +def read_requirements(file_name, directory='.'): + file_path = os.path.join(directory, file_name) + requirements = [] + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + # Check for a nested requirements file + if line.startswith('-r'): + nested_file = line.split(' ')[1].strip() + requirements += read_requirements(nested_file, directory) + elif not line.startswith('#') and line.strip() != '': + requirements.append(line.strip().split('#')[0].strip()) + return requirements + + +base_dir = os.path.dirname(os.path.abspath(__file__)) + +install_requires = read_requirements('requirements-build.txt', base_dir) +extras_require = { + 'dev': read_requirements('requirements-test.txt', base_dir), +} + + setup( name="Tribler", version=version, @@ -36,60 +58,8 @@ def read_version_from_file(file_path): packages=find_packages(where="src"), package_dir={"": "src"}, include_package_data=True, - install_requires=[ - "aiohttp==3.9.0", - "aiohttp-apispec==2.2.3", - "anyio==3.7.1", - "chardet==5.1.0", - "configobj==5.0.8", - "cryptography==42.0.5", - "Faker==18.11.2", - "libnacl==1.8.0", - "lz4==4.3.2", - "marshmallow==3.19.0", - "networkx==3.1", - "pony==0.7.17", - "psutil==5.9.5", - "pydantic==1.10.11", - "PyOpenSSL==24.0.0", - "pyyaml==6.0", - "sentry-sdk==1.31.0", - "yappi==1.4.0", - "yarl==1.9.2", - "bitarray==2.7.6", - "pyipv8==2.13.0", - "libtorrent==1.2.19", - "file-read-backwards==3.0.0", - "Brotli==1.0.9", - "human-readable==1.3.2", - "colorlog==6.7.0", - "filelock==3.13.0", - "ipv8-rust-tunnels==0.1.17", - "Pillow==10.2.0", - "PyQt5==5.15.1", - "PyQt5-sip==12.8.1", - "pyqtgraph==0.12.3", - "PyQtWebEngine==5.15.2", - "setuptools==65.5.1; sys_platform == 'darwin'", - "text-unidecode==1.3; sys_platform == 'darwin'", - "defusedxml==0.7.1; sys_platform == 'linux2' or sys_platform == 'linux'", - "markupsafe==2.0.1; sys_platform == 'linux2' or sys_platform == 'linux'", - "PyGObject==3.44.1; sys_platform == 'linux2' or sys_platform == 'linux'", - "requests==2.31.0", - ], - extras_require={ - "dev": [ - "pytest==7.4.3", - "pytest-aiohttp==1.0.5", - "pytest-asyncio==0.21.1", - "pytest-randomly==3.15.0", - "pytest-timeout==2.2.0", - "pylint-pytest==1.1.7", - "coverage==7.3.2", - "looptime==0.2;sys_platform!='win32'", - "pytest-qt==4.2.0", - ], - }, + install_requires=install_requires, + extras_require=extras_require, entry_points={ "gui_scripts": [ "tribler=tribler.run:main", From 910c9438d50fa164e6092643e2874605b565615f Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Fri, 22 Mar 2024 13:56:42 +0100 Subject: [PATCH 07/12] Support creating build using Cx_Freeze --- README.rst | 12 +++---- build.py | 82 ++++++++++++++++++++++++++++++++++++++++++ requirements-build.txt | 3 +- setup.py | 36 ++++++++++++------- 4 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 build.py diff --git a/README.rst b/README.rst index a022a322304..2152e309e25 100644 --- a/README.rst +++ b/README.rst @@ -48,9 +48,9 @@ We support development on Linux, macOS and Windows. We have written documentation that guides you through installing the required packages when setting up a Tribler development environment. -* `Linux `_ -* `Windows `_ -* `macOS `_ +* `Linux `__ +* `Windows `__ +* `macOS `__ @@ -59,9 +59,9 @@ Packaging Tribler We have written guides on how to package Tribler for distribution on various systems. -* `Linux `_ -* `Windows `_ -* `macOS `_ +* `Linux `__ +* `Windows `__ +* `macOS `__ Docker support diff --git a/build.py b/build.py new file mode 100644 index 00000000000..19e99fdeee1 --- /dev/null +++ b/build.py @@ -0,0 +1,82 @@ +""" +This file includes the build configuration for the Tribler executable using CX Freeze. +The exports of this file are used in setup.py to build the executable. + +To create a build: +python setup.py build + +To create a distributable package: +python setup.py bdist + +To create a distributable package for a specific platform: +python setup.py bdist_mac +python setup.py bdist_win +""" +import os +import re +import shutil +import sys +from pathlib import Path + +from setuptools import find_packages +from cx_Freeze import setup, Executable + +app_name = "Tribler" if sys.platform != "linux" else "tribler" +app_script = "src/tribler/run.py" +app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" +app_executable = Executable( + target_name=app_name, + script=app_script, + base="Win32GUI" if sys.platform == "win32" else None, + icon=app_icon_path, +) + +# These packages will be included in the build +sys.path.insert(0, 'src') +included_packages = [ + "aiohttp_apispec", + "sentry_sdk", + "ipv8", + "PIL", + "pkg_resources", + "pydantic", + "pyqtgraph", + "PyQt5.QtTest", + "requests", + "tribler.core", + "tribler.gui", + "faker" +] + +# These files will be included in the build +included_files = [ + ("src/tribler/gui/qt_resources", "qt_resources"), + ("src/tribler/gui/images", "images"), + ("src/tribler/gui/i18n", "i18n"), + ("src/tribler/core", "tribler_source/tribler/core"), + ("src/tribler/gui", "tribler_source/tribler/gui"), + ("build/win/resources", "tribler_source/resources"), +] + +# These packages will be excluded from the build +excluded_packages = [ + 'wx', + 'PyQt4', + 'FixTk', + 'tcl', + 'tk', + '_tkinter', + 'tkinter', + 'Tkinter', + 'matplotlib' +] + +build_exe_options = { + "packages": included_packages, + "excludes": excluded_packages, + "include_files": included_files, + "include_msvcr": True, + 'build_exe': 'dist/tribler' +} + +__all__ = ["setup", "app_executable", "build_exe_options"] diff --git a/requirements-build.txt b/requirements-build.txt index c59bb3660d3..21a70ba7097 100644 --- a/requirements-build.txt +++ b/requirements-build.txt @@ -1,6 +1,7 @@ -r requirements.txt -PyInstaller==5.1; sys_platform != 'darwin' +PyInstaller==5.13.1; sys_platform == 'linux2' or sys_platform == 'linux' +cx_Freeze==6.15.16; sys_platform == 'win32' setuptools==65.5.1; sys_platform == 'darwin' text-unidecode==1.3; sys_platform == 'darwin' diff --git a/setup.py b/setup.py index e38e7cce04d..85e091cb9f3 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,9 @@ import shutil from pathlib import Path -from setuptools import setup, find_packages +from setuptools import find_packages -# Copy src/run_tribler.py --> src/tribler/run.py to make it accessible in entry_points scripts. -shutil.copy("src/run_tribler.py", "src/tribler/run.py") +from build import app_executable, build_exe_options, setup def read_version_from_file(file_path): @@ -20,10 +19,6 @@ def read_version_from_file(file_path): raise RuntimeError("Unable to find version string.") -version_file = os.path.join('src', 'tribler', 'core', 'version.py') -version = read_version_from_file(version_file) - - def read_requirements(file_name, directory='.'): file_path = os.path.join(directory, file_name) requirements = [] @@ -39,22 +34,36 @@ def read_requirements(file_name, directory='.'): base_dir = os.path.dirname(os.path.abspath(__file__)) - install_requires = read_requirements('requirements-build.txt', base_dir) extras_require = { 'dev': read_requirements('requirements-test.txt', base_dir), } +# Copy src/run_tribler.py --> src/tribler/run.py to make it accessible in entry_points scripts. +# See: entry_points={"gui_scripts": ["tribler=tribler.run:main"]} in setup() below. +shutil.copy("src/run_tribler.py", "src/tribler/run.py") + +# Read the version from the version file: src/tribler/core/version.py +# Note that, for version.py to include the correct version, it should be generated first using git commands. +# For example: +# git describe --tags | python -c "import sys; print(next(sys.stdin).lstrip('v'))" > .TriblerVersion +# git rev-parse HEAD > .TriblerCommit +# Then, the version.py file can be generated using the following command: +# python build/update_version.py +version_file = os.path.join('src', 'tribler', 'core', 'version.py') +version = read_version_from_file(version_file) setup( - name="Tribler", + name="tribler", version=version, description="Privacy enhanced BitTorrent client with P2P content discovery", long_description=Path('README.rst').read_text(encoding="utf-8"), long_description_content_type="text/x-rst", author="Tribler Team", author_email="info@tribler.org", - url="https://www.tribler.org", + url="https://github.com/Tribler/tribler", + keywords='BitTorrent client, file sharing, peer-to-peer, P2P, TOR-like network', + python_requires='>=3.8', packages=find_packages(where="src"), package_dir={"": "src"}, include_package_data=True, @@ -68,12 +77,15 @@ def read_requirements(file_name, directory='.'): classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", - "License :: OSI Approved :: GPL-3.0 license", + "Intended Audience :: End Users/Desktop", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", - "Topic :: Internet :: File Sharing", + "Topic :: Communications :: File Sharing", "Topic :: Security :: Cryptography", "Operating System :: OS Independent", ], + options={"build_exe": build_exe_options}, + executables=[app_executable] ) From 65ebd2a590e0c8ceecfbe1a4afa8099381bd44dd Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Fri, 22 Mar 2024 13:59:38 +0100 Subject: [PATCH 08/12] Update Windows build script to use Cx_Freeze build --- build/win/makedist_win.bat | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/win/makedist_win.bat b/build/win/makedist_win.bat index f36214724dc..2844d46b009 100644 --- a/build/win/makedist_win.bat +++ b/build/win/makedist_win.bat @@ -48,7 +48,10 @@ REM packs them in the installer .EXE ECHO Install pip dependencies for correct py-installer's work python3 -m pip install --upgrade -r build\win\requirements.txt -%PYTHONHOME%\Scripts\pyinstaller.exe tribler.spec --log-level=%LOG_LEVEL% || exit /b +REM Sandip 2024-03-22: Deprecated, we are not using PyInstaller anymore because of issue with False Malware detections. +REM %PYTHONHOME%\Scripts\pyinstaller.exe tribler.spec --log-level=%LOG_LEVEL% || exit /b +ECHO Building Tribler using Cx_Freeze +python3 setup.py build copy build\win\resources\tribler*.nsi dist\tribler From 2a9fdd67ed3b05094fc63e4539a03c91aaa6e739 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Fri, 22 Mar 2024 16:24:16 +0100 Subject: [PATCH 09/12] Update build.py to build wheel package as well --- build.py | 145 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 61 deletions(-) diff --git a/build.py b/build.py index 19e99fdeee1..728f9e5d7ca 100644 --- a/build.py +++ b/build.py @@ -1,6 +1,16 @@ """ -This file includes the build configuration for the Tribler executable using CX Freeze. -The exports of this file are used in setup.py to build the executable. +This file includes the build configuration for the Tribler. +The exports of this file are used in setup.py to build the executable or wheel package. + +Building executable depends on cx_Freeze. + +1) If cx_Freeze is not installed, +setuptools is used to build the wheel package. + +To create a wheel package: +python setup.py bdist_wheel + +2) If cx_Freeze is installed, To create a build: python setup.py build @@ -19,64 +29,77 @@ from pathlib import Path from setuptools import find_packages -from cx_Freeze import setup, Executable - -app_name = "Tribler" if sys.platform != "linux" else "tribler" -app_script = "src/tribler/run.py" -app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" -app_executable = Executable( - target_name=app_name, - script=app_script, - base="Win32GUI" if sys.platform == "win32" else None, - icon=app_icon_path, -) - -# These packages will be included in the build -sys.path.insert(0, 'src') -included_packages = [ - "aiohttp_apispec", - "sentry_sdk", - "ipv8", - "PIL", - "pkg_resources", - "pydantic", - "pyqtgraph", - "PyQt5.QtTest", - "requests", - "tribler.core", - "tribler.gui", - "faker" -] - -# These files will be included in the build -included_files = [ - ("src/tribler/gui/qt_resources", "qt_resources"), - ("src/tribler/gui/images", "images"), - ("src/tribler/gui/i18n", "i18n"), - ("src/tribler/core", "tribler_source/tribler/core"), - ("src/tribler/gui", "tribler_source/tribler/gui"), - ("build/win/resources", "tribler_source/resources"), -] - -# These packages will be excluded from the build -excluded_packages = [ - 'wx', - 'PyQt4', - 'FixTk', - 'tcl', - 'tk', - '_tkinter', - 'tkinter', - 'Tkinter', - 'matplotlib' -] - -build_exe_options = { - "packages": included_packages, - "excludes": excluded_packages, - "include_files": included_files, - "include_msvcr": True, - 'build_exe': 'dist/tribler' -} + +try: + import cx_Freeze +except ImportError: + cx_Freeze = None + +if cx_Freeze is None: + # If cx_Freeze is not installed, use setuptools to build the wheel package + from setuptools import setup + app_executable = None + build_exe_options = {} + +else: + from cx_Freeze import setup, Executable + + app_name = "Tribler" if sys.platform != "linux" else "tribler" + app_script = "src/tribler/run.py" + app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" + app_executable = Executable( + target_name=app_name, + script=app_script, + base="Win32GUI" if sys.platform == "win32" else None, + icon=app_icon_path, + ) + + # These packages will be included in the build + sys.path.insert(0, 'src') + included_packages = [ + "aiohttp_apispec", + "sentry_sdk", + "ipv8", + "PIL", + "pkg_resources", + "pydantic", + "pyqtgraph", + "PyQt5.QtTest", + "requests", + "tribler.core", + "tribler.gui", + "faker" + ] + + # These files will be included in the build + included_files = [ + ("src/tribler/gui/qt_resources", "qt_resources"), + ("src/tribler/gui/images", "images"), + ("src/tribler/gui/i18n", "i18n"), + ("src/tribler/core", "tribler_source/tribler/core"), + ("src/tribler/gui", "tribler_source/tribler/gui"), + ("build/win/resources", "tribler_source/resources"), + ] + + # These packages will be excluded from the build + excluded_packages = [ + 'wx', + 'PyQt4', + 'FixTk', + 'tcl', + 'tk', + '_tkinter', + 'tkinter', + 'Tkinter', + 'matplotlib' + ] + + build_exe_options = { + "packages": included_packages, + "excludes": excluded_packages, + "include_files": included_files, + "include_msvcr": True, + 'build_exe': 'dist/tribler' + } __all__ = ["setup", "app_executable", "build_exe_options"] From bc0316ee20534a5e92a789f2d1cc9fc7a47e42fa Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 25 Mar 2024 14:38:18 +0100 Subject: [PATCH 10/12] Add libtorrent and ssl as additional explicit packages to include on binary build Add OpenSSL DLLs during build Move added DLLs to lib directory --- build.py | 4 +++- build/win/makedist_win.bat | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index 728f9e5d7ca..c8a9268efa9 100644 --- a/build.py +++ b/build.py @@ -68,7 +68,9 @@ "requests", "tribler.core", "tribler.gui", - "faker" + "faker", + "libtorrent", + "ssl", ] # These files will be included in the build diff --git a/build/win/makedist_win.bat b/build/win/makedist_win.bat index 2844d46b009..c198d786b04 100644 --- a/build/win/makedist_win.bat +++ b/build/win/makedist_win.bat @@ -70,9 +70,9 @@ REM copy C:\build\vc_redist_110.exe dist\tribler copy C:\build\vc_redist_140.exe dist\tribler REM Copy various libraries required on runtime (libsodium and openssl) -copy C:\build\libsodium.dll dist\tribler -REM Sandip, 2019-10-24: No need to copy openssl dlls separately -REM copy C:\build\openssl\*.dll dist\tribler +copy C:\build\libsodium.dll dist\tribler\lib +REM Sandip, 2024-03-26: Some openssl dlls are missing so need to be copied manually. +copy C:\build\openssl\*.dll dist\tribler\lib @echo Running NSIS From 7bcab352dca76a58acc65f5f76109ea5621119da Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 27 Mar 2024 12:00:55 +0100 Subject: [PATCH 11/12] Fix building wheel and binaries using setup.py --- build.py | 82 ++++++++++++++++++++++++++++++-------------------------- setup.py | 6 ++--- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/build.py b/build.py index c8a9268efa9..70563df6898 100644 --- a/build.py +++ b/build.py @@ -2,17 +2,15 @@ This file includes the build configuration for the Tribler. The exports of this file are used in setup.py to build the executable or wheel package. -Building executable depends on cx_Freeze. - -1) If cx_Freeze is not installed, -setuptools is used to build the wheel package. +There are two build options: +1) setuptools is used to build the wheel package. To create a wheel package: python setup.py bdist_wheel -2) If cx_Freeze is installed, +2) Building executable is done using cx_Freeze. -To create a build: +To build an executable: python setup.py build To create a distributable package: @@ -21,38 +19,23 @@ To create a distributable package for a specific platform: python setup.py bdist_mac python setup.py bdist_win + +Building wheel and building executable had to be separated because cx_Freeze does not +support building wheels. Therefore, the build options are separated into two functions +and the appropriate function is called based on the command line arguments. """ -import os -import re -import shutil import sys -from pathlib import Path -from setuptools import find_packages -try: - import cx_Freeze -except ImportError: - cx_Freeze = None - -if cx_Freeze is None: - # If cx_Freeze is not installed, use setuptools to build the wheel package +def get_wheel_build_options(): from setuptools import setup - app_executable = None - build_exe_options = {} + setup_options = {"build_exe": {}} + setup_executables = None + return setup, setup_options, setup_executables -else: - from cx_Freeze import setup, Executable - app_name = "Tribler" if sys.platform != "linux" else "tribler" - app_script = "src/tribler/run.py" - app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" - app_executable = Executable( - target_name=app_name, - script=app_script, - base="Win32GUI" if sys.platform == "win32" else None, - icon=app_icon_path, - ) +def get_freeze_build_options(): + from cx_Freeze import setup, Executable # These packages will be included in the build sys.path.insert(0, 'src') @@ -96,12 +79,35 @@ 'matplotlib' ] - build_exe_options = { - "packages": included_packages, - "excludes": excluded_packages, - "include_files": included_files, - "include_msvcr": True, - 'build_exe': 'dist/tribler' + setup_options = { + "build_exe": { + "packages": included_packages, + "excludes": excluded_packages, + "include_files": included_files, + "include_msvcr": True, + 'build_exe': 'dist/tribler' + } } -__all__ = ["setup", "app_executable", "build_exe_options"] + app_name = "Tribler" if sys.platform != "linux" else "tribler" + app_script = "src/tribler/run.py" + app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" + setup_executables = [ + Executable( + target_name=app_name, + script=app_script, + base="Win32GUI" if sys.platform == "win32" else None, + icon=app_icon_path, + ) + ] + return setup, setup_options, setup_executables + + +# Based on the command line arguments, get the build options. +# If the command line arguments include 'setup.py' and 'bdist_wheel', +# then the options are for building a wheel package. +# Otherwise, the options are for building an executable (any other). +if {'setup.py', 'bdist_wheel'}.issubset(sys.argv): + setup, setup_options, setup_executables = get_wheel_build_options() +else: + setup, setup_options, setup_executables = get_freeze_build_options() diff --git a/setup.py b/setup.py index 85e091cb9f3..ccfef951491 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import find_packages -from build import app_executable, build_exe_options, setup +from build import setup, setup_options, setup_executables def read_version_from_file(file_path): @@ -86,6 +86,6 @@ def read_requirements(file_name, directory='.'): "Topic :: Security :: Cryptography", "Operating System :: OS Independent", ], - options={"build_exe": build_exe_options}, - executables=[app_executable] + options=setup_options, + executables=setup_executables ) From fd4c1992987bb717367db4d2efbf3830f59ceb13 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 8 Apr 2024 13:33:29 +0200 Subject: [PATCH 12/12] Address pylint issues on build.py --- build.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/build.py b/build.py index 70563df6898..597f9f48f36 100644 --- a/build.py +++ b/build.py @@ -28,14 +28,14 @@ def get_wheel_build_options(): - from setuptools import setup - setup_options = {"build_exe": {}} - setup_executables = None - return setup, setup_options, setup_executables + from setuptools import setup as _setup # pylint: disable=import-outside-toplevel + _setup_options = {"build_exe": {}} + _setup_executables = None + return _setup, _setup_options, _setup_executables def get_freeze_build_options(): - from cx_Freeze import setup, Executable + from cx_Freeze import setup as _setup, Executable # pylint: disable=import-outside-toplevel # These packages will be included in the build sys.path.insert(0, 'src') @@ -79,7 +79,7 @@ def get_freeze_build_options(): 'matplotlib' ] - setup_options = { + _setup_options = { "build_exe": { "packages": included_packages, "excludes": excluded_packages, @@ -92,7 +92,7 @@ def get_freeze_build_options(): app_name = "Tribler" if sys.platform != "linux" else "tribler" app_script = "src/tribler/run.py" app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns" - setup_executables = [ + _setup_executables = [ Executable( target_name=app_name, script=app_script, @@ -100,7 +100,7 @@ def get_freeze_build_options(): icon=app_icon_path, ) ] - return setup, setup_options, setup_executables + return _setup, _setup_options, _setup_executables # Based on the command line arguments, get the build options.