Skip to content

Commit

Permalink
Bump version to v0.4.18 for release
Browse files Browse the repository at this point in the history
  • Loading branch information
jakep-allenai committed Jan 24, 2025
1 parent 065f243 commit ed62f06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [v0.4.18](https://github.com/allenai/tinyhost/releases/tag/v0.4.18) - 2025-01-24

## [v0.4.17](https://github.com/allenai/tinyhost/releases/tag/v0.4.17) - 2025-01-24

## [v0.4.16](https://github.com/allenai/tinyhost/releases/tag/v0.4.16) - 2025-01-24
Expand Down
48 changes: 10 additions & 38 deletions tinyhost/tinyhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from typing import Optional
from urllib.parse import urlparse

import click
import boto3
import click
import magic
from botocore.exceptions import ClientError, NoCredentialsError
from bs4 import BeautifulSoup
Expand All @@ -18,11 +18,7 @@


def tinyhost_main(
html_files: list[str],
bucket: Optional[str]=None,
prefix: str="",
duration: int=604800,
reset: bool=False
html_files: list[str], bucket: Optional[str] = None, prefix: str = "", duration: int = 604800, reset: bool = False
):
"""
Core logic that uploads an HTML file (or .ipynb) to S3 and returns signed URLs.
Expand All @@ -47,9 +43,7 @@ def tinyhost_main(
if not bucket:
bucket = run_new_bucket_flow()
if not bucket:
raise RuntimeError(
"Unable to automatically detect/create an S3 bucket, please specify one using --bucket"
)
raise RuntimeError("Unable to automatically detect/create an S3 bucket, please specify one using --bucket")

results = []

Expand Down Expand Up @@ -168,17 +162,12 @@ def tinyhost_main(
html_file,
bucket,
s3_key,
ExtraArgs={
"ContentType": "text/html",
"CacheControl": "max-age=31536000, public"
},
ExtraArgs={"ContentType": "text/html", "CacheControl": "max-age=31536000, public"},
)

# Generate a signed URL
signed_url = s3_client.generate_presigned_url(
"get_object",
Params={"Bucket": bucket, "Key": s3_key},
ExpiresIn=duration
"get_object", Params={"Bucket": bucket, "Key": s3_key}, ExpiresIn=duration
)

results.append(signed_url)
Expand Down Expand Up @@ -226,30 +215,20 @@ def get_datastore_presigned_urls(bucket, prefix, datastore_id, duration):
except ClientError as e:
if e.response["Error"]["Code"] == "404":
empty_json = json.dumps({})
s3_client.put_object(
Bucket=bucket,
Key=object_key,
Body=empty_json,
ContentType="application/json"
)
s3_client.put_object(Bucket=bucket, Key=object_key, Body=empty_json, ContentType="application/json")
else:
raise e

get_url = s3_client.generate_presigned_url(
"get_object",
Params={"Bucket": bucket, "Key": object_key},
ExpiresIn=duration
"get_object", Params={"Bucket": bucket, "Key": object_key}, ExpiresIn=duration
)

# POST is used for the writing side, because it's the only way to ensure a maximum length
post_conditions = [
["content-length-range", 0, MAX_DATASTORE_SIZE],
]
post_dict = s3_client.generate_presigned_post(
Bucket=bucket,
Key=object_key,
Conditions=post_conditions,
ExpiresIn=duration
Bucket=bucket, Key=object_key, Conditions=post_conditions, ExpiresIn=duration
)
return get_url, post_dict

Expand Down Expand Up @@ -281,7 +260,6 @@ def run_new_bucket_flow():
raise RuntimeError(f"Error checking bucket existence: {e}")



@click.command()
@click.option("--bucket", help="S3 bucket on which to host your static site")
@click.option("--prefix", help="S3 bucket prefix to use", default="")
Expand Down Expand Up @@ -309,18 +287,12 @@ def tinyhost(html_files, bucket, prefix, duration, reset):
return

try:
urls = tinyhost_main(
html_files=html_files,
bucket=bucket,
prefix=prefix,
duration=duration,
reset=reset
)
urls = tinyhost_main(html_files=html_files, bucket=bucket, prefix=prefix, duration=duration, reset=reset)
for url in urls:
click.echo(f"\nAccess it at:\n{url}\n")
except Exception as e:
click.echo(str(e))


if __name__ == "__main__":
tinyhost()
tinyhost()
2 changes: 1 addition & 1 deletion tinyhost/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
_MINOR = "4"
# On main and in a nightly release the patch should be one ahead of the last
# released build.
_PATCH = "17"
_PATCH = "18"
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
# https://semver.org/#is-v123-a-semantic-version for the semantics.
_SUFFIX = ""
Expand Down

0 comments on commit ed62f06

Please sign in to comment.