Back-ported format strings for compatibility with Py 3.5

Also fixed a encoding error where Heroku --json return needs to be treated as UTF8
pull/145/head
Simon Willison 2017-11-22 09:42:29 -08:00
rodzic a9b9d42791
commit fb505de11c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: FBB38AFE227189DB
2 zmienionych plików z 21 dodań i 9 usunięć

Wyświetl plik

@ -59,13 +59,18 @@ def publish(publisher, files, name, metadata, extra_options, force, branch, **ex
"""Exit (with error message) if ``binary` isn't installed"""
if not shutil.which(binary):
click.secho(
f" Publishing to {publish_target} requires {binary} to be installed and configured ",
"Publishing to {publish_target} requires {binary} to be installed and configured".format(
publish_target=publish_target,
binary=binary,
),
bg='red',
fg='white',
bold=True,
err=True
)
click.echo(f"Follow the instructions at {install_link}", err=True)
click.echo("Follow the instructions at {install_link}".format(
install_link=install_link,
), err=True)
sys.exit(1)
if publisher == 'now':
@ -87,10 +92,13 @@ def publish(publisher, files, name, metadata, extra_options, force, branch, **ex
call(["heroku", "plugins:install", "heroku-builds"])
with temporary_heroku_directory(files, name, metadata, extra_options, branch, extra_metadata):
create_output = check_output(['heroku', 'apps:create', '--json'])
create_output = check_output(
['heroku', 'apps:create', '--json']
).decode('utf8')
app_name = json.loads(create_output)["name"]
call(["heroku", "builds:create", "-a", app_name])
@cli.command()
@click.argument('files', type=click.Path(exists=True), nargs=-1, required=True)
@click.option(

Wyświetl plik

@ -151,8 +151,8 @@ def temporary_docker_directory(files, name, metadata, extra_options, branch=None
os.mkdir(datasette_dir)
saved_cwd = os.getcwd()
file_paths = [
os.path.join(saved_cwd, name)
for name in files
os.path.join(saved_cwd, file_path)
for file_path in files
]
file_names = [os.path.split(f)[-1] for f in files]
if metadata:
@ -185,8 +185,8 @@ def temporary_heroku_directory(files, name, metadata, extra_options, branch=None
saved_cwd = os.getcwd()
file_paths = [
os.path.join(saved_cwd, name)
for name in files
os.path.join(saved_cwd, file_path)
for file_path in files
]
file_names = [os.path.split(f)[-1] for f in files]
@ -207,7 +207,9 @@ def temporary_heroku_directory(files, name, metadata, extra_options, branch=None
open('runtime.txt', 'w').write('python-3.6.2')
if branch:
install_from = f'https://github.com/simonw/datasette/archive/{branch}.zip'
install_from = 'https://github.com/simonw/datasette/archive/{branch}.zip'.format(
branch=branch
)
else:
install_from = 'datasette'
@ -216,7 +218,9 @@ def temporary_heroku_directory(files, name, metadata, extra_options, branch=None
open('bin/post_compile', 'w').write('datasette build --inspect-file inspect-data.json')
quoted_files = " ".join(map(shlex.quote, files))
procfile_cmd = f'web: datasette serve --host 0.0.0.0 {quoted_files} --cors --port $PORT --inspect-file inspect-data.json'
procfile_cmd = 'web: datasette serve --host 0.0.0.0 {quoted_files} --cors --port $PORT --inspect-file inspect-data.json'.format(
quoted_files=quoted_files,
)
open('Procfile', 'w').write(procfile_cmd)
for path, filename in zip(file_paths, file_names):