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

Bump cryptography from 39.0.1 to 40.0.1 #101

Closed
wants to merge 2 commits 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
200 changes: 200 additions & 0 deletions cactus/pyinstaller.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# -*- mode: python ; coding: utf-8 -*-
import importlib
import os
import pathlib
import platform
import sysconfig

from pkg_resources import get_distribution

from PyInstaller.utils.hooks import collect_submodules, copy_metadata

THIS_IS_WINDOWS = platform.system().lower().startswith("win")
THIS_IS_MAC = platform.system().lower().startswith("darwin")

ROOT = pathlib.Path(importlib.import_module("cactus").__file__).absolute().parent.parent


def solve_name_collision_problem(analysis):
"""
There is a collision between the `cactus` file name (which is the executable)
and the `cactus` directory, which contains non-code resources like `english.txt`.
We move all the resources in the zipped area so there is no
need to create the `cactus` directory, since the names collide.

Fetching data now requires going into a zip file, so it will be slower.
It's best if files that are used frequently are cached.

A sample large compressible file (1 MB of `/dev/zero`), seems to be
about eight times slower.

Note that this hack isn't documented, but seems to work.
"""

zipped = []
datas = []
for data in analysis.datas:
if str(data[0]).startswith("cactus/"):
zipped.append(data)
else:
datas.append(data)

# items in this field are included in the binary
analysis.zipped_data = zipped

# these items will be dropped in the root folder uncompressed
analysis.datas = datas


keyring_imports = collect_submodules("keyring.backends")

# keyring uses entrypoints to read keyring.backends from metadata file entry_points.txt.
keyring_datas = copy_metadata("keyring")[0]

version_data = copy_metadata(get_distribution("cactus-blockchain"))[0]

block_cipher = None

SERVERS = [
"data_layer",
"wallet",
"full_node",
"harvester",
"farmer",
"introducer",
"timelord",
]

# TODO: collapse all these entry points into one `cactus_exec` entrypoint that accepts the server as a parameter

entry_points = ["cactus.cmds.cactus"] + [f"cactus.server.start_{s}" for s in SERVERS]

hiddenimports = []
hiddenimports.extend(entry_points)
hiddenimports.extend(keyring_imports)

binaries = []

if os.path.exists(f"{ROOT}/madmax/cactus_plot"):
binaries.extend([
(
f"{ROOT}/madmax/cactus_plot",
"madmax"
)
])

if os.path.exists(f"{ROOT}/madmax/cactus_plot_k34",):
binaries.extend([
(
f"{ROOT}/madmax/cactus_plot_k34",
"madmax"
)
])

if os.path.exists(f"{ROOT}/bladebit/bladebit"):
binaries.extend([
(
f"{ROOT}/bladebit/bladebit",
"bladebit"
)
])

if THIS_IS_WINDOWS:
hiddenimports.extend(["win32timezone", "win32cred", "pywintypes", "win32ctypes.pywin32"])

# this probably isn't necessary
if THIS_IS_WINDOWS:
entry_points.extend(["aiohttp", "cactus.util.bip39"])

if THIS_IS_WINDOWS:
cactus_mod = importlib.import_module("cactus")
dll_paths = pathlib.Path(sysconfig.get_path("platlib")) / "*.dll"

binaries = [
(
dll_paths,
".",
),
(
"C:\\Windows\\System32\\msvcp140.dll",
".",
),
(
"C:\\Windows\\System32\\vcruntime140_1.dll",
".",
),
]


datas = []

datas.append((f"{ROOT}/cactus/util/english.txt", "cactus/util"))
datas.append((f"{ROOT}/cactus/util/initial-config.yaml", "cactus/util"))
datas.append((f"{ROOT}/cactus/wallet/puzzles/*.hex", "cactus/wallet/puzzles"))
datas.append((f"{ROOT}/cactus/ssl/*", "cactus/ssl"))
datas.append((f"{ROOT}/mozilla-ca/*", "mozilla-ca"))
datas.append(version_data)

pathex = []


def add_binary(name, path_to_script, collect_args):
analysis = Analysis(
[path_to_script],
pathex=pathex,
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)

solve_name_collision_problem(analysis)

binary_pyz = PYZ(analysis.pure, analysis.zipped_data, cipher=block_cipher)

binary_exe = EXE(
binary_pyz,
analysis.scripts,
[],
exclude_binaries=True,
name=name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
)

collect_args.extend(
[
binary_exe,
analysis.binaries,
analysis.zipfiles,
analysis.datas,
]
)


COLLECT_ARGS = []

add_binary("cactus", f"{ROOT}/cactus/cmds/cactus.py", COLLECT_ARGS)
add_binary("daemon", f"{ROOT}/cactus/daemon/server.py", COLLECT_ARGS)

for server in SERVERS:
add_binary(f"start_{server}", f"{ROOT}/cactus/server/start_{server}.py", COLLECT_ARGS)

add_binary("start_crawler", f"{ROOT}/cactus/seeder/start_crawler.py", COLLECT_ARGS)
add_binary("start_seeder", f"{ROOT}/cactus/seeder/dns_server.py", COLLECT_ARGS)
add_binary("start_data_layer_http", f"{ROOT}/cactus/data_layer/data_layer_server.py", COLLECT_ARGS)

COLLECT_KWARGS = dict(
strip=False,
upx_exclude=[],
name="daemon",
)

coll = COLLECT(*COLLECT_ARGS, **COLLECT_KWARGS)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"colorama==0.4.6", # Colorizes terminal output
"colorlog==6.7.0", # Adds color to logs
"concurrent-log-handler==0.9.20", # Concurrently log and rotate logs
"cryptography==39.0.1", # Python cryptography library for TLS - keyring conflict
"cryptography==40.0.1", # Python cryptography library for TLS - keyring conflict
"filelock==3.9.0", # For reading and writing config multiprocess and multithread safely (non-reentrant locks)
"keyring==23.13.1", # Store keys in MacOS Keychain, Windows Credential Locker
"PyYAML==6.0", # Used for config file format
Expand Down