def exec_script_command(cmd: str, pretend: bool) -> int: """ This will execute the already compiled script command. This function serves the purpose of encapsulating the low level code of spawning a subprocess from the rest of the logic. """ if not pretend: with conf.within_proj_dir(): # God knows why, if we run the command using `shell.run()` and it # exists with non-zero code it will also kill the parent peltak # process. The Popen arguments are the same, to my knowledge # everything is the same but the way it behaves is completely # different. If we just use Popen directly, everything works as # expected ¯\_(ツ)_/¯ p = subprocess.Popen(cmd, shell=True) try: p.communicate() return p.returncode except KeyboardInterrupt: p.kill() return -1 else: log.info( "<90>{bar}<0>\n{script}\n<90>{bar}", bar='=' * 80, script=shell.highlight(cmd, 'bash'), ) return 0
def start(component: str, exact: str): """ Create a new release branch. Args: component (str): Version component to bump when creating the release. Can be *major*, *minor* or *patch*. exact (str): The exact version to set for the release. Overrides the component argument. This allows to re-release a version if something went wrong with the release upload. """ version_files = versioning.get_version_files() develop = conf.get('git.devel_branch', 'develop') common.assert_on_branch(develop) with conf.within_proj_dir(): out = shell.run('git status --porcelain', capture=True).stdout lines = out.split(os.linesep) has_changes = any(not line.startswith('??') for line in lines if line.strip()) if has_changes: log.info("Cannot release: there are uncommitted changes") exit(1) old_ver, new_ver = versioning.bump(component, exact) log.info("Bumping package version") log.info(" old version: <35>{}".format(old_ver)) log.info(" new version: <35>{}".format(new_ver)) with conf.within_proj_dir(): branch = 'release/' + new_ver hooks.register.call('pre-release-start', branch, old_ver, new_ver) common.git_checkout(branch, create=True) log.info("Creating commit for the release") shell.run('git add {files} && git commit -m "{msg}"'.format( files=' '.join(f'"{v.path}"' for v in version_files), msg="Releasing v{}".format(new_ver))) hooks.register.call('post-release-start', branch, old_ver, new_ver)
def tag(message: str): """ Tag the current commit with the current version. """ release_ver = versioning.current() message = message or 'v{} release'.format(release_ver) with conf.within_proj_dir(): log.info("Creating release tag") git.tag( author=git.latest_commit().author, name='v{}'.format(release_ver), message=message, )
def test_works_as_expected(p_getcwd, p_chdir, app_conf): # Better one test than none fake_cwd = 'fake_dir' path = '.' p_getcwd.return_value = fake_cwd with conf.within_proj_dir(path): p_getcwd.assert_called() p_chdir.assert_called_once_with(conf.proj_path(path)) # last call was back to our fake working directory p_chdir.assert_called_with(fake_cwd)
def upload(target: str): """ Upload the release to a pypi server. TODO: Make sure the git directory is clean before allowing a release. Args: target (str): pypi target as defined in ~/.pypirc """ log.info("Uploading to pypi server <33>{}".format(target)) with conf.within_proj_dir(): shell.run('python setup.py sdist register -r "{}"'.format(target)) shell.run('python setup.py sdist upload -r "{}"'.format(target))
def devserver(port, admin_port, clear): # type: (int, int, bool) -> None """ Run devserver. Args: port (int): Port on which the app will be served. admin_port (int): Port on which the admin interface is served. clear (bool): If set to **True**, clear the datastore on startup. """ admin_port = admin_port or (port + 1) args = ['--port={}'.format(port), '--admin_port={}'.format(admin_port)] if clear: args += ['--clear_datastore=yes'] with conf.within_proj_dir(): shell.run('dev_appserver.py . {args}'.format(args=' '.join(args)))