mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Remove code to fix obscure cx_Freeze bug
This commit is contained in:
parent
b26e7cb0df
commit
06aac69087
@ -26,85 +26,6 @@ import cx_Freeze
|
||||
from cx_Freeze import setup, Executable
|
||||
from setuptools import find_packages
|
||||
|
||||
# There's an obscure cx_Freeze bug that I'm hitting that's preventing the macOS
|
||||
# package from getting built. This is some monkeypatching to fix it.
|
||||
|
||||
if platform.system() == "Darwin" or platform.system() == "Linux":
|
||||
import importlib_metadata
|
||||
import pathlib
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
class CustomPackagePath(pathlib.PurePosixPath):
|
||||
def __init__(self, filename):
|
||||
self.long_filename = str(filename)
|
||||
self.short_filename = "/".join(filename.as_posix().split("/")[-2:])
|
||||
super(CustomPackagePath, self).__init__()
|
||||
|
||||
def read_text(self, encoding="utf-8"):
|
||||
with self.locate().open(encoding=encoding) as stream:
|
||||
return stream.read()
|
||||
|
||||
def read_binary(self):
|
||||
with self.locate().open("rb") as stream:
|
||||
return stream.read()
|
||||
|
||||
def locate(self):
|
||||
return Path(self.long_filename)
|
||||
|
||||
def as_posix(self):
|
||||
return self.short_filename
|
||||
|
||||
class DistributionCache(importlib_metadata.PathDistribution):
|
||||
_cachedir = TemporaryDirectory(prefix="cxfreeze-")
|
||||
|
||||
@staticmethod
|
||||
def at(path):
|
||||
return DistributionCache(Path(path))
|
||||
|
||||
at.__doc__ = importlib_metadata.PathDistribution.at.__doc__
|
||||
|
||||
@classmethod
|
||||
def from_name(cls, name):
|
||||
distribution = super().from_name(name)
|
||||
temp_dir = Path(cls._cachedir.name)
|
||||
dist_dir = None
|
||||
files = distribution.files or []
|
||||
prep = importlib_metadata.Prepared(distribution.name)
|
||||
normalized = prep.normalized
|
||||
legacy_normalized = prep.legacy_normalized
|
||||
for file in files:
|
||||
# patch: the onionshare and onionshare_cli files are using absolute paths, which break everything
|
||||
if name in ["onionshare", "onionshare_cli"]:
|
||||
if ".dist-info" not in file.as_posix():
|
||||
continue
|
||||
|
||||
file = CustomPackagePath(file)
|
||||
|
||||
if (
|
||||
not file.match(f"{name}-*.dist-info/*")
|
||||
and not file.match(f"{distribution.name}-*.dist-info/*")
|
||||
and not file.match(f"{normalized}-*.dist-info/*")
|
||||
and not file.match(f"{legacy_normalized}-*.dist-info/*")
|
||||
):
|
||||
continue
|
||||
src_path = file.locate()
|
||||
if not src_path.exists():
|
||||
continue
|
||||
dst_path = temp_dir / file.as_posix()
|
||||
if dist_dir is None:
|
||||
dist_dir = dst_path.parent
|
||||
dist_dir.mkdir(exist_ok=True)
|
||||
shutil.copy2(src_path, dst_path)
|
||||
if dist_dir is None:
|
||||
raise importlib_metadata.PackageNotFoundError(name)
|
||||
return cls.at(dist_dir)
|
||||
|
||||
from_name.__doc__ = importlib_metadata.PathDistribution.from_name.__doc__
|
||||
|
||||
#cx_Freeze.module.DistributionCache = DistributionCache
|
||||
|
||||
|
||||
# Discover the version
|
||||
with open(os.path.join("..", "cli", "onionshare_cli", "resources", "version.txt")) as f:
|
||||
version = f.read().strip()
|
||||
|
Loading…
Reference in New Issue
Block a user