Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_console_entry_point(bin_dir, name, value, env_exe, creator):
result = []
if sys.platform == "win32":
# windows doesn't support simple script files, so fallback to more complicated exe generator
from distlib.scripts import ScriptMaker
maker = ScriptMaker(None, str(bin_dir))
maker.clobber = True # overwrite
maker.variants = {"", "X", "X.Y"} # create all variants
maker.set_mode = True # ensure they are executable
maker.executable = str(env_exe)
specification = "{} = {}".format(name, value)
new_files = maker.make(specification)
result.extend(new_files)
else:
module, func = value.split(":")
content = (
dedent(
"""
#!{0}
# -*- coding: utf-8 -*-
import re
import sys
python = f'python{pyver[0]}.{pyver[1]}'
if args.platform == 'windows':
sp = venv / 'Lib' / 'site-packages'
headers = venv / 'Include'
scripts = venv / 'Scripts'
data = venv
elif args.platform == 'linux':
sp = venv / 'lib' / python / 'site-packages'
headers = venv / 'include' / 'site' / python
scripts = venv / 'bin'
data = venv
else:
die(f'unsupported platform: {args.platform}')
maker = distlib.scripts.ScriptMaker(None, None)
for filename in os.listdir(td):
if not filename.endswith('.whl'):
continue
wheel = distlib.wheel.Wheel(os.path.join(td, filename))
paths = {
'prefix': venv,
'purelib': sp,
'platlib': sp,
'headers': headers / wheel.name,
'scripts': scripts,
'data': data
}
def pack(ctx, remove_lib=True):
"""Build a isolated runnable package.
"""
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
with ROOT.joinpath('Pipfile.lock').open() as f:
lockfile = plette.Lockfile.load(f)
libdir = OUTPUT_DIR.joinpath('lib')
paths = {'purelib': libdir, 'platlib': libdir}
sources = lockfile.meta.sources._data
maker = distlib.scripts.ScriptMaker(None, None)
# Install packages from Pipfile.lock.
for name, package in lockfile.default._data.items():
if name in DONT_PACKAGE:
continue
print(f'[pack] Installing {name}')
package.pop('editable', None) # Don't install things as editable.
package.pop('markers', None) # Always install everything.
r = requirementslib.Requirement.from_pipfile(name, package)
wheel = passa.internals._pip.build_wheel(
r.as_ireq(), sources, r.hashes or None,
)
wheel.install(paths, maker, lib_only=True)
for pattern in IGNORE_LIB_PATTERNS:
for path in libdir.rglob(pattern):
def _make_python_script(script_name, code, directory):
maker = ScriptMaker(None, directory)
maker.clobber = True
maker.variants = set(('',))
maker.set_mode = True
maker.script_template = code
return maker.make(script_name + '=isthisreallynecessary')
code (str): The python code to run.
# Returns
A list of filenames created. Depending on the platform, more than one file
might be created to support multiple use cases (eg. and `.exe` but also a
bash-script on Windows).
"""
if os.name == 'nt' and (not script_name.endswith('.py') \
or not script_name.endswith('.pyw')):
# ScriptMaker._write_script() will split the extension from the script
# name, thus if there is an extension, we should add another suffix so
# the extension doesn't get lost.
script_name += '.py'
maker = _ScriptMaker(None, self.directory)
maker.clobber = True
maker.variants = set(('',))
maker.set_mode = True
maker.script_template = self._init_code() + code
return maker.make(script_name + '=isthisreallynecessary')
def install(self):
self.wheel.install(self.paths, distlib.scripts.ScriptMaker(None, None))