From 0e0673bc16cfee94aaf7e616d256a6d2d991d62f Mon Sep 17 00:00:00 2001 From: Ellwood Zwovic Date: Fri, 14 Jul 2017 17:16:00 -0700 Subject: [PATCH] Add setup.py --- setup.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 setup.py diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..f74f934 --- /dev/null +++ b/setup.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# setup.py adapted from blender_cloud addon + +import glob +import sys +import zipfile + +from distutils import log +from distutils.core import Command +from distutils.command.bdist import bdist +from distutils.command.install import install +from distutils.command.install_egg_info import install_egg_info +from setuptools import setup, find_packages + +# sys.dont_write_bytecode = True + +# noinspection PyAttributeOutsideInit +class BlenderAddonBdist(bdist): + """Ensures that 'python setup.py bdist' creates a zip file.""" + + def initialize_options(self): + super().initialize_options() + self.formats = ['zip'] + self.plat_name = 'addon' # use this instead of 'linux-x86_64' or similar. + + def run(self): + self.run_command('wheels') + super().run() + + +# noinspection PyAttributeOutsideInit +class BlenderAddonFdist(BlenderAddonBdist): + """Ensures that 'python setup.py fdist' creates a plain folder structure.""" + + user_options = [ + ('dest-path=', None, 'addon installation path'), + ] + + def initialize_options(self): + super().initialize_options() + self.dest_path = None # path that will contain the addon + + def run(self): + super().run() + + # dist_files is a list of tuples ('bdist', 'any', 'filepath') + filepath = self.distribution.dist_files[0][2] + + # if dest_path is not specified use the filename as the dest_path (minus the .zip) + assert filepath.endswith('.zip') + target_folder = self.dest_path or filepath[:-4] + + print('Unzipping the package on {}.'.format(target_folder)) + + with zipfile.ZipFile(filepath, 'r') as zip_ref: + zip_ref.extractall(target_folder) + + +# noinspection PyAttributeOutsideInit +class BlenderAddonInstall(install): + """Ensures the module is placed at the root of the zip file.""" + + def initialize_options(self): + super().initialize_options() + self.prefix = '' + self.install_lib = '' + + +class AvoidEggInfo(install_egg_info): + """Makes sure the egg-info directory is NOT created. + + If we skip this, the user's addon directory will be polluted by egg-info + directories, which Blender doesn't use anyway. + """ + + def run(self): + pass + + +setup( + cmdclass={'bdist': BlenderAddonBdist, + 'fdist': BlenderAddonFdist, + 'install': BlenderAddonInstall, + 'install_egg_info': AvoidEggInfo}, + name='bpkg', + description='Integrated package manager for Blender', + version='0.0.1', + author='Ellwood Zwovic', + author_email='gandalf3@blendermonkey.com', + packages=['bpkg'], + url='https://developer.blender.org/diffusion/BPMA/', + platforms='', + zip_safe=False, +) +