setup fdist option for files distribution (unzipped files)
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
This commit is contained in:
parent
da4d4df5fb
commit
74a5830dae
31
setup.py
31
setup.py
@ -18,11 +18,13 @@
|
|||||||
# ##### END GPL LICENSE BLOCK #####
|
# ##### END GPL LICENSE BLOCK #####
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from distutils import log
|
from distutils import log
|
||||||
from distutils.core import Command
|
from distutils.core import Command
|
||||||
@ -168,6 +170,34 @@ class BlenderAddonBdist(bdist):
|
|||||||
super().run()
|
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
|
# noinspection PyAttributeOutsideInit
|
||||||
class BlenderAddonInstall(install):
|
class BlenderAddonInstall(install):
|
||||||
"""Ensures the module is placed at the root of the zip file."""
|
"""Ensures the module is placed at the root of the zip file."""
|
||||||
@ -191,6 +221,7 @@ class AvoidEggInfo(install_egg_info):
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
cmdclass={'bdist': BlenderAddonBdist,
|
cmdclass={'bdist': BlenderAddonBdist,
|
||||||
|
'fdist': BlenderAddonFdist,
|
||||||
'install': BlenderAddonInstall,
|
'install': BlenderAddonInstall,
|
||||||
'install_egg_info': AvoidEggInfo,
|
'install_egg_info': AvoidEggInfo,
|
||||||
'wheels': BuildWheels},
|
'wheels': BuildWheels},
|
||||||
|
Reference in New Issue
Block a user