Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from egbertbouman/build
Browse files Browse the repository at this point in the history
Fix build scripts
  • Loading branch information
egbertbouman committed Aug 1, 2024
2 parents c2ef78f + b2fa912 commit 668dae2
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exclude = [
"build",
"dist",
"node_modules",
"src/tribler/gui",
"src/tribler/ui",
"venv",
]

Expand Down
7 changes: 7 additions & 0 deletions build/debian/makedist_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ python3 -m pip install --upgrade -r requirements-build.txt
python3 ./build/update_version.py -r .
python3 ./build/debian/update_metainfo.py -r .

# ----- Build UI
pushd .
cd src/tribler/ui/
npm install
npm run build
popd

# ----- Build binaries
echo Building Tribler using Cx_Freeze
python3 setup.py build
Expand Down
9 changes: 9 additions & 0 deletions build/mac/makedist_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ python3 -m venv "${BUILD_ENV}"
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade -r requirements-build.txt

# ----- Build UI

pushd .
cd src/tribler/ui/
npm install
npm run build
rm -rf node_modules
popd

# ----- Build

pyinstaller tribler.spec --log-level="${LOG_LEVEL}"
Expand Down
21 changes: 15 additions & 6 deletions build/win/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
and the appropriate function is called based on the command line arguments.
"""
import sys
import platform


def get_wheel_build_options():
Expand All @@ -43,20 +44,23 @@ def get_freeze_build_options():
included_packages = [
"aiohttp_apispec",
"pkg_resources",
"pyqtgraph",
"requests",
"tribler.core",
"tribler.gui",
"libtorrent",
"ssl",
]

if platform.system() != 'Windows':
included_packages.append("gi")

# These files will be included in the build
included_files = [
("src/tribler/gui/qt_resources", "qt_resources"),
("src/tribler/gui/images", "images"),
("src/tribler/ui/public", "lib/tribler/ui/public"),
("src/tribler/ui/dist", "lib/tribler/ui/dist"),

("src/tribler/core", "tribler_source/tribler/core"),
("src/tribler/gui", "tribler_source/tribler/gui"),
("src/tribler/ui/public", "tribler_source/tribler/ui/public"),
("src/tribler/ui/dist", "tribler_source/tribler/ui/dist"),
("build/win/resources", "tribler_source/resources"),
]

Expand All @@ -70,7 +74,9 @@ def get_freeze_build_options():
'_tkinter',
'tkinter',
'Tkinter',
'matplotlib'
'matplotlib',
'numpy',
'tribler.ui'
]

_setup_options = {
Expand All @@ -82,6 +88,9 @@ def get_freeze_build_options():
'build_exe': 'dist/tribler'
}
}
if platform.system() == 'Linux':
_setup_options["build_exe"]["bin_includes"] = "libffi.so"


app_name = "Tribler" if sys.platform != "linux" else "tribler"
app_script = "src/tribler/run.py"
Expand Down
7 changes: 7 additions & 0 deletions build/win/makedist_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ if defined VENV (
call python3 -m pip install --upgrade pip
call python3 -m pip install --upgrade -r requirements-build.txt

REM ----- Build UI
pushd .
cd src/tribler/ui/
call npm install
call npm run build
popd

REM ----- Build

REM Arno: When adding files here, make sure tribler.nsi actually
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ pillow
pony
pystray
pywin32;sys_platform=="win32"

PyQt5
numpy
pyqtgraph
3 changes: 2 additions & 1 deletion src/run_tribler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path

import pystray
import tribler
from PIL import Image
from tribler.core.session import Session
from tribler.tribler_config import TriblerConfigManager
Expand Down Expand Up @@ -85,7 +86,7 @@ async def main() -> None:
session = Session(config)
await session.start()

image_path = Path(__file__).absolute() / "../tribler/ui/public/tribler.png"
image_path = Path(tribler.__file__).parent / "ui/public/tribler.png"
image = Image.open(image_path.resolve())
url = f"http://localhost:{session.rest_manager.get_api_port()}/ui/#/downloads/all?key={config.get('api/key')}"
menu = (pystray.MenuItem('Open', lambda: webbrowser.open_new_tab(url)),
Expand Down
8 changes: 5 additions & 3 deletions src/tribler/core/restapi/file_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import contextlib
import logging
import sys
import platform
from pathlib import Path

import win32api
from aiohttp import web

from tribler.core.restapi.rest_endpoint import HTTP_NOT_FOUND, RESTEndpoint, RESTResponse

if platform.system() == 'Windows':
import win32api


class FileEndpoint(RESTEndpoint):
"""
Expand All @@ -33,7 +35,7 @@ async def browse(self, request: web.Request) -> RESTResponse:
show_files = request.query.get('files') == "1"

# Deal with getting the drives on Windows
if path == "/" and sys.platform == 'win32':
if path == "/" and platform.system() == 'Windows':
paths = []
for drive in win32api.GetLogicalDriveStrings().split("\000"):
if not drive:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/socks5/aiohttp_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def __init__(self, proxy_addr: tuple, **kwargs) -> None:

async def _wrap_create_connection(self, # type: ignore[override]
protocol_factory: Callable[[], Socks5ClientUDPConnection],
host: str, port: int,
**kwargs) -> tuple[BaseTransport, Socks5ClientUDPConnection]:
"""
Create a transport and its associated connection.
"""
client = Socks5Client(self.proxy_addr, lambda *_: None)
host, port = kwargs.pop("addr_infos")[0][-1]

