Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aip-dev/site-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: egen/site-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 6 commits
  • 18 files changed
  • 2 contributors

Commits on Oct 12, 2022

  1. Copy the full SHA
    02d2ad7 View commit details

Commits on Oct 13, 2022

  1. Copy the full SHA
    1a13532 View commit details
  2. Copy the full SHA
    9b62e2c View commit details
  3. Copy the full SHA
    830b133 View commit details

Commits on Nov 2, 2022

  1. Add minimal AIP rules for Bazel reproducible builds without Docker (#1)

    * feat: add experimental bazel rules
    
    * feat: initial working rules
    
    * feat: add vendored dependencies
    
    * chore: update dependencies
    
    * chore: rename `.bzl` file
    christian-roggia authored Nov 2, 2022
    Copy the full SHA
    67de61f View commit details
  2. Copy the full SHA
    0c35ea0 View commit details
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -6,3 +6,9 @@ htmlcov
build/
dist/
.venv/
.DS_Store
.vscode
__pycache__

# Bazel
bazel-*
86 changes: 86 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
load("//:requirements.bzl", "requirement")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

# The requirements.bzl file is generated with a reference to the interpreter for the host platform.
# In order to check in a platform-agnostic file, we have to replace that reference with the symbol
# loaded from our python toolchain.
genrule(
name = "make_platform_agnostic",
srcs = ["@pip//:requirements.bzl"],
outs = ["requirements.clean.bzl"],
cmd = " | ".join([
"cat $<",
# Insert our load statement after the existing one so we don't produce a file with buildifier warnings
"""sed -e '/^load.*/i\\'$$'\\n''load("@python39//:defs.bzl", "interpreter")'""",
"""tr "'" '"' """,
"""sed 's#"@python39_.*//:bin/python3"#interpreter#' >$@""",
]),
)

write_file(
name = "gen_update",
out = "update.sh",
content = [
# This depends on bash, would need tweaks for Windows
"#!/usr/bin/env bash",
# Bazel gives us a way to access the source folder!
"cd $BUILD_WORKSPACE_DIRECTORY",
"cp -fv bazel-bin/requirements.clean.bzl requirements.bzl",
],
)

sh_binary(
name = "vendor_requirements",
srcs = ["update.sh"],
data = [":make_platform_agnostic"],
)

# Similarly ensures that the requirements.bzl file is updated
# based on the requirements.txt lockfile.
diff_test(
name = "test_vendored",
failure_message = "Please run: bazel run //:vendor_requirements",
file1 = "requirements.bzl",
file2 = ":make_platform_agnostic",
)

filegroup(
name = "data",
srcs = glob([
"aip_site/support/assets/js/**/*.js",
"aip_site/support/scss/**/*.scss",
"aip_site/support/templates/**/*.j2",
]) + [
"aip_site/support/assets/favicon.ico",
"aip_site/support/assets/images/glue-icons.svg",
"aip_site/support/assets/images/github.png",
] + [
"VERSION",
"README.md",
],
)

py_binary(
name = "site-generator",
srcs = glob(["aip_site/**/*.py"]) + ["//internal:main.py"],
data = [":data"],
main = "//internal:main.py",
visibility = ["//visibility:public"],
deps = [
requirement("click"),
requirement("flask"),
requirement("itsdangerous"),
requirement("jinja2"),
requirement("markdown"),
requirement("markupsafe"),
requirement("pygments"),
requirement("pymdown-extensions"),
requirement("pyscss"),
requirement("pyyaml"),
requirement("six"),
requirement("types-Markdown"),
requirement("types-PyYAML"),
requirement("werkzeug"),
],
)
43 changes: 43 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
workspace(name = "rules_aip")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "rules_python",
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
strip_prefix = "rules_python-0.13.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python39",
python_version = "3.9",
)

load("@python39//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "pip",
python_interpreter_target = interpreter,
requirements = "//internal:requirements.txt",
)

load("//:requirements.bzl", "install_deps")

install_deps()
3 changes: 2 additions & 1 deletion aip_site/cli.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
from __future__ import annotations

import click
import os

from aip_site import server
from aip_site.publisher import Publisher
@@ -47,4 +48,4 @@ def publish(src: str, dest: str):
def serve(src: str):
"""Run a debug server."""
server.app.before_request(server.site_load_func(src))
server.app.run(host='0.0.0.0', port=4000, debug=True)
server.app.run(host='0.0.0.0', port=os.environ.get('PORT', 4000), debug=True)
6 changes: 5 additions & 1 deletion aip_site/server.py
Original file line number Diff line number Diff line change
@@ -89,8 +89,12 @@ def site_load_func(src: str):
def fx():
flask.g.site = Site.load(src)

# This is a workaround as we currently do not serve a static site.
if os.environ.get('FLASK_ENV', "development") == "production":
return

# This is the dev server, so plow over whatever the configuration
# says that the site URL is.
flask.g.site.config.setdefault('urls', {})
flask.g.site.config['urls']['site'] = 'http://localhost:4000'
flask.g.site.config['urls']['site'] = 'http://localhost:' + str(os.environ.get('PORT', 4000))
return fx
Binary file modified aip_site/support/assets/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions aip_site/support/assets/images/glue-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 0 additions & 184 deletions aip_site/support/assets/misc/ebnf-filtering.txt

