jborean93 / pypsexec

Remote Windows execution like PsExec on Python
MIT License
119 stars 38 forks source link

Add PyInstaller hooks #45

Closed mssalvatore closed 3 years ago

mssalvatore commented 3 years ago

These hooks allow pypsexec to be properly packaged with PyInstaller. Specifically, they help Pyinstaller locate the paexec.exe binary.

You can read more about PyInstaller here, and more about PyInstaller hooks here.

Fixes #43

codecov[bot] commented 3 years ago

Codecov Report

Merging #45 (dd35f27) into master (51fbd8d) will decrease coverage by 0.99%. The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #45      +/-   ##
==========================================
- Coverage   98.26%   97.27%   -1.00%     
==========================================
  Files           7        9       +2     
  Lines        1094     1099       +5     
==========================================
- Hits         1075     1069       -6     
- Misses         19       30      +11     
Impacted Files Coverage Δ
pypsexec/__pyinstaller/__init__.py 0.00% <0.00%> (ø)
pypsexec/__pyinstaller/hook-pypsexec.py 0.00% <0.00%> (ø)
pypsexec/client.py 94.06% <0.00%> (-2.55%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 51fbd8d...dd35f27. Read the comment docs.

jborean93 commented 3 years ago

Thanks for the PR, I'll have to set aside some time in the coming week(s) to try and understand this setup a bit more. Is pyinstaller a way to essentially package Python and some libraries into a self contained executable or is there some other reason to use it?

mssalvatore commented 3 years ago

Is pyinstaller a way to essentially package Python and some libraries into a self contained executable?

Yep!

mssalvatore commented 3 years ago

@jborean93 Any update on this PR? Do you need any more information from me?

jborean93 commented 3 years ago

Sorry for the delay. I've had a very brief look at this and I think I'm still quite reluctant to add official support for this. I don't know much about this environment and I don't particular want to be on the hook for any future changes to the structure of this library that might affect pyinstaller.

One thing when reading online is I see there's something called a spec file to generate the executable https://pyinstaller.readthedocs.io/en/stable/spec-files.html#spec-file-operation. It seems to be just a Python script that is executed so I would assume you can do the following to manually include the paexec.exe file.

import os.path
import pypsexec

paexec_path = os.path.join(os.path.dirname(pypsexec.__file__), 'paexec.exe')

a = Analysis(...
    binaries=[paexec_path])
...

You can even adapt the method https://github.com/jborean93/pypsexec/issues/43#issuecomment-895970104 by calling it programmatically through a python script:

import os
import os.path

import PyInstaller.__main__
import pypsexec

pypsexec_path = os.path.dirname(pypsexec.__file__)
paexec_path = os.path.join(pypsexec_path, 'paexec.exe')

PyInstaller.__main__.run([
    '--onefile',
    f'--add-data={pypsexec_path}{os.pathsep}{paexec_path}',
    'my-script.py',
])

When testing this even creates a nice spec file that you can adapt for future use.

mssalvatore commented 3 years ago

Fair enough.

jborean93 commented 3 years ago

Closing as per the comment above.