Skip to content

Commit

Permalink
Back-ported format strings for compatibility with Py 3.5
Browse files Browse the repository at this point in the history
Also fixed a encoding error where Heroku --json return needs to be treated as UTF8
  • Loading branch information
simonw committed Nov 22, 2017
1 parent a9b9d42 commit fb505de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 11 additions & 3 deletions datasette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ def _fail_if_publish_binary_not_installed(binary, publish_target, install_link):
"""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':
Expand All @@ -87,10 +92,13 @@ def _fail_if_publish_binary_not_installed(binary, publish_target, install_link):
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(
Expand Down
16 changes: 10 additions & 6 deletions datasette/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]

Expand All @@ -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'

Expand All @@ -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):
Expand Down

0 comments on commit fb505de

Please sign in to comment.