Skip to content

Commit

Permalink
Excluding system libraries from PyInstaller (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeMouse92 committed Dec 30, 2019
1 parent a23aeae commit 6bc9790
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 16 deletions.
15 changes: 12 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
To build Timecard, we recommend using Python 3.7 and creating a virtual
environment.

Run the following in a virtual environment to build Timecard:
If you're on a Linux system, you can use the provided Makefile:

```
make build
```

Alternatively, run the following in a virtual environment to build Timecard:

```
pip install pyinstaller
pip install -r requirements.txt
pyinstaller --clean --windowed timecard_app.spec
```

The distribution folder is `dist/timecard_app`. To start the application,
run `dist/timecard_app/timecard_app`.
The distribution folder is `dist/timecard_app`, and the standalone binary is
at `dist/timecard_app/timecard_app`.

## Debian Package

The Debian packaging is configured to build an executable using
a virtual environment and PyInstaller. Standard Debian packaging commands
apply.

WARNING: This should be considered experimental right now. I have yet to add
the rest of the dependencies stripped out of the PyInstaller.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/make -f

none:
@echo "build Build as single file."
@echo "build_folder Build as single folder."
@echo "clean Clean build artifacts."

clean:
rm -rf dist/
rm -rf build/
Expand Down
54 changes: 47 additions & 7 deletions timecard_app.spec
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
# -*- mode: python ; coding: utf-8 -*-

def filter_binaries(all_binaries):
exclude_binaries = set()
for binary, path, type in all_binaries:
if type != "BINARY":
continue
if "site-packages" in path:
continue
if "libpython3" in binary:
continue

exclude_binaries.add((binary, path, type))

binaries = [x for x in all_binaries if x not in exclude_binaries]

with open('dist/binary_list.txt', 'w') as file:
for name, path, type in binaries:
print(f".. Including {type} {path}")
file.write(f"Including {type} {path}.\n")

file.write("\n")

for name, path, type in exclude_binaries:
print(f">> EXCLUDING {type} {path}")
file.write(f"EXCLUDING {type} {path}.\n")

file.write("\n")

info = "On Debian, use `dpkg -S <pkg_name> to find dependency packages."

print(info)
file.write(f"{info}\n")

return binaries

block_cipher = None

added_files = [
('timecard/resources', 'timecard/resources')
]

a = Analysis(['timecard_app.py'],
pathex=['/home/jason/Code/Repositories/timecard'],
pathex=['./timecard'],
binaries=[],
datas=added_files,
hiddenimports=['PySide2'],
Expand All @@ -17,20 +51,26 @@ a = Analysis(['timecard_app.py'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
noarchive=False
)

pyz = PYZ(a.pure,
a.zipped_data,
cipher=block_cipher
)

exe = EXE(pyz,
a.scripts,
a.binaries,
filter_binaries(a.binaries),
a.zipfiles,
a.datas,
[],
name='timecard',
name='timecard_app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
console=False
)
53 changes: 47 additions & 6 deletions timecard_app_folder.spec
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
# -*- mode: python ; coding: utf-8 -*-

def filter_binaries(all_binaries):
exclude_binaries = set()
for binary, path, type in all_binaries:
if type != "BINARY":
continue
if "site-packages" in path:
continue
if "libpython3" in binary:
continue

exclude_binaries.add((binary, path, type))

binaries = [x for x in all_binaries if x not in exclude_binaries]

with open('dist/binary_list.txt', 'w') as file:
for name, path, type in binaries:
print(f".. Including {type} {path}")
file.write(f"Including {type} {path}.\n")

file.write("\n")

for name, path, type in exclude_binaries:
print(f">> EXCLUDING {type} {path}")
file.write(f"EXCLUDING {type} {path}.\n")

file.write("\n")

info = "On Debian, use `dpkg -S <pkg_name> to find dependency packages."

print(info)
file.write(f"{info}\n")

return binaries

block_cipher = None

added_files = [
('timecard/resources', 'timecard/resources')
]

a = Analysis(['timecard_app.py'],
pathex=['/home/jason/Code/Repositories/timecard'],
pathex=['./timecard'],
binaries=[],
datas=added_files,
hiddenimports=['PySide2'],
Expand All @@ -17,9 +51,14 @@ a = Analysis(['timecard_app.py'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
noarchive=False
)

pyz = PYZ(a.pure,
a.zipped_data,
cipher=block_cipher
)

exe = EXE(pyz,
a.scripts,
[],
Expand All @@ -29,9 +68,11 @@ exe = EXE(pyz,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False )
console=False
)

coll = COLLECT(exe,
a.binaries,
filter_binaries(a.binaries),
a.zipfiles,
a.datas,
strip=False,
Expand Down

0 comments on commit 6bc9790

Please sign in to comment.