Skip to content

Commit

Permalink
Move BEE2 files to bin/ subfolder when frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Oct 22, 2023
1 parent 33f8597 commit e0068b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
37 changes: 27 additions & 10 deletions src/BEE2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,34 @@ data_files = [
('../images/icons/*.png', 'images/icons/'),
('../images/splash_screen/*.jpg', 'images/splash_screen/'),
('../sounds/*.ogg', 'sounds'),
('../INSTALL_GUIDE.txt', '.'),
]

HA_VERSION = utils.get_git_version(hammeraddons)


def copy_datas(appfolder: Path, compiler_loc: str) -> None:
"""Copy `datas_files` files to the root of the app folder."""
for gl_src, dest in data_files:
for filename in Path().glob(gl_src):
name = filename.name
if name == 'INSTALL_GUIDE.txt':
# Special case, use a different name.
name = 'README.txt'

p_dest = Path(appfolder, dest, name)

print(filename, '->', p_dest)
p_dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(filename, p_dest)

(appfolder / 'packages').mkdir(exist_ok=True)

compiler_dest = Path(appfolder, 'bin', 'compiler')
print(compiler_loc, '->', compiler_dest)
shutil.copytree(compiler_loc, compiler_dest)


def do_localisation() -> None:
"""Build localisation."""

Expand Down Expand Up @@ -260,7 +283,6 @@ if utils.WIN:
version_val = f'''\
BEE_VERSION={utils.get_git_version(SPECPATH)!r}
HA_VERSION={HA_VERSION!r}
HAS_BIN_DIR=False
'''
print(version_val)
version_filename = os.path.join(workpath, '_compiled_version.py')
Expand All @@ -275,7 +297,7 @@ if version_val:

# Include the compiler, picking the right architecture.
bitness = 64 if sys.maxsize > (2**33) else 32
data_files.append((f'../dist/{bitness}bit/compiler/', 'compiler'))
COMPILER_LOC = f'../dist/{bitness}bit/compiler/'

# Finally, run the PyInstaller analysis process.

Expand All @@ -297,13 +319,6 @@ bee2_a = Analysis(
noarchive=False
)

# Need to add this manually, so it can have a different name.
bee2_a.datas.append((
'README.txt',
os.path.join(os.getcwd(), '../INSTALL_GUIDE.txt'),
'DATA',
))

pyz = PYZ(
bee2_a.pure,
bee2_a.zipped_data,
Expand All @@ -320,7 +335,7 @@ exe = EXE(
strip=False,
upx=False,
console=False,
contents_directory='.', # TODO
contents_directory='bin',
windowed=True,
icon='../BEE2.ico'
)
Expand All @@ -334,3 +349,5 @@ coll = COLLECT(
upx=True,
name='BEE2',
)

copy_datas(Path(coll.name), COMPILER_LOC)
1 change: 0 additions & 1 deletion src/compiler.spec
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ print('DATA:', data_files)
version_val = f'''\
BEE_VERSION={utils.get_git_version(SPECPATH)!r}
HA_VERSION={HA_VERSION!r}
HAS_BIN_DIR=True
'''
print(version_val)
version_filename = os.path.join(workpath, '_compiled_version.py')
Expand Down
6 changes: 2 additions & 4 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def get_git_version(inst_path: Path | str) -> str:
from _compiled_version import ( # type: ignore
BEE_VERSION as BEE_VERSION,
HA_VERSION as HA_VERSION,
HAS_BIN_DIR as _HAS_BIN_DIR,
)
except ImportError:
# We're running from src/, so data is in the folder above that.
Expand All @@ -133,11 +132,10 @@ def get_git_version(inst_path: Path | str) -> str:
FROZEN = True
# This special attribute is set by PyInstaller to our folder.
_BINS_ROOT = Path(sys._MEIPASS) # type: ignore[attr-defined] # noqa
_INSTALL_ROOT = _BINS_ROOT
# We are in a bin/ subfolder.
_INSTALL_ROOT = _BINS_ROOT.parent
# Check if this was produced by above
DEV_MODE = '#' in BEE_VERSION
if _HAS_BIN_DIR: # On PyInstaller 6.0+, we are in a bee2_bin/ subfolder.
_INSTALL_ROOT = _INSTALL_ROOT.parent

# Regular dev mode is enable-able by users, this is only for people editing code.
CODE_DEV_MODE = DEV_MODE
Expand Down

0 comments on commit e0068b3

Please sign in to comment.