defrun(self):# Make sure we have built everything we need firstself.build()# Install everything: simply dump the entire contents of the build# directory to the installation directory (that's the beauty of# having a build directory!)outfiles=self.install()# (Optionally) compile .py to .pycifoutfilesisnotNoneandself.distribution.has_pure_modules():self.byte_compile(outfiles)
importosfromdistutils.coreimportsetupfromdistutils.command.install_libimportinstall_libfromdistutilsimportlogfromdistutils.dep_utilimportnewerfrompy_compileimportcompileclassInstallLib(install_lib):definstall(self):forroot,dirs,filesinos.walk(self.build_dir):current=root.replace(self.build_dir,self.install_dir)foriindirs:self.mkpath(os.path.join(current,i))foriinfiles:file=os.path.join(root,i)cfile=os.path.join(current,i)+"c"cfile_base=os.path.basename(cfile)ifself.forceornewer(file,cfile):log.info("byte-compiling %s to %s",file,cfile_base)compile(file,cfile)else:log.debug("skipping byte-compilation of %s",file)setup(cmdclass={"install_lib":InstallLib},name="HelloWorld",version="1.0")