├── README.md ├── .prettierrc.toml ├── Procfile ├── requirements.txt ├── vercel.json ├── setup.cfg ├── .github └── workflows │ └── main.yaml ├── .pre-commit-config.yaml ├── fly.toml ├── LICENSE ├── pyproject.toml ├── src └── app.py └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # html-reprs 2 | -------------------------------------------------------------------------------- /.prettierrc.toml: -------------------------------------------------------------------------------- 1 | tabWidth = 2 2 | semi = false 3 | singleQuote = true 4 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | # Modify this Procfile to fit your needs 2 | web: gunicorn -w 1 -k uvicorn.workers.UvicornWorker src.app:app 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cftime 2 | dask[complete] 3 | fastapi 4 | fsspec 5 | gcsfs 6 | gunicorn 7 | s3fs 8 | uvicorn 9 | xarray>=2022.06 10 | zarr 11 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "public": false, 4 | "builds": [{ "src": "src/app.py", "use": "@vercel/python" }], 5 | "routes": [ 6 | { "src": "/", "dest": "src/app.py" }, 7 | { "src": "/docs", "dest": "src/app.py" }, 8 | { "src": "/openapi.json", "dest": "src/app.py" } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | exclude = docs 3 | ignore = E203,E266,E501,W503,E722,E402,C901,E731 4 | max-line-length = 100 5 | max-complexity = 18 6 | select = B,C,E,F,W,T4,B9 7 | 8 | [isort] 9 | profile = black 10 | 11 | [tool:pytest] 12 | console_output_style = count 13 | addopts = --cov=./ --cov-report=xml --verbose 14 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Fly Deploy 2 | on: [push] 3 | env: 4 | FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} 5 | 6 | concurrency: 7 | group: ${{ github.workflow }}-${{ github.ref }} 8 | cancel-in-progress: true 9 | 10 | jobs: 11 | deploy: 12 | name: Deploy app 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: superfly/flyctl-actions/setup-flyctl@master 17 | - run: flyctl deploy --remote-only 18 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | ci: 2 | autoupdate_schedule: monthly 3 | 4 | repos: 5 | - repo: https://github.com/pre-commit/pre-commit-hooks 6 | rev: v4.6.0 7 | hooks: 8 | - id: trailing-whitespace 9 | - id: end-of-file-fixer 10 | - id: check-docstring-first 11 | - id: check-json 12 | - id: check-yaml 13 | - id: double-quote-string-fixer 14 | - id: debug-statements 15 | - id: mixed-line-ending 16 | 17 | - repo: https://github.com/astral-sh/ruff-pre-commit 18 | rev: "v0.6.5" 19 | hooks: 20 | - id: ruff 21 | args: ["--fix"] 22 | - id: ruff-format 23 | 24 | - repo: https://github.com/pre-commit/mirrors-prettier 25 | rev: v4.0.0-alpha.8 26 | hooks: 27 | - id: prettier 28 | -------------------------------------------------------------------------------- /fly.toml: -------------------------------------------------------------------------------- 1 | # fly.toml file generated for html-reprs on 2022-09-08T19:34:42-06:00 2 | 3 | app = "html-reprs" 4 | kill_signal = "SIGINT" 5 | kill_timeout = 5 6 | processes = [] 7 | 8 | [build] 9 | builder = "paketobuildpacks/builder:base" 10 | 11 | [env] 12 | PORT = "8080" 13 | 14 | [experimental] 15 | allowed_public_ports = [] 16 | auto_rollback = true 17 | 18 | [[services]] 19 | http_checks = [] 20 | internal_port = 8080 21 | processes = ["app"] 22 | protocol = "tcp" 23 | script_checks = [] 24 | [services.concurrency] 25 | hard_limit = 25 26 | soft_limit = 20 27 | type = "connections" 28 | 29 | [[services.ports]] 30 | force_https = true 31 | handlers = ["http"] 32 | port = 80 33 | 34 | [[services.ports]] 35 | handlers = ["tls", "http"] 36 | port = 443 37 | 38 | [[services.tcp_checks]] 39 | grace_period = "1s" 40 | interval = "15s" 41 | restart_limit = 0 42 | timeout = "2s" 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Anderson Banihirwe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | 2 | [build-system] 3 | requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"] 4 | 5 | 6 | [tool.ruff] 7 | line-length = 100 8 | target-version = "py310" 9 | extend-include = ["*.ipynb"] 10 | 11 | 12 | builtins = ["ellipsis"] 13 | # Exclude a variety of commonly ignored directories. 14 | exclude = [ 15 | ".bzr", 16 | ".direnv", 17 | ".eggs", 18 | ".git", 19 | ".git-rewrite", 20 | ".hg", 21 | ".ipynb_checkpoints", 22 | ".mypy_cache", 23 | ".nox", 24 | ".pants.d", 25 | ".pyenv", 26 | ".pytest_cache", 27 | ".pytype", 28 | ".ruff_cache", 29 | ".svn", 30 | ".tox", 31 | ".venv", 32 | ".vscode", 33 | "__pypackages__", 34 | "_build", 35 | "buck-out", 36 | "build", 37 | "dist", 38 | "node_modules", 39 | "site-packages", 40 | "venv", 41 | ] 42 | [tool.ruff.lint] 43 | per-file-ignores = {} 44 | ignore = [ 45 | "E721", # Comparing types instead of isinstance 46 | "E741", # Ambiguous variable names 47 | "E501", # Conflicts with ruff format 48 | ] 49 | select = [ 50 | # Pyflakes 51 | "F", 52 | # Pycodestyle 53 | "E", 54 | "W", 55 | # isort 56 | "I", 57 | # Pyupgrade 58 | "UP", 59 | ] 60 | 61 | 62 | [tool.ruff.lint.mccabe] 63 | max-complexity = 18 64 | 65 | [tool.ruff.lint.isort] 66 | known-first-party = ["intake_esm"] 67 | combine-as-imports = true 68 | 69 | [tool.ruff.format] 70 | quote-style = "single" 71 | docstring-code-format = true 72 | 73 | [tool.ruff.lint.pydocstyle] 74 | convention = "numpy" 75 | -------------------------------------------------------------------------------- /src/app.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pydantic 4 | from fastapi import FastAPI, Query, status 5 | from fastapi.middleware.cors import CORSMiddleware 6 | from fastapi.responses import JSONResponse 7 | 8 | origins = ['*'] 9 | 10 | app = FastAPI() 11 | app.add_middleware( 12 | CORSMiddleware, 13 | allow_origins=origins, 14 | allow_credentials=True, 15 | allow_methods=['*'], 16 | allow_headers=['*'], 17 | ) 18 | 19 | 20 | @app.get('/') 21 | def index(): 22 | return {'message': 'Hello World!'} 23 | 24 | 25 | @app.get('/xarray/') 26 | def xarray( 27 | url: pydantic.AnyUrl = Query( 28 | ..., 29 | description='URL to a zarr store', 30 | example='https://ncsa.osn.xsede.org/Pangeo/pangeo-forge/HadISST-feedstock/hadisst.zarr', 31 | ), 32 | ): 33 | import xarray as xr 34 | import zarr 35 | 36 | error_message = f'An error occurred while fetching the data from URL: {url}' 37 | 38 | try: 39 | with xr.open_dataset(url, engine='zarr', chunks={}) as ds: 40 | html = ds._repr_html_().strip() 41 | 42 | del ds 43 | 44 | return {'html': html, 'dataset': url} 45 | 46 | except (zarr.errors.GroupNotFoundError, FileNotFoundError): 47 | return JSONResponse( 48 | status_code=status.HTTP_404_NOT_FOUND, 49 | content={'detail': f'{error_message}. Dataset not found.'}, 50 | ) 51 | 52 | except PermissionError: 53 | return JSONResponse( 54 | status_code=status.HTTP_403_FORBIDDEN, 55 | content={'detail': f'{error_message}. Permission denied.'}, 56 | ) 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | --------------------------------------------------------------------------------