This file was deleted.

5 changes: 5 additions & 0 deletions aip_site/support/scss/imports/header.scss
Original file line number Diff line number Diff line change
@@ -69,3 +69,8 @@ body .glue-header.glue-header--single .glue-header__bar {
}
}
}

.glue-header__logo-container {
height: 36px;
width: 75px;
}
2 changes: 1 addition & 1 deletion aip_site/support/templates/includes/breadcrumb.html.j2
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
<ol class="glue-breadcrumbs__list aip-breadcrumbs">
<li class="glue-breadcrumbs__item" aria-level="1">
<a class="glue-breadcrumbs__link" href="{{ site.relative_uri }}/">
API Improvement Proposals
Architecture Improvement Proposals
</a>
</li>
{% if aip is defined %}
8 changes: 4 additions & 4 deletions aip_site/support/templates/includes/header.html.j2
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
<div class="glue-header__container">
<div class="glue-header__lock-up">
<div class="glue-header__logo">
<a class="glue-header__logo-link" href="{{ site.relative_uri }}/" title="Google">
<a class="glue-header__logo-link" href="{{ site.relative_uri }}/" title="Qarik">
<div class="glue-header__logo-container">
<svg role="img" aria-hidden="true" class="glue-header__logo-svg">
<use xlink:href="{{ site.relative_uri }}/assets/images/glue-icons.svg#google-color-logo"></use>
<use xlink:href="{{ site.relative_uri }}/assets/images/glue-icons.svg#qarik-color-logo"></use>
</svg>
</div>
<p class="glue-header__logo--product">AIPs</p>
@@ -81,10 +81,10 @@
</div>
</div>
<div class="glue-header__logo">
<a class="glue-header__logo-link" href="{{ site.relative_uri }}/" title="Google">
<a class="glue-header__logo-link" href="{{ site.relative_uri }}/" title="Qarik">
<div class="glue-header__logo-container">
<svg role="img" aria-hidden="true" class="glue-header__logo-svg">
<use xlink:href="{{ site.relative_uri }}/assets/images/glue-icons.svg#google-color-logo"></use>
<use xlink:href="{{ site.relative_uri }}/assets/images/glue-icons.svg#qarik-color-logo"></use>
</svg>
</div>
<p class="glue-header__logo--product">AIPs</p>
11 changes: 5 additions & 6 deletions aip_site/support/templates/index.html.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'layouts/base.html.j2' %}

{% block title %}API Improvement Proposals{% endblock %}
{% block title %}Architecture Improvement Proposals{% endblock %}

{% block css %}
<link rel="stylesheet" type="text/css" media="screen" href="{{ site.relative_uri }}/assets/css/hero.css?v={{ site.revision }}">
@@ -10,10 +10,10 @@
<main role="main" class="aip-hero" id="page-content">
<div class="aip-hero-banner">
<div class="aip-hero-title">
API Improvement Proposals
Architecture Improvement Proposals
</div>
<div class="aip-hero-subtitle">
Focused design documents for flexible API development.
Focused design documents for flexible architecture proposals.
</div>
<div class="aip-buttons">
{% for button in site.config.hero.buttons -%}
@@ -27,9 +27,8 @@
<div class="aip-landing-content">
<h1>Welcome</h1>
<p>
AIPs are design documents that summarize Google's API design
decisions. They also provide a framework and system for others to
document their own API design rules and practices.
AIPs are design documents that summarize Qarik's architectural design
proposals.
</p>
</div>

50 changes: 50 additions & 0 deletions builder.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load("@bazel_skylib//lib:paths.bzl", "paths")

def _aip_site_build_impl(ctx):
site = ctx.actions.declare_directory(ctx.label.name)

workdir = ctx.actions.declare_directory("_" + ctx.label.name)
script = ctx.actions.declare_file(ctx.label.name + ".sh")

cmds = [
"mkdir -p $(dirname {dest}); cp -L {src} {dest}".format(
dirname = workdir.path + "/" + f.dirname,
src = f.path,
dest = workdir.path + "/" + f.short_path,
) for f in ctx.files.srcs
]

ctx.actions.write(
output = script,
content = "\n".join(["#!/bin/sh"] + cmds) + "\n",
is_executable = True,
)

ctx.actions.run(
executable = script,
inputs = [script] + ctx.files.srcs,
outputs = [workdir],
)

# Action to call the script.
ctx.actions.run(
inputs = [workdir],
outputs = [site],
arguments = ["publish", workdir.path + "/" + paths.dirname(ctx.build_file_path), site.path],
progress_message = "Generating AIP static site with generator",
executable = ctx.executable.generator,
)

return [DefaultInfo(files = depset([site]))]

aip_site_build = rule(
implementation = _aip_site_build_impl,
attrs = {
"srcs": attr.label_list(allow_files = True),
"generator": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
),
},
)
1 change: 1 addition & 0 deletions internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(glob(["**"]))
9 changes: 9 additions & 0 deletions internal/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from aip_site import cli

