Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP PyInstaller progress #1628

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

uellue
Copy link
Member

@uellue uellue commented Apr 19, 2024

Current status: libertem-server starts up, but doesn't find the static files where they are expected

Fixes #39

Contributor Checklist:

Reviewer Checklist:

  • /azp run libertem.libertem-data passed
  • No import of GPL code from MIT code

Current status: libertem-server starts up, but doesn't find the static files
where they are expected
@uellue
Copy link
Member Author

uellue commented Apr 19, 2024

The opentelemetry hook won't be required in the future and should be deleted, probably: fixed properly in pyinstaller/pyinstaller-hooks-contrib#725

Thx @rokm for the help and the quick fix!

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.76%. Comparing base (92f14c3) to head (e20a249).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1628      +/-   ##
==========================================
- Coverage   69.85%   65.76%   -4.09%     
==========================================
  Files         325      325              
  Lines       27251    27251              
  Branches     3136     3136              
==========================================
- Hits        19036    17922    -1114     
- Misses       7646     8823    +1177     
+ Partials      569      506      -63     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

dask_datas = []

dask_files = [
('Lib/site-packages/dask/dask.yaml', 'dask'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unnecessary, as existing hook for dask should collect that file.


dask_files = [
('Lib/site-packages/dask/dask.yaml', 'dask'),
('Lib/site-packages/distributed/distributed.yaml', 'distributed')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be handled in more portable way by creating a hook for distributed that calls collect_data_files('distributed').

@rokm
Copy link

rokm commented Apr 19, 2024

And to avoid a future issue report - if your code uses a package that in turn uses multiprocessing (I think dask.distributed / distributed fits the bill), make sure to call multiprocessing.freeze_support() at the start of your program. Otherwise, use of multiprocessing will likely result in endless program spawn loop. See https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#multi-processing

if os.path.exists(path):
dask_datas.append((path, target))

libertem_datas = [('../../client', 'libertem')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current status: libertem-server starts up, but doesn't find the static files where they are expected

Do they end up in the site-packages in the installation? Is the relative path correct (whats the working directory when this code runs?), or does it maybe need a os.path.join(os.path.dirname(__file__), '..', '..', 'client') or similar?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If relative paths are given like that, PyInstaller assumes they are relative to the spec file (in order to factor out current working directory during the build).

I think part of the problem here is that the contents of that client directory are collected into libertem directory, as instructed. The target directory should be libertem\web\client, as it is when the package is installed.

But if the build process here assumes that libertem is installed (in non-editable mode) in the python environment prior to the build (which I suspect is the case, otherwise PyInstaller will have no way of finding libertem modules...), then the data files could be simply collected by hook-libertem.py:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('libertem')

The second part of the problem seems to be that in frozen application, tornado.template.Loader receives relative root_directory (libertem\web), which it incorrectly resolves to absolute path using current working directory. When running unfrozen, that root_directory is already a correct absolute path. Will need to dig around a bit more to see what exactly is going wrong...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of the problem seems to be that in frozen application, tornado.template.Loader receives relative root_directory (libertem\web), which it incorrectly resolves to absolute path using current working directory. When running unfrozen, that root_directory is already a correct absolute path. Will need to dig around a bit more to see what exactly is going wrong...

Ah yes, tornado is trying to infer the path from co_filename of code objects, which are anonymized relative paths in PyInstaller builds.

I suppose the easiest way for you to work around this insanity is to set template_path in the application settings, similarly to how it is done for static_path. In this case, the value should be os.path.dirname(__file__).

@uellue
Copy link
Member Author

uellue commented Apr 19, 2024

@rokm thank you for the pointers, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package/Installer for Windows
3 participants