Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def build_executable(self, target, arcname, pkgexts, copyexts, script, extra_scripts):
# Build an executable for the target
appdir, resdir, plist = self.create_bundle(target, script)
self.appdir = appdir
self.resdir = resdir
self.plist = plist
for fn in extra_scripts:
if fn.endswith('.py'):
fn = fn[:-3]
elif fn.endswith('.pyw'):
fn = fn[:-4]
src_fn = script_executable(arch=self.arch, secondary=True)
tgt_fn = os.path.join(self.appdir, 'Contents', 'MacOS', os.path.basename(fn))
mergecopy(src_fn, tgt_fn)
make_exec(tgt_fn)
site_path = os.path.join(resdir, 'site.py')
byte_compile([
SourceModule('site', site_path),
],
target_dir=resdir,
optimize=self.optimize,
force=self.force,
verbose=self.verbose,
dry_run=self.dry_run)
if not self.dry_run:
os.unlink(site_path)
def create_appbundle(destdir, name, extension='.app', module=py2app.apptemplate,
platform='MacOS', copy=mergecopy, mergetree=mergetree,
condition=skipscm, plist={}, arch=None):
kw = module.plist_template.infoPlistDict(
plist.get('CFBundleExecutable', name), plist)
app = os.path.join(destdir, kw['CFBundleName'] + extension)
if os.path.exists(app):
# Remove any existing build artifacts to ensure that
# we're getting a clean build
shutil.rmtree(app)
contents = os.path.join(app, 'Contents')
resources = os.path.join(contents, 'Resources')
platdir = os.path.join(contents, platform)
dirs = [contents, resources, platdir]
plist = plistlib.Plist()
plist.update(kw)
plistPath = os.path.join(contents, 'Info.plist')
if os.path.exists(plistPath):
extra_scripts = list(self.extra_scripts)
if hasattr(target, 'extra_scripts'):
extra_scripts.update(extra_scripts)
dst = self.build_alias_executable(target, target.script, extra_scripts)
self.app_files.append(dst)
for fn in extra_scripts:
if fn.endswith('.py'):
fn = fn[:-3]
elif fn.endswith('.pyw'):
fn = fn[:-4]
src_fn = script_executable(arch=self.arch, secondary=True)
tgt_fn = os.path.join(target.appdir, 'Contents', 'MacOS', os.path.basename(fn))
mergecopy(src_fn, tgt_fn)
make_exec(tgt_fn)
def create_pluginbundle(destdir, name, extension='.plugin', module=py2app.bundletemplate,
platform='MacOS', copy=mergecopy, mergetree=mergetree,
condition=skipscm, plist={}, arch=None):
kw = module.plist_template.infoPlistDict(
plist.get('CFBundleExecutable', name), plist)
plugin = os.path.join(destdir, kw['CFBundleName'] + extension)
if os.path.exists(plugin):
# Remove any existing build artifacts to ensure
# we're getting a clean build
shutil.rmtree(plugin)
contents = os.path.join(plugin, 'Contents')
resources = os.path.join(contents, 'Resources')
platdir = os.path.join(contents, platform)
dirs = [contents, resources, platdir]
plist = plistlib.Plist()
plist.update(kw)
plistPath = os.path.join(contents, 'Info.plist')
if os.path.exists(plistPath):