Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TMP] temporary PR, do not merge #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://tribler.readthedocs.io/en/latest/development/development_on_linux.html>`_
* `Windows <http://tribler.readthedocs.io/en/latest/development/development_on_windows.html>`_
* `macOS <http://tribler.readthedocs.io/en/latest/development/development_on_osx.html>`_
* `Linux <http://tribler.readthedocs.io/en/latest/development/development_on_linux.html>`__
* `Windows <http://tribler.readthedocs.io/en/latest/development/development_on_windows.html>`__
* `macOS <http://tribler.readthedocs.io/en/latest/development/development_on_osx.html>`__



Expand All @@ -59,9 +59,9 @@ Packaging Tribler

We have written guides on how to package Tribler for distribution on various systems.

* `Linux <http://tribler.readthedocs.io/en/latest/building/building.html>`_
* `Windows <http://tribler.readthedocs.io/en/latest/building/building_on_windows.html>`_
* `macOS <http://tribler.readthedocs.io/en/latest/building/building_on_osx.html>`_
* `Linux <http://tribler.readthedocs.io/en/latest/building/building.html>`__
* `Windows <http://tribler.readthedocs.io/en/latest/building/building_on_windows.html>`__
* `macOS <http://tribler.readthedocs.io/en/latest/building/building_on_osx.html>`__


Docker support
Expand Down
113 changes: 113 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 7 additions & 4 deletions build/win/makedist_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
3 changes: 2 additions & 1 deletion requirements-build.txt
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
91 changes: 91 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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
)
6 changes: 5 additions & 1 deletion src/run_tribler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading