From 5ab54763c6270c9d9c4dcb3cf2d382c6647d8bf6 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 5 Apr 2024 17:51:26 +0000 Subject: [PATCH] remove pyoxidizer (unmaintained) partially reverts e430b2567a8e478a93c80809a16cb83acb9c2e3c the remaining stuff might be useful for other cpython alternatives --- copyparty/__init__.py | 1 - copyparty/__main__.py | 34 +++++----------------------- copyparty/mtag.py | 3 +-- docs/pyoxidizer.txt | 52 ------------------------------------------- pyoxidizer.bzl | 48 --------------------------------------- scripts/make-sfx.sh | 34 ++-------------------------- 6 files changed, 8 insertions(+), 164 deletions(-) delete mode 100644 docs/pyoxidizer.txt delete mode 100644 pyoxidizer.bzl diff --git a/copyparty/__init__.py b/copyparty/__init__.py index 2830fbba..dc99255f 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -56,7 +56,6 @@ class EnvParams(object): self.t0 = time.time() self.mod = "" self.cfg = "" - self.ox = getattr(sys, "oxidized", None) E = EnvParams() diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 5de0ae7f..015cf373 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -157,7 +157,8 @@ def warn(msg: str) -> None: def init_E(EE: EnvParams) -> None: - # __init__ runs 18 times when oxidized; do expensive stuff here + # some cpython alternatives (such as pyoxidizer) can + # __init__ several times, so do expensive stuff here E = EE # pylint: disable=redefined-outer-name @@ -190,34 +191,9 @@ def init_E(EE: EnvParams) -> None: raise Exception("could not find a writable path for config") - def _unpack() -> str: - import atexit - import tarfile - import tempfile - from importlib.resources import open_binary - - td = tempfile.TemporaryDirectory(prefix="") - atexit.register(td.cleanup) - tdn = td.name - - with open_binary("copyparty", "z.tar") as tgz: - with tarfile.open(fileobj=tgz) as tf: - try: - tf.extractall(tdn, filter="tar") - except TypeError: - tf.extractall(tdn) # nosec (archive is safe) - - return tdn - - try: - E.mod = os.path.dirname(os.path.realpath(__file__)) - if E.mod.endswith("__init__"): - E.mod = os.path.dirname(E.mod) - except: - if not E.ox: - raise - - E.mod = _unpack() + E.mod = os.path.dirname(os.path.realpath(__file__)) + if E.mod.endswith("__init__"): + E.mod = os.path.dirname(E.mod) if sys.platform == "win32": bdir = os.environ.get("APPDATA") or os.environ.get("TEMP") or "." diff --git a/copyparty/mtag.py b/copyparty/mtag.py index d630fb63..9d2ba6f8 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -551,8 +551,7 @@ class MTag(object): pypath = str(os.pathsep.join(zsl)) env["PYTHONPATH"] = pypath except: - if not E.ox and not EXE: - raise + raise # might be expected outside cpython ret: dict[str, Any] = {} for tagname, parser in sorted(parsers.items(), key=lambda x: (x[1].pri, x[0])): diff --git a/docs/pyoxidizer.txt b/docs/pyoxidizer.txt deleted file mode 100644 index b277008d..00000000 --- a/docs/pyoxidizer.txt +++ /dev/null @@ -1,52 +0,0 @@ -pyoxidizer doesn't crosscompile yet so need to build in a windows vm, -luckily possible to do mostly airgapped (https-proxy for crates) - -none of this is version-specific but doing absolute links just in case -(only exception is py3.8 which is the final win7 ver) - -# deps (download on linux host): -https://www.python.org/ftp/python/3.10.7/python-3.10.7-amd64.exe -https://github.com/indygreg/PyOxidizer/releases/download/pyoxidizer%2F0.22.0/pyoxidizer-0.22.0-x86_64-pc-windows-msvc.zip -https://github.com/upx/upx/releases/download/v3.96/upx-3.96-win64.zip -https://static.rust-lang.org/dist/rust-1.61.0-x86_64-pc-windows-msvc.msi -https://github.com/indygreg/python-build-standalone/releases/download/20220528/cpython-3.8.13%2B20220528-i686-pc-windows-msvc-static-noopt-full.tar.zst - -# need cl.exe, prefer 2017 -- download on linux host: -https://visualstudio.microsoft.com/downloads/?q=build+tools -https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-history#release-dates-and-build-numbers -https://aka.ms/vs/15/release/vs_buildtools.exe # 2017 -https://aka.ms/vs/16/release/vs_buildtools.exe # 2019 -https://aka.ms/vs/17/release/vs_buildtools.exe # 2022 -https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2017 - -# use disposable w10 vm to prep offline installer; xfer to linux host with firefox to copyparty -vs_buildtools-2017.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.Windows10SDK.17763 --layout c:\msbt2017 --lang en-us - -# need two proxies on host; s5s or ssh for msys2(socks5), and tinyproxy for rust(http) -UP=- python3 socks5server.py 192.168.123.1 4321 -ssh -vND 192.168.123.1:4321 localhost -git clone https://github.com/tinyproxy/tinyproxy.git - ./autogen.sh - ./configure --prefix=/home/ed/pe/tinyproxy - make -j24 install - printf '%s\n' >cfg "Port 4380" "Listen 192.168.123.1" - ./tinyproxy -dccfg - -https://github.com/msys2/msys2-installer/releases/download/2022-09-04/msys2-x86_64-20220904.exe -export all_proxy=socks5h://192.168.123.1:4321 -# if chat dies after auth (2 messages) it probably failed dns, note the h in socks5h to tunnel dns -pacman -Syuu -pacman -S git patch mingw64/mingw-w64-x86_64-zopfli -cd /c && curl -k https://192.168.123.1:3923/ro/ox/msbt2017/?tar | tar -xv - -first install certs from msbt/certificates then admin-cmd `vs_buildtools.exe --noweb`, -default selection (vc++2017-v15.9-v14.16, vc++redist, vc++bt-core) += win10sdk (for io.h) - -install rust without documentation, python 3.10, put upx and pyoxidizer into ~/bin, -[cmd.exe] python -m pip install --user -U wheel-0.37.1.tar.gz strip-hints-0.1.10.tar.gz -p=192.168.123.1:4380; export https_proxy=$p; export http_proxy=$p - -# and with all of the one-time-setup out of the way, -mkdir /c/d; cd /c/d && curl -k https://192.168.123.1:3923/cpp/gb?pw=wark > gb && git clone gb copyparty -cd /c/d/copyparty/ && curl -k https://192.168.123.1:3923/cpp/patch?pw=wark | patch -p1 -cd /c/d/copyparty/scripts && CARGO_HTTP_CHECK_REVOKE=false PATH=/c/Users/$USER/AppData/Local/Programs/Python/Python310:/c/Users/$USER/bin:"$(cygpath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86"):$PATH" ./make-sfx.sh ox ultra diff --git a/pyoxidizer.bzl b/pyoxidizer.bzl deleted file mode 100644 index 9e213e2e..00000000 --- a/pyoxidizer.bzl +++ /dev/null @@ -1,48 +0,0 @@ -# builds win7-i386 exe on win10-ltsc-1809(17763.316) -# see docs/pyoxidizer.txt - -def make_exe(): - dist = default_python_distribution(flavor="standalone_static", python_version="3.8") - policy = dist.make_python_packaging_policy() - policy.allow_files = True - policy.allow_in_memory_shared_library_loading = True - #policy.bytecode_optimize_level_zero = True - #policy.include_distribution_sources = False # error instantiating embedded Python interpreter: during initializing Python main: init_fs_encoding: failed to get the Python codec of the filesystem encoding - policy.include_distribution_resources = False - policy.include_non_distribution_sources = False - policy.include_test = False - python_config = dist.make_python_interpreter_config() - #python_config.module_search_paths = ["$ORIGIN/lib"] - - python_config.run_module = "copyparty" - exe = dist.to_python_executable( - name="copyparty", - config=python_config, - packaging_policy=policy, - ) - exe.windows_runtime_dlls_mode = "never" - exe.windows_subsystem = "console" - exe.add_python_resources(exe.read_package_root( - path="sfx", - packages=[ - "copyparty", - "jinja2", - "markupsafe", - "pyftpdlib", - "python-magic", - ] - )) - return exe - -def make_embedded_resources(exe): - return exe.to_embedded_resources() - -def make_install(exe): - files = FileManifest() - files.add_python_resource("copyparty", exe) - return files - -register_target("exe", make_exe) -register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True) -register_target("install", make_install, depends=["exe"], default=True) -resolve_targets() diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index dd9b817d..418793e1 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -16,8 +16,6 @@ help() { exec cat <<'EOF' # `re` does a repack of an sfx which you already executed once # (grabs files from the sfx-created tempdir), overrides `clean` # -# `ox` builds a pyoxidizer exe instead of py -# # `gz` creates a gzip-compressed python sfx instead of bzip2 # # `lang` limits which languages/translations to include, @@ -111,7 +109,6 @@ while [ ! -z "$1" ]; do case $1 in clean) clean=1 ; ;; re) repack=1 ; ;; - ox) use_ox=1 ; ;; gz) use_gz=1 ; ;; gzz) shift;use_gzz=$1;use_gz=1; ;; no-ftp) no_ftp=1 ; ;; @@ -461,8 +458,8 @@ rm -f ftp/pyftpdlib/{__main__,prefork}.py iawk '/^\}/{l=0} !l; /^var Ls =/{l=1;next} o; /^\t["}]/{o=0} /^\t"'"$langs"'"/{o=1;print}' $f done -[ ! $repack ] && [ ! $use_ox ] && { - # uncomment; oxidized drops 45 KiB but becomes undebuggable +[ ! $repack ] && { + # uncomment find | grep -E '\.py$' | grep -vE '__version__' | tr '\n' '\0' | @@ -570,33 +567,6 @@ nf=$(ls -1 "$zdir"/arc.* 2>/dev/null | wc -l) } -[ $use_ox ] && { - tgt=x86_64-pc-windows-msvc - tgt=i686-pc-windows-msvc # 2M smaller (770k after upx) - bdir=build/$tgt/release/install/copyparty - - t="res web" - (printf "\n\n\nBUT WAIT! THERE'S MORE!!\n\n"; - cat ../$bdir/COPYING.txt) >> copyparty/res/COPYING.txt || - echo "copying.txt 404 pls rebuild" - - mv ftp/* j2/* . - rm -rf ftp j2 py2 py37 - (cd copyparty; tar -cvf z.tar $t; rm -rf $t) - cd .. - pyoxidizer build --release --target-triple $tgt - mv $bdir/copyparty.exe dist/ - cp -pv "$(for d in '/c/Program Files (x86)/Microsoft Visual Studio/'*'/BuildTools/VC/Redist/MSVC'; do - find "$d" -name vcruntime140.dll; done | sort | grep -vE '/x64/|/onecore/' | head -n 1)" dist/ - dist/copyparty.exe --version - cp -pv dist/copyparty{,.orig}.exe - [ $ultra ] && a="--best --lzma" || a=-1 - /bin/time -f %es upx $a dist/copyparty.exe >/dev/null - ls -al dist/copyparty{,.orig}.exe - exit 0 -} - - echo gen tarlist for d in copyparty partftpy magic j2 py2 py37 ftp; do find $d -type f || true; done | # strip_hints sed -r 's/(.*)\.(.*)/\2 \1/' | LC_ALL=C sort |