Skip to content

Commit

Permalink
License file (hopefully) properly copied into the binary
Browse files Browse the repository at this point in the history
  • Loading branch information
kkalinowski-reef committed Dec 15, 2023
1 parent f103c3f commit 73e227b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ venv
doc/source/main_help.rst
Dockerfile
b2/licenses_output.txt
b2.spec
*.spec
8 changes: 5 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def bundle(session: nox.Session):
'VERSION': version,
'NAME': binary_name,
})
pathlib.Path('b2.spec').write_text(spec)
pathlib.Path(f'{binary_name}.spec').write_text(spec)

session.run('pyinstaller', *session.posargs, 'b2.spec', **run_kwargs)
session.run('pyinstaller', *session.posargs, f'{binary_name}.spec', **run_kwargs)

if SYSTEM == 'linux' and not NO_STATICX:
session.run(
Expand All @@ -343,7 +343,9 @@ def bundle(session: nox.Session):

# Pick only the shortest named executable.
# All the longer ones should be for different versions, the shortest one will be the latest stable.
executable = min([str(path) for path in pathlib.Path('dist').glob('*')], key=lambda path: len(path))
executable = min(
[str(path) for path in pathlib.Path('dist').glob('*')], key=lambda path: len(path)
)
print(f'sut_path={executable}')


Expand Down
18 changes: 17 additions & 1 deletion pyinstaller-hooks/hook-b2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,21 @@
license_file = Path('b2/licenses_output.txt')
assert license_file.exists()
datas = [
(str(license_file), '.'),
# When '.' was provided here, the license file was copied to the root of the executable.
# Before ApiVer, it pasted the file to the `b2/` directory.
# I have no idea why it worked before or how it works now.
# If you mean to debug it in the future, know that `pyinstaller` provides a special
# attribute in the `sys` module whenever it runs.
#
# Example:
# import sys
# if hasattr(sys, '_MEIPASS'):
# self._print(f'{NAME}')
# self._print(f'{sys._MEIPASS}')
# elems = [elem for elem in pathlib.Path(sys._MEIPASS).glob('**/*')]
# self._print(f'{elems}')
#
# If used at the very start of the `_run` of `Licenses` command, it will print
# all the files that were unpacked from the executable.
(str(license_file), 'b2/'),
]

0 comments on commit 73e227b

Please sign in to comment.