Files
OpenBB/build/pyinstaller/terminal.spec
montezdesousa 825b8955df Set guest by default and put authentication behind environment variable (#4197)
* small bug

* small bug on routines list

* guest as default

* limit logout to users2

* simpler this way

* add logout

* move logout to account & add env var

* put authentication under env var

* fix tests

* remove login

* remove openbb vars on login

* ruff

* revert .toml

* Delete Icon

* Update .env

* fix sdk guest not loading keys

* ruff

* remove press enter & --login

* ruff

* move env load

* load env

* move dot env loading to terminal.py

* fix user sdk login mixing .env with user

* now it works

* fix reset

* fix tests

* ruff

* Login on the SDK using the OpenBB Personal Access Token (#4206)

* openbb key on keys menu

* adding sdk endpoints

* adding login via token to the sdk

* base url

* rename to personal access token

* added docstrings and examples

* openbb is special

* removing extra break line

* making keys working with the personal access token

* resolve conflicting tests

* Revert "resolve conflicting tests"

This reverts commit 2fca2c0ec3.

* using custom requests

* tests

* tests

* tests

* using process_session_response instead

* rewriting some tests

* Fix sdk guest not loading keys (#4207)

* fix sdk guest not loading keys

* ruff

* remove comment

* tests

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>

* test record mode vcr none

* remove yes from tests yml

* specify modules to reload

* try disable check api

* UPdate spec file

* Small stocks bug

* avoid reloading in test mode

* will this work?

* skip session tests

* try with env var as well

* mock sdk reload

* pylint

* bump poetry on python 3.8

* adapt to python 3.8

* adapt to python 3.8 remaining tests

* Tests : update cassettes

* Fix linting

* Makes login conditions simpler

* Tests : txt

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Chavithra <chavithra@gmail.com>
Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
2023-02-14 09:56:03 +00:00

191 lines
5.4 KiB
Python
Vendored

# -*- mode: python ; coding: utf-8 -*-
import os
import subprocess
import sys
from pathlib import Path
import scipy
from dotenv import set_key
from PyInstaller.building.api import COLLECT, EXE, PYZ
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.splash import Splash
from PyInstaller.compat import is_darwin, is_win
from openbb_terminal.loggers import get_commit_hash
NAME = "OpenBBTerminal"
build_type = (
os.getenv("OPENBB_BUILD_TYPE") if bool(os.getenv("OPENBB_BUILD_TYPE")) else "folder"
)
# Local python environment packages folder
venv_path = Path(sys.executable).parent.parent.resolve()
# Check if we are running in a conda environment
if is_darwin:
pathex = os.path.join(os.path.dirname(os.__file__), "site-packages")
else:
if "site-packages" in list(venv_path.iterdir()):
pathex = str(venv_path / "site-packages")
else:
pathex = str(venv_path / "lib" / "site-packages")
# Removing unused ARM64 binary
binary_to_remove = Path(os.path.join(pathex, "_scs_direct.cpython-39-darwin.so"))
print("Removing ARM64 Binary: _scs_direct.cpython-39-darwin.so")
binary_to_remove.unlink(missing_ok=True)
build_assets_folder = os.path.join(os.getcwd(), "build", "pyinstaller")
# Removing inspect hook
destination = Path(
os.path.join(pathex, "pyinstaller/hooks/rthooks", "pyi_rth_inspect.py")
)
print("Replacing Pyinstaller Hook: pyi_rth_inspect.py")
source = os.path.join(build_assets_folder, "hooks", "pyi_rth_inspect.py")
subprocess.run(["cp", source, str(destination)], check=True)
# Get latest commit
commit_hash = get_commit_hash()
build_assets_folder = os.path.join(os.getcwd(), "build", "pyinstaller")
default_env_file = os.path.join(build_assets_folder, ".env")
set_key(default_env_file, "OPENBB_LOGGING_COMMIT_HASH", str(commit_hash))
# Files that are explicitly pulled into the bundle
added_files = [
(os.path.join(os.getcwd(), "openbb_terminal"), "openbb_terminal"),
(os.path.join(pathex, "property_cached"), "property_cached"),
(os.path.join(pathex, "user_agent"), "user_agent"),
(os.path.join(pathex, "vaderSentiment"), "vaderSentiment"),
(os.path.join(pathex, "prophet"), "prophet"),
(os.path.join(pathex, "frozendict", "VERSION"), "frozendict"),
(
os.path.join(pathex, "linearmodels", "datasets"),
os.path.join("linearmodels", "datasets"),
),
(
os.path.join(pathex, "statsmodels", "datasets"),
os.path.join("statsmodels", "datasets"),
),
(
os.path.join(pathex, "debugpy", "_vendored"),
os.path.join("debugpy", "_vendored"),
),
(".env", "."),
(os.path.join(pathex, "blib2to3", "Grammar.txt"), "blib2to3"),
(os.path.join(pathex, "blib2to3", "PatternGrammar.txt"), "blib2to3"),
]
if is_win:
added_files.append(
(os.path.join(f"{os.path.dirname(scipy.__file__)}.libs"), "scipy.libs/"),
)
# Python libraries that are explicitly pulled into the bundle
hidden_imports = [
"sklearn.utils._cython_blas",
"sklearn.utils._typedefs",
"sklearn.utils._heap",
"sklearn.utils._sorting",
"sklearn.utils._vector_sentinel",
"sklearn.neighbors.quad_tree",
"sklearn.tree._utils",
"sklearn.neighbors._partition_nodes",
"sklearn.metrics._pairwise_distances_reduction._datasets_pair",
"sklearn.metrics._pairwise_distances_reduction._middle_term_computer",
"squarify",
"linearmodels",
"statsmodels",
"user_agent",
"vaderSentiment",
"frozendict",
"pyEX",
"feedparser",
"_sysconfigdata__darwin_darwin",
"prophet",
"debugpy",
"scipy.sparse.linalg._isolve._iterative",
]
analysis_kwargs = dict(
scripts=[os.path.join(os.getcwd(), "terminal.py")],
pathex=[pathex, "."],
binaries=[],
datas=added_files,
hiddenimports=hidden_imports,
hookspath=["build/pyinstaller/hooks"],
hooksconfig={},
runtime_hooks=["build/pyinstaller/hooks/hook-debugpy.py"],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=None,
noarchive=False,
)
a = Analysis(**analysis_kwargs)
pyz = PYZ(a.pure, a.zipped_data, cipher=analysis_kwargs["cipher"])
exe_args = [
pyz,
a.scripts,
[],
]
exe_kwargs = dict(
name=NAME,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
upx_exclude=[],
console=True,
disable_windowed_traceback=False,
target_arch="x86_64",
codesign_identity=None,
entitlements_file=None,
)
# Packaging settings
if build_type == "onefile":
exe_args += [a.binaries, a.zipfiles, a.datas]
exe_kwargs["runtime_tmpdir"] = None
elif build_type == "folder":
exe_kwargs["exclude_binaries"] = True
collect_args = [
a.binaries,
a.zipfiles,
a.datas,
]
collect_kwargs = dict(
strip=False,
upx=True,
upx_exclude=[],
name=NAME,
)
# Platform specific settings
if is_win:
splash = Splash(
os.path.join(os.getcwd(), "images", "openbb_splashscreen.png"),
binaries=a.binaries,
datas=a.datas,
text_pos=(200, 400),
text_size=12,
text_color="white",
)
exe_args += [splash, splash.binaries]
exe_kwargs["icon"] = (os.path.join(os.getcwd(), "images", "openbb_icon.ico"),)
if is_darwin:
exe_kwargs["icon"] = (os.path.join(os.getcwd(), "images", "openbb.icns"),)
exe = EXE(*exe_args, **exe_kwargs)
if build_type == "folder":
coll = COLLECT(*([exe] + collect_args), **collect_kwargs)