From 74a5830dae3b4895bf45a4fedee86cb0c7c4da74 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 11 Nov 2016 16:15:24 +0100 Subject: [PATCH] setup fdist option for files distribution (unzipped files) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the equivalent of `python setup.py bdist` and unzipping the outputted file. If no --dest-path is specified it dumps the files in the same folder as the .zip. It is used for symlinking of the latest addon in production computers without having to deal with .zip files. Review, design, lessons, patient orientations by Sybren Stüvel --- setup.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/setup.py b/setup.py index 025ead7..6349e50 100755 --- a/setup.py +++ b/setup.py @@ -18,11 +18,13 @@ # ##### END GPL LICENSE BLOCK ##### import glob +import os import sys import shutil import subprocess import re import pathlib +import zipfile from distutils import log from distutils.core import Command @@ -168,6 +170,34 @@ class BlenderAddonBdist(bdist): 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.""" @@ -191,6 +221,7 @@ class AvoidEggInfo(install_egg_info): setup( cmdclass={'bdist': BlenderAddonBdist, + 'fdist': BlenderAddonFdist, 'install': BlenderAddonInstall, 'install_egg_info': AvoidEggInfo, 'wheels': BuildWheels},