def test(zfg, args=None): """Run configured ``test commands``. """ dev(zfg) # first (re)install project in develop mode for command in zfg.TEST_COMMANDS: print("zetup: Running %s" % repr(command)) status = call(command, shell=True, env=os.environ) if status: # ==> error return status
def conda(zfg, args): """The actual conda command action called by Command base. """ import yaml metadir = Path('.conda') metadir.mkdir_p() metafile = metadir / 'meta.yaml' buildfile = metadir / 'build.sh' def conda_req(req): """conda wants space between requirement name and version specs. """ return re.sub(r'([=<>]+)', r' \1', str(req)) requirements = list(map(conda_req, zfg.REQUIRES)) # Also add all extra requirements # (conda doesn't seem to have such an extra features management): for extra in zfg.EXTRAS.values(): requirements.extend(map(conda_req, extra)) meta = { # to be dumped to meta.yaml 'package': { 'name': zfg.NAME, 'version': str(zfg.VERSION), }, 'source': { 'fn': '%s-%s.tar.gz' % (zfg.NAME, zfg.VERSION), # The absolute path to the sdist in dist/ 'url': 'file://%s' % os.path.realpath(os.path.join( 'dist', '%s-%s.tar.gz' % (zfg.NAME, zfg.VERSION))) }, 'requirements': { 'build': [ 'python', 'pyyaml', ] + requirements, 'run': [ 'python', ] + requirements, }, 'about': { 'home': zfg.URL, 'summary': zfg.DESCRIPTION, }, } with open(metafile, 'w') as f: yaml.dump(meta, f, default_flow_style=False) with open(buildfile, 'w') as f: f.write('#!/bin/bash' '\n\n' '$PYTHON setup.py install' '\n') return call(['conda', 'build', metadir], env=os.environ)
def pip(command, raise_=True, **options): """ Run a pip `command`. :param command: The sequence of pip arguments :param raise_: Raise exception if pip `command` fails with non-zero exit code? :param options: General options for ``zetup.call``, including all options for ``subprocess.call`` >>> import zetup >>> zetup.pip(['list', '-v']) Package...Version...Location...Installer -------...-------...--------...--------- ... 0 :return: ``0`` on success or, if called with ``raise_=False``, also any non-zero pip exit code >>> zetup.pip(['invalid'], raise_=False) 1 :raises zetup.ZetupPipError: on non-zero pip exit codes, if not called with ``raise_=False`` >>> zetup.pip(['invalid']) Traceback (most recent call last): ... ZetupPipError: pip command ['invalid'] failed with exit code 1 """ from pip._internal import configuration, main # HACK: Avoid unnecessary debug messages (which also destroy doctests) configuration.logger.level = logging.INFO # try: # exit_code = main(command) # except SystemExit as exc: # exit_code = exc.code exit_code = call([sys.executable, '-m', 'pip'] + list(command)) if raise_ and exit_code != 0: raise ZetupPipError(command, exit_code) return exit_code
def __call__(self, *args, **options): """Runs external conda executable with the given `args`. - Automatically adds ``--json`` arg and returns pythonized JSON output. - If called with ``json=False``, stdout is not captured and status code is returned. """ args = list(args) if self.command: args.insert(0, self.command) if options.get('json', True): return json.loads(Popen( ['conda'] + args + ['--json'], env=os.environ, stdout=PIPE, universal_newlines=True ).communicate()[0]) return call(['conda'] + args, env=os.environ)
def __call__(self, *args, **options): """Runs external conda executable with the given `args`. - Automatically adds ``--json`` arg and returns pythonized JSON output. - If called with ``json=False``, stdout is not captured and status code is returned. """ args = list(args) if self.command: args.insert(0, self.command) if options.get('json', True): return json.loads( Popen(['conda'] + args + ['--json'], env=os.environ, stdout=PIPE, universal_newlines=True).communicate()[0]) return call(['conda'] + args, env=os.environ)
def pytest(zfg, args=None): """The actual pytest command action called by Command base. """ return call(['py.test' if not WIN else 'py.test.exe'])
def run(zfg, args=None, cmd=None): if not cmd and args: cmd = args.cmd return call(cmd)
def tox(self, args=None): return call(['tox'], env=os.environ)