diff --git a/CHANGELOG.md b/CHANGELOG.md index 0260403..bc284c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tinyhost/tinyhost.py b/tinyhost/tinyhost.py index 319223d..ba06985 100644 --- a/tinyhost/tinyhost.py +++ b/tinyhost/tinyhost.py @@ -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 @@ -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. @@ -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 = [] @@ -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) @@ -226,19 +215,12 @@ 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 @@ -246,10 +228,7 @@ def get_datastore_presigned_urls(bucket, prefix, datastore_id, duration): ["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 @@ -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="") @@ -309,13 +287,7 @@ 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: @@ -323,4 +295,4 @@ def tinyhost(html_files, bucket, prefix, duration, reset): if __name__ == "__main__": - tinyhost() \ No newline at end of file + tinyhost() diff --git a/tinyhost/version.py b/tinyhost/version.py index b5326bf..70aa145 100644 --- a/tinyhost/version.py +++ b/tinyhost/version.py @@ -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 = ""