Skip to content

Commit 73e7143

Browse files
authored
Merge pull request #6 from simple-repository/feature/static-files-at-runtime
Generate the static file hashes at app startup, rather than requiring a build stage
2 parents bdcdbbc + 5ac15e1 commit 73e7143

24 files changed

+304
-81
lines changed

.github/workflows/python-publish.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This workflow will upload a Python Package to PyPI when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
release-build:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: "3.x"
28+
29+
- name: Build release distributions
30+
run: |
31+
# NOTE: put your own distribution build steps here.
32+
python -m pip install build
33+
python -m build
34+
35+
- name: Upload distributions
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: release-dists
39+
path: dist/
40+
41+
pypi-publish:
42+
runs-on: ubuntu-latest
43+
needs:
44+
- release-build
45+
permissions:
46+
# IMPORTANT: this permission is mandatory for trusted publishing
47+
id-token: write
48+
49+
# Dedicated environments with protections for publishing are strongly recommended.
50+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51+
environment:
52+
name: pypi
53+
url: https://pypi.org/p/simple-repository-browser
54+
55+
steps:
56+
- name: Retrieve release distributions
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: release-dists
60+
path: dist/
61+
62+
- name: Publish release distributions to PyPI
63+
uses: pypa/gh-action-pypi-publish@release/v1
64+
with:
65+
packages-dir: dist/

.github/workflows/python-test.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
test:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
python-version: ["3.11"]
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install pre-commit --editable .[test]
31+
- name: pre-commit run
32+
run: |
33+
pre-commit run -a
34+
- name: Test with pytest
35+
run: |
36+
python -m pytest .
37+
38+
static_analysis:
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
python-version: ["3.11"]
43+
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v3
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
python -m pip install mypy --editable .[test]
56+
- name: mypy
57+
run: |
58+
python -m mypy -p simple_repository_browser

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
simple_repository_browser/static_source/js/simple-repository-browser.project.js.LICENSE.txt
2-
simple_repository_browser/static_source/js/simple-repository-browser.core.js.LICENSE.txt
3-
simple_repository_browser/static_source/js/simple-repository-browser.core.js
4-
simple_repository_browser/static_source/js/simple-repository-browser.project.js
1+
simple_repository_browser/static/js/simple-repository-browser.project.js.LICENSE.txt
2+
simple_repository_browser/static/js/simple-repository-browser.core.js.LICENSE.txt
3+
simple_repository_browser/static/js/simple-repository-browser.core.js
4+
simple_repository_browser/static/js/simple-repository-browser.project.js
55

66
*/_version.py
77
node_modules

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ The browser can be run with:
7979
```bash
8080
python -m simple_repository_browser
8181
```
82-

javascript/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
},
88
output: {
99
filename: '[name]',
10-
path: path.resolve(__dirname, '../simple_repository_browser/static_source/js/')
10+
path: path.resolve(__dirname, '../simple_repository_browser/static/js/')
1111
},
1212
resolve: {
1313
extensions: [".ts", ".js"],

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"pkginfo>=1.12",
3333
"readme-renderer[md]",
3434
"simple-repository~=0.9",
35+
"typing-extensions",
3536
"uvicorn",
3637
"authlib",
3738
"starlette[full]",
@@ -64,6 +65,11 @@ ensure_newline_before_comments = true
6465
line_length = 88
6566
force_sort_within_sections = true
6667

68+
# [tool.mypy]
69+
# check_untyped_defs = true
70+
# disallow_untyped_defs = true
71+
# disallow_untyped_calls = true
72+
6773
[[tool.mypy.overrides]]
6874
module = [
6975
"diskcache",

setup.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

simple_repository_browser/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def handler(args: typing.Any) -> None:
4242
# Include the "base" folder, such that upstream templates can inherit from "base/...".
4343
here/"templates",
4444
],
45-
static_files_path=here / "static",
45+
static_files_paths=[here / "static"],
4646
crawl_popular_projects=args.crawl_popular_projects,
4747
url_prefix=args.url_prefix,
4848
browser_version=__version__,

simple_repository_browser/_app.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from . import controller, crawler, errors, fetch_projects, model, view
1717
from .metadata_injector import MetadataInjector
18+
from .static_files import generate_manifest
1819

1920

2021
class AppBuilder:
@@ -24,15 +25,15 @@ def __init__(
2425
repository_url: str,
2526
cache_dir: Path,
2627
template_paths: typing.Sequence[Path],
27-
static_files_path: Path,
28+
static_files_paths: typing.Sequence[Path],
2829
crawl_popular_projects: bool,
2930
browser_version: str,
3031
) -> None:
3132
self.url_prefix = url_prefix
3233
self.repository_url = repository_url
3334
self.cache_dir = cache_dir
3435
self.template_paths = template_paths
35-
self.static_files_path = static_files_path
36+
self.static_files_manifest = generate_manifest(static_files_paths)
3637
self.crawl_popular_projects = crawl_popular_projects
3738
self.browser_version = browser_version
3839

@@ -50,6 +51,7 @@ def create_app(self) -> fastapi.FastAPI:
5051
_view = self.create_view()
5152

5253
async def lifespan(app: fastapi.FastAPI):
54+
5355
async with (
5456
httpx.AsyncClient(timeout=30) as http_client,
5557
aiosqlite.connect(self.db_path, timeout=5) as db,
@@ -61,7 +63,7 @@ async def lifespan(app: fastapi.FastAPI):
6163
),
6264
view=_view,
6365
)
64-
router = _controller.create_router(self.static_files_path)
66+
router = _controller.create_router(self.static_files_manifest)
6567
app.mount(self.url_prefix or "/", router)
6668

6769
if self.url_prefix:
@@ -107,7 +109,7 @@ async def catch_exceptions_middleware(request: fastapi.Request, call_next):
107109
return app
108110

109111
def create_view(self) -> view.View:
110-
return view.View(self.template_paths, self.browser_version, static_files_path=self.static_files_path)
112+
return view.View(self.template_paths, self.browser_version, static_files_manifest=self.static_files_manifest)
111113

112114
def create_crawler(self, http_client: httpx.AsyncClient, source: SimpleRepository) -> crawler.Crawler:
113115
return crawler.Crawler(

simple_repository_browser/_compile_static.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)