import sys

if __name__ == '__main__':
if sys.argv[1] == "serve":
cli.serve([sys.argv[2]])
elif sys.argv[1] == "publish":
cli.publish([sys.argv[2], sys.argv[3]])
16 changes: 16 additions & 0 deletions internal/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
click==8.1.3
flask==2.1.2
itsdangerous==2.1.2
jinja2==3.1.2
markdown==3.3.7
markupsafe==2.1.1
pygments==2.12.0
pymdown-extensions==9.4
pyscss==1.4.0
pyyaml==6.0
six==1.16.0
types-Markdown==3.3.21
types-PyYAML==6.0.7
werkzeug==2.1.2
importlib-metadata==5.0.0
zipp==3.10.0
20 changes: 20 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_aip_repositories():
maybe(
http_archive,
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
)
maybe(
http_archive,
name = "rules_python",
sha256 = "8c8fe44ef0a9afc256d1e75ad5f448bb59b81aba149b8958f02f7b3a98f5d9b4",
strip_prefix = "rules_python-0.13.0",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.13.0.tar.gz",
)
53 changes: 53 additions & 0 deletions requirements.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Starlark representation of locked requirements.
@generated by rules_python pip_parse repository rule
from //internal:requirements.txt
"""

load("@python39//:defs.bzl", "interpreter")
load("@rules_python//python/pip_install:pip_repository.bzl", "whl_library")

all_requirements = ["@pip_click//:pkg", "@pip_flask//:pkg", "@pip_itsdangerous//:pkg", "@pip_jinja2//:pkg", "@pip_markdown//:pkg", "@pip_markupsafe//:pkg", "@pip_pygments//:pkg", "@pip_pymdown_extensions//:pkg", "@pip_pyscss//:pkg", "@pip_pyyaml//:pkg", "@pip_six//:pkg", "@pip_types_markdown//:pkg", "@pip_types_pyyaml//:pkg", "@pip_werkzeug//:pkg", "@pip_importlib_metadata//:pkg", "@pip_zipp//:pkg"]

all_whl_requirements = ["@pip_click//:whl", "@pip_flask//:whl", "@pip_itsdangerous//:whl", "@pip_jinja2//:whl", "@pip_markdown//:whl", "@pip_markupsafe//:whl", "@pip_pygments//:whl", "@pip_pymdown_extensions//:whl", "@pip_pyscss//:whl", "@pip_pyyaml//:whl", "@pip_six//:whl", "@pip_types_markdown//:whl", "@pip_types_pyyaml//:whl", "@pip_werkzeug//:whl", "@pip_importlib_metadata//:whl", "@pip_zipp//:whl"]

_packages = [("pip_click", "click==8.1.3"), ("pip_flask", "flask==2.1.2"), ("pip_itsdangerous", "itsdangerous==2.1.2"), ("pip_jinja2", "jinja2==3.1.2"), ("pip_markdown", "markdown==3.3.7"), ("pip_markupsafe", "markupsafe==2.1.1"), ("pip_pygments", "pygments==2.12.0"), ("pip_pymdown_extensions", "pymdown-extensions==9.4"), ("pip_pyscss", "pyscss==1.4.0"), ("pip_pyyaml", "pyyaml==6.0"), ("pip_six", "six==1.16.0"), ("pip_types_markdown", "types-Markdown==3.3.21"), ("pip_types_pyyaml", "types-PyYAML==6.0.7"), ("pip_werkzeug", "werkzeug==2.1.2"), ("pip_importlib_metadata", "importlib-metadata==5.0.0"), ("pip_zipp", "zipp==3.10.0")]
_config = {"download_only": False, "enable_implicit_namespace_pkgs": False, "environment": {}, "extra_pip_args": [], "isolated": True, "pip_data_exclude": [], "python_interpreter": "python3", "python_interpreter_target": interpreter, "quiet": True, "repo": "pip", "repo_prefix": "pip_", "timeout": 600}
_annotations = {}

def _clean_name(name):
return name.replace("-", "_").replace(".", "_").lower()

def requirement(name):
return "@pip_" + _clean_name(name) + "//:pkg"

def whl_requirement(name):
return "@pip_" + _clean_name(name) + "//:whl"

def data_requirement(name):
return "@pip_" + _clean_name(name) + "//:data"

def dist_info_requirement(name):
return "@pip_" + _clean_name(name) + "//:dist_info"

def entry_point(pkg, script = None):
if not script:
script = pkg
return "@pip_" + _clean_name(pkg) + "//:rules_python_wheel_entry_point_" + script

def _get_annotation(requirement):
# This expects to parse `setuptools==58.2.0 --hash=sha256:2551203ae6955b9876741a26ab3e767bb3242dafe86a32a749ea0d78b6792f11`
# down wo `setuptools`.
name = requirement.split(" ")[0].split("=")[0]
return _annotations.get(name)

def install_deps(**whl_library_kwargs):
whl_config = dict(_config)
whl_config.update(whl_library_kwargs)
for name, requirement in _packages:
whl_library(
name = name,
requirement = requirement,
annotation = _get_annotation(requirement),
**whl_config
)