def write_obj_lists(python_base, install_prefix): """Generate config file of keyword, check, and other object lists.""" path = os.path.join(python_base, pkgdist.MODULE_NAME, "_const.py") os.makedirs(os.path.dirname(path), exist_ok=True) log.info(f'writing config to {path!r}') # hack to drop quotes on modules in generated files class _kls(object): def __init__(self, module): self.module = module def __repr__(self): return self.module with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcheck import const modules = defaultdict(set) objs = defaultdict(list) for obj in ('KEYWORDS', 'CHECKS', 'REPORTERS'): for name, cls in getattr(const, obj).items(): parent, module = cls.__module__.rsplit('.', 1) modules[parent].add(module) objs[obj].append((name, _kls(f'{module}.{name}'))) keywords = tuple(objs['KEYWORDS']) checks = tuple(objs['CHECKS']) reporters = tuple(objs['REPORTERS']) with open(path, 'w') as f: os.chmod(path, 0o644) for k, v in sorted(modules.items()): f.write(f"from {k} import {', '.join(sorted(v))}\n") f.write( dedent(f"""\ KEYWORDS = {keywords} CHECKS = {checks} REPORTERS = {reporters} """)) # write install path constants to config if install_prefix != os.path.abspath(sys.prefix): # write more dynamic _const file for wheel installs f.write( dedent("""\ import os.path as osp import sys INSTALL_PREFIX = osp.abspath(sys.prefix) DATA_PATH = osp.join(INSTALL_PREFIX, {!r}) """.format(DATA_INSTALL_OFFSET))) else: f.write("INSTALL_PREFIX=%r\n" % install_prefix) f.write("DATA_PATH=%r\n" % os.path.join(install_prefix, DATA_INSTALL_OFFSET)) # only optimize during install, skip during wheel builds if install_prefix == os.path.abspath(sys.prefix): byte_compile([path], prefix=python_base) byte_compile([path], optimize=1, prefix=python_base) byte_compile([path], optimize=2, prefix=python_base)
def run(self): super().run() target = self.install_data root = self.root or '/' if target.startswith(root): target = os.path.join('/', os.path.relpath(target, root)) target = os.path.abspath(target) if not self.dry_run: # Install module plugincache # TODO: move this to pkgdist once plugin support is moved to snakeoil with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore import plugin, plugins log.info('Generating plugin cache') path = os.path.join(self.install_purelib, 'pkgcore', 'plugins') plugin.initialize_cache(plugins, force=True, cache_dir=path) # Install configuration data so pkgcore knows where to find its content, # rather than assuming it is running from a tarball/git repo. write_pkgcore_lookup_configs(self.install_purelib, target) # Generate ebd libs when not running from release tarballs that # contain pre-generated files. if not os.path.exists(os.path.join(pkgdist.REPODIR, 'man')): generated_target = os.path.join(target, EBD_INSTALL_OFFSET, '.generated') write_pkgcore_ebd_funclists(root=root, target=generated_target) write_pkgcore_ebd_cmdlists(root=root, target=generated_target) write_pkgcore_ebd_eapi_libs(root=root, target=generated_target)
def write_pkgcore_ebd_funclists(root, target): "Generate bash function lists from ebd implementation for env filtering." "" ebd_dir = target if root != '/': ebd_dir = os.path.join(root, target.lstrip('/')) os.makedirs(os.path.join(ebd_dir, 'funcs'), exist_ok=True) # generate global function list path = os.path.join(ebd_dir, 'funcs', 'global') log.info(f'writing ebd global function list: {path!r}') with open(path, 'w') as f: if subprocess.call([ os.path.join(pkgdist.REPODIR, 'ebd', 'generate_global_func_list') ], cwd=ebd_dir, stdout=f): raise DistutilsExecError("generating global function list failed") # generate EAPI specific function lists with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore.ebuild.eapi import EAPI for eapi_obj in EAPI.known_eapis.values(): eapi = str(eapi_obj) path = os.path.join(ebd_dir, 'funcs', eapi) log.info(f'writing EAPI {eapi} function list: {path!r}') with open(path, 'w') as f: if subprocess.call([ os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_func_list'), eapi ], cwd=ebd_dir, stdout=f): raise DistutilsExecError( "generating EAPI %s function list failed" % eapi)
def run(self): pkgdist.install.run(self) target = self.install_data root = self.root or '/' if target.startswith(root): target = os.path.join('/', os.path.relpath(target, root)) target = os.path.abspath(target) if not self.dry_run: # Install module plugincache # TODO: move this to pkgdist once plugin support is moved to snakeoil with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore import plugin, plugins log.info('Generating plugin cache') path = os.path.join(self.install_purelib, 'pkgcore', 'plugins') plugin.initialize_cache(plugins, force=True, cache_dir=path) # Install configuration data so pkgcore knows where to find its content, # rather than assuming it is running from a tarball/git repo. write_pkgcore_lookup_configs(self.install_purelib, target) # Generate ebd function lists used for environment filtering if # they don't exist (release tarballs contain pre-generated files). if not os.path.exists(os.path.join(pkgdist.REPODIR, 'ebd', 'generated')): write_pkgcore_ebd_funclists( root=root, target=os.path.join(target, EBD_INSTALL_OFFSET, 'generated'), scripts_dir=self.install_scripts, python_base=self.install_purelib) write_pkgcore_ebd_eapi_libs( root=root, target=os.path.join(target, EBD_INSTALL_OFFSET, 'generated'), scripts_dir=self.install_scripts, python_base=self.install_purelib)
def write_pkgcore_ebd_eapi_libs(root, target): "Generate bash EAPI scope libs for sourcing." "" ebd_dir = target if root != '/': ebd_dir = os.path.join(root, target.lstrip('/')) script = os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_lib') with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore.ebuild.eapi import EAPI for eapi_obj in EAPI.known_eapis.values(): eapi = str(eapi_obj) os.makedirs(os.path.join(ebd_dir, 'libs', eapi), exist_ok=True) # generate global scope lib path = os.path.join(ebd_dir, 'libs', eapi, 'global') log.info(f'writing global EAPI {eapi} lib: {path!r}') with open(path, 'w') as f: if subprocess.call([script, eapi], cwd=ebd_dir, stdout=f): raise DistutilsExecError( f"generating global scope EAPI {eapi} lib failed") for phase in eapi_obj.phases.values(): # generate phase scope lib path = os.path.join(ebd_dir, 'libs', eapi, phase) log.info(f'writing EAPI {eapi} {phase} phase lib: {path!r}') with open(path, 'w') as f: if subprocess.call([script, '-s', phase, eapi], cwd=ebd_dir, stdout=f): raise DistutilsExecError( f"generating {phase} phase scope EAPI {eapi} lib failed" )
def write_pkgcore_ebd_cmdlists(root, target): "Generate bash function lists from ebd implementation for env filtering.""" ebd_dir = target if root != '/': ebd_dir = os.path.join(root, target.lstrip('/')) os.makedirs(os.path.join(ebd_dir, 'cmds'), exist_ok=True) # generate EAPI specific command lists with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore.ebuild.eapi import EAPI for eapi_obj in EAPI.known_eapis.values(): eapi = str(eapi_obj) os.makedirs(os.path.join(ebd_dir, 'cmds', eapi), exist_ok=True) path = os.path.join(ebd_dir, 'cmds', eapi, 'banned') log.info(f'writing EAPI {eapi} banned command list: {path!r}') with open(path, 'w') as f: if subprocess.call( [os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_cmd_list'), '-b', eapi], cwd=ebd_dir, stdout=f): raise DistutilsExecError(f'generating EAPI {eapi} banned command list failed') path = os.path.join(ebd_dir, 'cmds', eapi, 'deprecated') log.info(f'writing EAPI {eapi} deprecated command list: {path!r}') with open(path, 'w') as f: if subprocess.call( [os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_cmd_list'), '-d', eapi], cwd=ebd_dir, stdout=f): raise DistutilsExecError(f'generating EAPI {eapi} deprecated command list failed')
def run(self): pkgdist.install.run(self) if not self.dry_run: # Install module plugincache # TODO: move this to pkgdist once plugin support is moved to snakeoil with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcheck import plugins from pkgcore import plugin log.info('Generating plugin cache') path = os.path.join(self.install_purelib, 'pkgcheck', 'plugins') plugin.initialize_cache(plugins, force=True, cache_dir=path)
def __generate_files(self): with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcheck import const os.makedirs(os.path.join(pkgdist.REPODIR, '.generated'), exist_ok=True) files = [] for obj in ('KEYWORDS', 'CHECKS', 'REPORTERS'): log.info(f'Generating {obj.lower()} list') path = os.path.join(pkgdist.REPODIR, '.generated', obj.lower()) with open(path, 'w') as f: f.write('\n'.join(getattr(const, obj).keys()) + '\n') files.append(os.path.join('.generated', obj.lower())) self.data_files.append(('share/pkgcheck', files))
def write_lookup_config(python_base, install_prefix): """Generate file of install path constants.""" path = os.path.join(python_base, pkgdist.MODULE, "_const.py") try: os.makedirs(os.path.dirname(path)) except OSError as e: if e.errno != errno.EEXIST: raise log.info("writing lookup config to %r" % path) with pkgdist.syspath(pkgdist.PACKAGEDIR): from bite import const clients = tuple(sorted(const.CLIENTS.items())) services = tuple(sorted(const.SERVICES.items())) service_opts = tuple(sorted(const.SERVICE_OPTS.items())) import textwrap with open(path, "w") as f: os.chmod(path, 0o644) # write more dynamic file for wheel installs if install_prefix != os.path.abspath(sys.prefix): f.write( textwrap.dedent(f"""\ import os.path as osp import sys INSTALL_PREFIX = osp.abspath(sys.prefix) DATA_PATH = osp.join(INSTALL_PREFIX, {DATA_INSTALL_OFFSET!r}) CONFIG_PATH = osp.join(INSTALL_PREFIX, {CONFIG_INSTALL_OFFSET!r}) CLIENTS = {clients} SERVICES = {services} SERVICE_OPTS = {service_opts} """)) else: data_path = os.path.join(install_prefix, DATA_INSTALL_OFFSET), config_path = os.path.join(install_prefix, CONFIG_INSTALL_OFFSET), f.write( textwrap.dedent(f"""\ INSTALL_PREFIX = {install_prefix!r} DATA_PATH = {data_path!r} CONFIG_PATH = {config_path!r} CLIENTS = {clients!r} SERVICES = {services!r} SERVICE_OPTS = {service_opts!r} """)) f.close() byte_compile([path], prefix=python_base) byte_compile([path], optimize=2, prefix=python_base)
def write_pkgcore_ebd_eapi_libs(root, target, scripts_dir=None, python_base='.'): "Generate bash EAPI scope libs for sourcing." "" if scripts_dir is None: scripts_dir = os.path.join(pkgdist.REPODIR, 'bin') ebd_dir = target if root != '/': ebd_dir = os.path.join(root, target.lstrip('/')) log.info("Writing ebd libs %s" % os.path.join(ebd_dir, 'libs')) # Add scripts dir to PATH and set the current python binary for filter-env # usage in global scope. env = { 'PATH': os.pathsep.join([pkgdist.SCRIPTS_DIR, os.environ.get('PATH', '')]), 'PKGCORE_PYTHON_BINARY': sys.executable, 'PKGCORE_PYTHONPATH': os.path.abspath(python_base), } script = os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_lib') with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore.ebuild.eapi import EAPI for eapi_obj in EAPI.known_eapis.values(): eapi = str(eapi_obj) os.makedirs(os.path.join(ebd_dir, 'libs', eapi), exist_ok=True) # generate global scope lib with open(os.path.join(ebd_dir, 'libs', eapi, 'global'), 'w') as f: if subprocess.call([script, eapi], cwd=ebd_dir, env=env, stdout=f): raise DistutilsExecError( f"generating global scope EAPI {eapi} lib failed") for phase in eapi_obj.phases.values(): # generate phase scope lib with open(os.path.join(ebd_dir, 'libs', eapi, phase), 'w') as f: if subprocess.call([script, '-s', phase, eapi], cwd=ebd_dir, env=env, stdout=f): raise DistutilsExecError( f"generating {phase} phase scope EAPI {eapi} lib failed" )
def write_lookup_config(python_base, install_prefix): """Generate file of install path constants.""" path = os.path.join(python_base, pkgdist.MODULE, "_const.py") os.makedirs(os.path.dirname(path), exist_ok=True) log.info("writing lookup config to %r" % path) with pkgdist.syspath(pkgdist.PACKAGEDIR): from bite import const clients = tuple(sorted(const.CLIENTS.items())) services = tuple(sorted(const.SERVICES.items())) service_opts = tuple(sorted(const.SERVICE_OPTS.items())) with open(path, "w") as f: os.chmod(path, 0o644) # write more dynamic file for wheel installs if install_prefix != os.path.abspath(sys.prefix): f.write(dedent(f"""\ import os.path as osp import sys INSTALL_PREFIX = osp.abspath(sys.prefix) DATA_PATH = osp.join(INSTALL_PREFIX, {DATA_INSTALL_OFFSET!r}) CONFIG_PATH = osp.join(INSTALL_PREFIX, {CONFIG_INSTALL_OFFSET!r}) CLIENTS = {clients} SERVICES = {services} SERVICE_OPTS = {service_opts} """)) else: data_path = os.path.join(install_prefix, DATA_INSTALL_OFFSET) config_path = os.path.join(install_prefix, CONFIG_INSTALL_OFFSET) f.write(dedent(f"""\ INSTALL_PREFIX = {install_prefix!r} DATA_PATH = {data_path!r} CONFIG_PATH = {config_path!r} CLIENTS = {clients!r} SERVICES = {services!r} SERVICE_OPTS = {service_opts!r} """)) f.close() byte_compile([path], prefix=python_base) byte_compile([path], optimize=2, prefix=python_base)
def write_pkgcore_ebd_eapi_libs(root, target, scripts_dir=None, python_base='.'): "Generate bash EAPI scope libs for sourcing.""" if scripts_dir is None: scripts_dir = os.path.join(pkgdist.REPODIR, 'bin') ebd_dir = target if root != '/': ebd_dir = os.path.join(root, target.lstrip('/')) log.info("Writing ebd libs %s" % os.path.join(ebd_dir, 'libs')) # Add scripts dir to PATH and set the current python binary for filter-env # usage in global scope. env = { 'PATH': os.pathsep.join([pkgdist.SCRIPTS_DIR, os.environ.get('PATH', '')]), 'PKGCORE_PYTHON_BINARY': sys.executable, 'PKGCORE_PYTHONPATH': os.path.abspath(python_base), } script = os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_lib') with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore.ebuild.eapi import EAPI for eapi_obj in EAPI.known_eapis.values(): eapi = str(eapi_obj) os.makedirs(os.path.join(ebd_dir, 'libs', eapi), exist_ok=True) # generate global scope lib with open(os.path.join(ebd_dir, 'libs', eapi, 'global'), 'w') as f: if subprocess.call( [script, eapi], cwd=ebd_dir, env=env, stdout=f): raise DistutilsExecError( f"generating global scope EAPI {eapi} lib failed") for phase in eapi_obj.phases.values(): # generate phase scope lib with open(os.path.join(ebd_dir, 'libs', eapi, phase), 'w') as f: if subprocess.call( [script, '-s', phase, eapi], cwd=ebd_dir, env=env, stdout=f): raise DistutilsExecError( f"generating {phase} phase scope EAPI {eapi} lib failed")
def run(self): pkgdist.install.run(self) target = self.install_data root = self.root or '/' if target.startswith(root): target = os.path.join('/', os.path.relpath(target, root)) target = os.path.abspath(target) if not self.dry_run: # Install configuration data so the program can find its content, # rather than assuming it is running from a tarball/git repo. write_obj_lists(self.install_purelib, target) # Install module plugincache # TODO: move this to pkgdist once plugin support is moved to snakeoil with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcheck import plugins from pkgcore import plugin log.info('Generating plugin cache') path = os.path.join(self.install_purelib, 'pkgcheck', 'plugins') plugin.initialize_cache(plugins, force=True, cache_dir=path)
def run(self): pkgdist.install.run(self) target = self.install_data root = self.root or '/' if target.startswith(root): target = os.path.join('/', os.path.relpath(target, root)) target = os.path.abspath(target) if not self.dry_run: # Install module plugincache # TODO: move this to pkgdist once plugin support is moved to snakeoil with pkgdist.syspath(pkgdist.PACKAGEDIR): from pkgcore import plugin, plugins log.info('Generating plugin cache') path = os.path.join(self.install_purelib, 'pkgcore', 'plugins') plugin.initialize_cache(plugins, force=True, cache_dir=path) # Install configuration data so pkgcore knows where to find its content, # rather than assuming it is running from a tarball/git repo. write_pkgcore_lookup_configs(self.install_purelib, target) # Generate ebd function lists used for environment filtering if # they don't exist (release tarballs contain pre-generated files). if not os.path.exists( os.path.join(pkgdist.REPODIR, 'ebd', 'generated')): write_pkgcore_ebd_funclists(root=root, target=os.path.join( target, EBD_INSTALL_OFFSET, 'generated'), scripts_dir=self.install_scripts, python_base=self.install_purelib) write_pkgcore_ebd_eapi_libs(root=root, target=os.path.join( target, EBD_INSTALL_OFFSET, 'generated'), scripts_dir=self.install_scripts, python_base=self.install_purelib)