if "timeout" in kwargs and hasattr(kwargs["timeout"], "sock_connect"):
await wait_for(client.connect_tcp((host, port)), timeout=kwargs["timeout"].sock_connect)
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tribler-webui",
"private": true,
"version": "0.1",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
5 changes: 3 additions & 2 deletions src/tribler/ui/src/pages/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
import { triblerService } from "@/services/tribler.service";
import { Torrent } from "@/models/torrent.model";
import { ColumnDef } from "@tanstack/react-table";
import { categoryIcon, formatBytes, formatTimeAgo, getMagnetLink } from "@/lib/utils";
import { categoryIcon, filterDuplicates, formatBytes, formatTimeAgo, getMagnetLink } from "@/lib/utils";
import SaveAs from "@/dialogs/SaveAs";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { useSearchParams } from "react-router-dom";
Expand Down Expand Up @@ -69,7 +69,8 @@ export default function Search() {
useEffect(() => {
const searchTorrents = async () => {
if (!query) return;
setTorrents((await triblerService.searchTorrentsLocal(query, true)));
const localResults = await triblerService.searchTorrentsLocal(query, true);
setTorrents(filterDuplicates(localResults, 'infohash'));
const remoteQuery = await triblerService.searchTorrentsRemote(query, true);
setRequest(remoteQuery.request_uuid);
}
Expand Down
31 changes: 3 additions & 28 deletions tribler.spec
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ show_console = os.environ.get('SHOW_CONSOLE', 'false') == 'true'
if sys.platform == 'darwin':
show_console = True

widget_files = []
for file in os.listdir(os.path.join(src_dir, "tribler", "gui", "widgets")):
if file.endswith(".py"):
widget_files.append('tribler.gui.widgets.%s' % file[:-3])

data_to_copy = [
(os.path.join(src_dir, "tribler", "gui", "qt_resources"), 'qt_resources'),
(os.path.join(src_dir, "tribler", "gui", "images"), 'images'),
(os.path.join(src_dir, "tribler", "core"), 'tribler_source/tribler/core'),
(os.path.join(src_dir, "tribler", "gui"), 'tribler_source/tribler/gui'),
(os.path.join(src_dir, "tribler", "ui", "public"), 'tribler_source/tribler/ui/public'),
(os.path.join(src_dir, "tribler", "ui", "dist"), 'tribler_source/tribler/ui/dist'),
(os.path.join(root_dir, "build", "win", "resources"), 'tribler_source/resources'),

(os.path.dirname(aiohttp_apispec.__file__), 'aiohttp_apispec')
]

Expand All @@ -65,10 +60,6 @@ ttf_path = os.path.join("/usr", "share", "fonts", "truetype", "noto", "NotoColor
if sys.platform.startswith('linux') and os.path.exists(ttf_path):
data_to_copy += [(ttf_path, 'fonts')]

# fixes ZeroDivisionError in pyqtgraph\graphicsItems\ButtonItem.py
# https://issueexplorer.com/issue/pyqtgraph/pyqtgraph/1811
data_to_copy += collect_data_files("pyqtgraph", includes=["**/*.ui", "**/*.png", "**/*.svg"])

excluded_libs = ['wx', 'PyQt4', 'FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter', 'matplotlib']

# Pony dependencies; each packages need to be added separatedly; added as hidden import
Expand All @@ -85,18 +76,12 @@ hiddenimports = [
# 'pkg_resources.py2_warn', # Workaround PyInstaller & SetupTools, https://github.com/pypa/setuptools/issues/1963
'pyaes',
'pydantic',
'pyqtgraph',
'pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
'pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
'pyqtgraph.imageview.ImageViewTemplate_pyqt5',
'PyQt5.QtTest',
'requests',
'scrypt', '_scrypt',
'sqlalchemy', 'sqlalchemy.ext.baked', 'sqlalchemy.ext.declarative',
'tribler.core.logger.logger_streams',
'typing_extensions',
]
hiddenimports += widget_files
hiddenimports += pony_deps
hiddenimports += [x for member in known_components.__dict__.values() for x in getattr(member, "hiddenimports", set())]

Expand All @@ -109,10 +94,6 @@ if sys.platform.startswith('linux'):
# https://github.com/pyinstaller/pyinstaller/issues/5359
hiddenimports += collect_submodules('pydantic')

# fixes ZeroDivisionError in pyqtgraph\graphicsItems\ButtonItem.py
# https://issueexplorer.com/issue/pyqtgraph/pyqtgraph/1811
hiddenimports += collect_submodules("pyqtgraph", filter=lambda name: "Template" in name)

sys.modules['FixTk'] = None
a = Analysis(['src/run_tribler.py'],
pathex=[''],
Expand Down Expand Up @@ -164,9 +145,3 @@ app = BUNDLE(coll,
# Replace the Info.plist file on MacOS
if sys.platform == 'darwin':
shutil.copy('build/mac/resources/Info.plist', 'dist/Tribler.app/Contents/Info.plist')

# On Windows 10, we have to make sure that qwindows.dll is in the right path
if sys.platform == 'win32':
shutil.copytree(os.path.join('dist', 'tribler', 'PyQt5', 'Qt', 'plugins', 'platforms'),
os.path.join('dist', 'tribler', 'platforms'))

0 comments on commit 668dae2

Please sign in to comment.