├── pyinstaller_setuptools ├── __init__.py └── setup.py ├── .gitignore ├── README.md ├── COPYING └── setup.py /pyinstaller_setuptools/__init__.py: -------------------------------------------------------------------------------- 1 | from .setup import setup 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | *env 4 | *.egg* 5 | build 6 | dist 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyInstaller Setup 2 | 3 | Use pyinstaller with setuptools! 4 | 5 | ## setup.py 6 | 7 | ```python 8 | from pyinstaller_setuptools import setup 9 | 10 | setup( 11 | ... 12 | scripts=['path/to/a/script.py'], 13 | entry_points={ 14 | 'console_scripts': ['entry=module.func'] 15 | }, 16 | ... 17 | ) 18 | ``` 19 | 20 | ## Usage 21 | 22 | ``` 23 | > python ./setup.py build 24 | > python ./setup.py install 25 | > python ./setup.py pyinstaller [-- ] 26 | ``` 27 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2019 Neil F Jones 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | from os import path 3 | from io import open 4 | 5 | here = path.abspath(path.dirname(__file__)) 6 | 7 | with open(path.join(here, "README.md"), encoding="utf-8") as f: 8 | long_description = f.read() 9 | 10 | 11 | setup( 12 | name="pyinstaller_setuptools", 13 | version="2019.3", 14 | description="Use pyinstaller in your setup.py", 15 | long_description=long_description, 16 | long_description_content_type="text/markdown", 17 | url="https://github.com/NFJones/pyinstaller-setup", 18 | author="Neil F Jones", 19 | classifiers=[ 20 | "Development Status :: 4 - Beta", 21 | "Intended Audience :: Developers", 22 | "Topic :: Software Development :: Build Tools", 23 | "License :: OSI Approved :: MIT License", 24 | "Programming Language :: Python :: 2", 25 | "Programming Language :: Python :: 2.7", 26 | "Programming Language :: Python :: 3", 27 | "Programming Language :: Python :: 3.4", 28 | "Programming Language :: Python :: 3.5", 29 | "Programming Language :: Python :: 3.6", 30 | "Programming Language :: Python :: 3.7", 31 | ], 32 | keywords="sample setuptools development pyinstaller", 33 | packages=["pyinstaller_setuptools"], 34 | python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", 35 | install_requires=["pyinstaller"], 36 | ) 37 | -------------------------------------------------------------------------------- /pyinstaller_setuptools/setup.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import inspect 4 | import re 5 | from setuptools import setup as setuptools_setup 6 | 7 | ENTRY_POINT_TEMPLATE = """ 8 | #!/usr/bin/env python2.7 9 | # -*- coding: utf-8 -*- 10 | import re 11 | import sys 12 | 13 | from {} import {} 14 | 15 | if __name__ == '__main__': 16 | sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 17 | sys.exit({}()) 18 | """ 19 | 20 | 21 | class setup(object): 22 | """ 23 | This is intended to run pyinstaller in order to make executables out of 24 | all of the scripts and console script entry points listed in setuptools.setup 25 | 26 | Usage: 27 | ``` 28 | python ./setup.py build 29 | python ./setup.py install 30 | python ./setup.py pyinstaller [-- pyinstaller-opts ...] 31 | ``` 32 | """ 33 | 34 | def __init__(self, scripts=None, entry_points=None, **kwargs): 35 | self.scripts = scripts 36 | self.entry_points = entry_points 37 | 38 | if "pyinstaller" in sys.argv: 39 | if "--" in sys.argv and sys.argv.index("--") < len(sys.argv) - 1: 40 | self.flags = " ".join(sys.argv[sys.argv.index("--") + 1 :]) 41 | else: 42 | self.flags = "" 43 | 44 | if not os.path.exists("./dist"): 45 | os.mkdir("dist") 46 | 47 | if self.scripts: 48 | self.install_scripts() 49 | if self.entry_points: 50 | self.install_entry_points() 51 | else: 52 | setuptools_setup(scripts=scripts, entry_points=entry_points, **kwargs) 53 | 54 | def pyinstaller(self, name, target): 55 | if os.system("pyinstaller --name {} {} {}".format(name, self.flags, target)): 56 | raise Exception("PyInstaller failed!") 57 | 58 | def install_scripts(self): 59 | for script in self.scripts: 60 | self.pyinstaller(os.path.basename(script).replace(".py", ""), script) 61 | 62 | def install_entry_points(self): 63 | if "console_scripts" in self.entry_points.keys(): 64 | for entry_point in self.entry_points["console_scripts"]: 65 | name, entry = [part.strip() for part in entry_point.split("=")] 66 | module, func = [part.strip() for part in entry.split(":")] 67 | 68 | script = inspect.cleandoc( 69 | ENTRY_POINT_TEMPLATE.format(module, func, func) 70 | ) 71 | 72 | input_file = "dist/{}_entry.py".format(name) 73 | with open(input_file, "w") as outfile: 74 | outfile.write(script) 75 | 76 | self.pyinstaller(name, input_file) 77 | --------------------------------------------------------------------------------