Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying License dependencies for Pyinstaller

This is related to a previous question but is more specifically about implementation.

To recap the previous question, I have a Pyinstaller app with 3rd party dependencies. As @AKX answered, the license text from those dependencies should be included in the Pyinstaller distribution.

Pyinstaller makes no attempt to handle this.

Therefore I am looking for a way to automate this process.

My project uses a virtual env, and the dependencies are located at:

\venv\Lib\site-packages

One option would be to recursivley search through this folder, and find any files that match a specific pattern (e.g LICENSE.txt). However, some of the packages do not ship with a license file, and instead just name the license in their metadata. For example, I am using openpyxl

there is a folder

\venv\Lib\site-packages\openpyxl-3.0.0-py3.7.egg-info

which contains a PKG-INFO file. This lists the license (MIT/Expat) but does specifically contain the license text. In this case would it be acceptable to include a copy of the PKG-INFO file, or some copy of the standard MIT license text?

Has anyone faced this issue and implemented a solution in an elegant way? @AKX (in the previous question linked to a tool which outputs the license information as text/json etc.. but doesn't actually attempt to move any files.

like image 805
wstk Avatar asked Dec 15 '25 16:12

wstk


1 Answers

If anyone has a similar question, this is the solution I implemented, which seems to work pretty well for me:

At the top of my .spec file I added this

matches = ["LICENSE.txt","METADATA","PKG-INFO"]
lics = []
print("Find 3rd party dependency license files")
for root, dir, files in os.walk("venv\Lib\site-packages"):
    for file in files:
            if file in matches:
               src = f"{root}/{file}"
               dest = f"licenses/{os.path.basename(root)}"
               lics.append((src,dest))
               print(f"\tLicense file: {root}/{file}")
print(f"{len(lics)} dependency licenses found. Copying to /license folder in distribution")

which builds a list of tuples containing the source of the license or metadata, and the destination to copy it to in the distribution.

To do the actual copying, I made use of the datas keyword in the Analysis object, and simply expanded the list using *lics.

This could be adapted to include more matches or be smarter and parse the files, or something like that. It is also probably a bit wasteful and copies some files multiple times, but this seems like a minimal overhead for a tiny text file.

If anyone sees this and has suggestions or comments then I'd be happy to be further informed on this subject!

like image 117
wstk Avatar answered Dec 17 '25 11:12

wstk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!