Skip to content

Commit

Permalink
add hidden imports to pyinstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Apr 14, 2024
1 parent c3b2d56 commit c2a2593
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Build executable with pyinstaller
run: python -m PyInstaller src/joplin_custom_importer.py --onefile --collect-data pypandoc
run: python -m PyInstaller joplin_custom_importer.spec
- uses: actions/upload-artifact@v4
with:
name: joplin-custom-importer-${{ matrix.os }}
path: ./dist/joplin_custom_importer*
- name: Smoke test
run: ./dist/joplin_custom_importer test_inputs --dry-run
run: |
./dist/joplin_custom_importer test_inputs --dry-run
./dist/joplin_custom_importer test_inputs/obsidian_vault --app obsidian --dry-run
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__pycache__
*.AppImage
joplin_custom_importer.log
joplin_custom_importer.spec
.obsidian
build
dist
Expand Down
58 changes: 58 additions & 0 deletions joplin_custom_importer.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files

# pypandoc: https://github.com/orgs/pyinstaller/discussions/8387
datas = []
datas += collect_data_files('pypandoc')


# Generate list of hidden imports
# hidden import for dynamically loaded modules "apps.*":
# - https://stackoverflow.com/a/77395744/7410886
# - https://stackoverflow.com/a/35805418/7410886
# - https://pyinstaller.org/en/stable/when-things-go-wrong.html#listing-hidden-imports
from pathlib import Path
def list_python_files(folder):
file_list = []
for file_ in folder.iterdir():
if file_.suffix == ".py" and file_.name != "__init__.py":
file_list.append(f"{folder.stem}.{file_.stem}")
return file_list

hiddenimports = list_python_files(Path("src/apps"))


a = Analysis(
['src/joplin_custom_importer.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='joplin_custom_importer',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
2 changes: 2 additions & 0 deletions src/joplin_custom_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def convert_all_inputs(inputs: list[Path], app: str):
# Try to use an app specific converter. If there is none,
# fall back to the default converter.
try:
LOGGER.debug(f"Try converting with converter {app}")
module = importlib.import_module(f"apps.{app}")
converter_ = module.Converter(app)
except ModuleNotFoundError as exc:
LOGGER.debug(f"Fallback to default converter: {exc}")
if str(exc) == f"No module named 'apps.{app}'":
converter_ = converter.DefaultConverter(app)
else:
Expand Down

0 comments on commit c2a2593

Please sign in to comment.