From 656f0a6c39099058bb8eb9fe76d77e765edb588a Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 4 Oct 2025 21:33:01 +0000 Subject: [PATCH] unvendorable ifaddr (#887); stolen/ifaddr/ can be deleted and replaced with system lib; this is safe and will not affect any functionality --- README.md | 13 +++++++++++++ copyparty/tcpsrv.py | 3 +-- copyparty/util.py | 26 ++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6dac1f8c..121ea63e 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ made in Norway 🇳🇴 * [dependencies](#dependencies) - mandatory deps * [optional dependencies](#optional-dependencies) - install these to enable bonus features * [dependency chickenbits](#dependency-chickenbits) - prevent loading an optional dependency + * [dependency unvendoring](#dependency-unvendoring) - force use of system modules * [optional gpl stuff](#optional-gpl-stuff) * [sfx](#sfx) - the self-contained "binary" (recommended!) * [copyparty.exe](#copypartyexe) - download [copyparty.exe](https://github.com/9001/copyparty/releases/latest/download/copyparty.exe) (win8+) or [copyparty32.exe](https://github.com/9001/copyparty/releases/latest/download/copyparty32.exe) (win7+) @@ -2991,6 +2992,18 @@ example: `PRTY_NO_PIL=1 python3 copyparty-sfx.py` * python2.7 on windows: `PRTY_NO_FFMPEG` + `PRTY_NO_FFPROBE` saves startup time +### dependency unvendoring + +force use of system modules instead of the vendored versions: + +| env-var | what it does | +| -------------------- | ------------ | +| `PRTY_SYS_ALL` | all of the below | +| `PRTY_SYS_IFADDR` | replace [stolen/ifaddr](./copyparty/stolen/ifaddr) with [upstream](https://pypi.org/project/ifaddr/) | + +to debug, run copyparty with `PRTY_MODSPEC=1` to see where it's getting each module from + + ## optional gpl stuff some bundled tools have copyleft dependencies, see [./bin/#mtag](bin/#mtag) diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index c44adf8e..72638d23 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -21,6 +21,7 @@ from .util import ( VF_CAREFUL, Netdev, atomic_move, + get_adapters, min_ex, sunpack, termsize, @@ -456,8 +457,6 @@ class TcpSrv(object): self._distribute_netdevs() def detect_interfaces(self, listen_ips: list[str]) -> dict[str, Netdev]: - from .stolen.ifaddr import get_adapters - listen_ips = [x for x in listen_ips if not x.startswith(("unix:", "fd:"))] nics = get_adapters(True) diff --git a/copyparty/util.py b/copyparty/util.py index d51a5531..e10ca14d 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -136,6 +136,25 @@ try: except: pass +try: + if os.environ.get("PRTY_NO_IFADDR"): + raise Exception() + try: + if os.getenv("PRTY_SYS_ALL") or os.getenv("PRTY_SYS_IFADDR"): + raise ImportError() + + from .stolen.ifaddr import get_adapters + except ImportError: + from ifaddr import get_adapters + + HAVE_IFADDR = True +except: + HAVE_IFADDR = False + + def get_adapters(include_unconfigured=False): + return [] + + try: if os.environ.get("PRTY_NO_SQLITE"): raise Exception() @@ -173,6 +192,11 @@ try: except: pass +if os.getenv("PRTY_MODSPEC"): + from inspect import getsourcefile + + print("PRTY_MODSPEC: ifaddr:", getsourcefile(get_adapters)) + if True: # pylint: disable=using-constant-test import types from collections.abc import Callable, Iterable @@ -2928,8 +2952,6 @@ def read_socket_chunked( def list_ips() -> list[str]: - from .stolen.ifaddr import get_adapters - ret: set[str] = set() for nic in get_adapters(): for ipo in nic.ips: