From 3650bb815f9dfed0a373973c8c7bfc975894fecc Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 18 Mar 2024 14:51:14 +0100 Subject: [PATCH] review --- MANIFEST.in | 9 ++ README.rst | 12 +- build.py | 113 ++++++++++++++++++ build/win/makedist_win.bat | 11 +- pyproject.toml | 3 + requirements-build.txt | 3 +- setup.py | 91 ++++++++++++++ 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 14 files changed, 236 insertions(+), 12 deletions(-) create mode 100644 MANIFEST.in create mode 100644 build.py 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..1d16829087d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,9 @@ +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 * +include requirements*.txt 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..597f9f48f36 --- /dev/null +++ b/build.py @@ -0,0 +1,113 @@ +""" +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. + +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) Building executable is done using cx_Freeze. + +To build an executable: +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 + +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 sys + + +def get_wheel_build_options(): + 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 as _setup, Executable # pylint: disable=import-outside-toplevel + + # 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", + "libtorrent", + "ssl", + ] + + # 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' + ] + + _setup_options = { + "build_exe": { + "packages": included_packages, + "excludes": excluded_packages, + "include_files": included_files, + "include_msvcr": True, + 'build_exe': 'dist/tribler' + } + } + + 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/build/win/makedist_win.bat b/build/win/makedist_win.bat index f36214724dc..c198d786b04 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 @@ -67,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 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/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 new file mode 100644 index 00000000000..ccfef951491 --- /dev/null +++ b/setup.py @@ -0,0 +1,91 @@ +import os +import re +import shutil +from pathlib import Path + +from setuptools import find_packages + +from build import setup, setup_options, setup_executables + + +def read_version_from_file(file_path): + 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) + if version_match: + version_str = version_match.group(1) + return version_str.split("-")[0] + raise RuntimeError("Unable to find version string.") + + +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), +} + +# 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", + 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://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, + install_requires=install_requires, + extras_require=extras_require, + entry_points={ + "gui_scripts": [ + "tribler=tribler.run:main", + ] + }, + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "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 :: Communications :: File Sharing", + "Topic :: Security :: Cryptography", + "Operating System :: OS Independent", + ], + options=setup_options, + executables=setup_executables +) 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