Skip to content

Commit

Permalink
create a barebones pyramid app
Browse files Browse the repository at this point in the history
Includes

* pyramid application
* tailwind, htmx, hyperscript
* a very basic metal template and a single pseudo dashboard view

I'm switching from hatch to poetry as hatch doesn't have proper
locking for application-style packages.

Fixes ARAMAKI-10
  • Loading branch information
ctheune committed Feb 1, 2024
1 parent f7e00d8 commit 77c27c9
Show file tree
Hide file tree
Showing 20 changed files with 1,969 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
source = aramaki
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
*.egg
*.egg-info
*.pyc
*$py.class
*~
.coverage
coverage.xml
build/
dist/
.tox/
tailwind/node_modules/
nosetests.xml
env*/
tmp/
Data*.fs*
*.sublime-project
*.sublime-workspace
.*.sw?
.sw?
.DS_Store
coverage
test
*.sqlite
*.sqlite3
.web_cache/

# Devenv
.devenv*
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include *.txt *.ini *.cfg *.rst
recursive-include menage2 *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2
recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
85 changes: 85 additions & 0 deletions development.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
###
# app configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:aramaki

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = de
pyramid.includes =
pyramid_debugtoolbar

sqlalchemy.url = aramaki:///%(here)s/aramaki.sqlite

retry.attempts = 3

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1

[pshell]
setup = aramaki.pshell.setup

###
# wsgi server configuration
###

[alembic]
# path to migration scripts
script_location = src/aramaki/server/alembic
file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s
# file_template = %%(rev)s_%%(slug)s

[server:main]
use = egg:waitress#main
listen = 0.0.0.0:6543

###
# logging configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, aramaki, sqlalchemy, alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_aramaki]
level = DEBUG
handlers =
qualname = aramaki

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
29 changes: 13 additions & 16 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
pkgs.git
pkgs.postgresql_15
pkgs.python311Packages.psycopg2
pkgs.tailwindcss
];

enterShell = ''
pip install -e ./
'';

languages.python = {
enable = true;
package = pkgs.python311Full;
venv = {
poetry = {
enable = true;
quiet = true;
install = {
enable = true;
installRootPackage = true;
};
};
};

processes = {
aramaki-server-ui.exec = "aramaki-server ui";
aramaki-server-processing.exec = "aramaki-server processing";
aramaki-server-federation.exec = "aramaki-server federation";
aramaki-server-agent-manager.exec = "aramaki-server agent-manager";

aramaki-agent.exec = "aramaki-agent";
aramaki-server-ui.exec = "pserve development.ini";
#aramaki-server-processing.exec = "aramaki-server processing";
#aramaki-server-federation.exec = "aramaki-server federation";
#aramaki-server-agent-manager.exec = "aramaki-server agent-manager";
# aramaki-agent.exec = "aramaki-agent";

tailwindcss.exec = "cd tailwind; (while true; do sleep 10; done) | tailwindcss -i aramaki.css -o ../src/aramaki/server/ui/static/aramaki.css --minify --watch";
};

services.postgres = {
Expand All @@ -46,8 +47,4 @@
ruff.enable = true;
};

# https://devenv.sh/processes/
# processes.ping.exec = "ping example.com";

# See full reference at https://devenv.sh/reference/options/
}
1,443 changes: 1,443 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions production.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
###
# app configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:aramaki

pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
sqlalchemy.url = postgres:///%(here)s/aramaki.sqlite

retry.attempts = 3

[pshell]
setup = aramaki.pshell.setup

###
# wsgi server configuration
###

[alembic]
# path to migration scripts
script_location = src/aramaki/server/alembic
file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s
# file_template = %%(rev)s_%%(slug)s

[server:main]
use = egg:waitress#main
listen = *:6543
url_scheme = https

###
# logging configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, aramaki, sqlalchemy, alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console

[logger_aramaki]
level = WARN
handlers =
qualname = aramaki

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[logger_alembic]
level = WARN
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
66 changes: 44 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,62 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[project]
[tool.poetry]
name = "aramaki"
version = "0.0.1"
authors = [
{ name="Christian Theune", email="[email protected]" },
]
description = "A federated DevOps control-plane."
authors = ["Christian Theune <[email protected]>"]
license = "AGPLv3"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Operating System :: OS Independent",
]
dependencies = [
"psycopg2",
"websockets",
"pyramid"
]

[project.urls]
Homepage = "https://github.com/flyingcircusio/aramaki"
Issues = "https://github.com/flyingcircusio/aramaki/issues"

[project.scripts]
[tool.poetry.dependencies]
python = "^3.11"
pyramid = "^2.0.1"
pyramid-chameleon = "^0.3"
pyramid-debugtoolbar = "^4.10"
waitress = "^2.1.2"
plaster-pastedeploy = "^1.0.1"
alembic = "^1.11.1"
pyramid-retry = "^2.1.1"
pyramid-tm = "^2.5"
sqlalchemy = "^2.0.19"
transaction = "^3.1.0"
zope-sqlalchemy = "^3.0"
babel = "^2.12.1"
pytz = "^2023.3"
# peppercorn = "^0.6"
peppercorn = { git = "https://github.com/ctheune/peppercorn.git", branch = "htmx-workaround-1686-wrong-form-dataset-construction" }
rtmapi = "^0.7.2"
# implicit dependency that rtmapi did not specify!?!
httplib2 = "^0.22.0"
psycopg2-binary = "^2.9.9"
cachecontrol = "^0.13.1"
arrow = "^1.3.0"
filelock = "^3.13.1"
websockets = "^12"

[tool.poetry.group.dev.dependencies]
webtest = "^3.0.0"
pytest = "^7.4.0"
pytest-cov = "^4.1.0"

[tool.poetry.plugins."paste.app_factory"]
main = "aramaki.server.ui.main:main"

[tool.poetry.plugins."console_scripts"]
aramaki-initialize-db = "aramaki.scripts.initialize_db:main"
aramaki-server = "aramaki.server.main:main"
aramaki-agent = "aramaki.agent.main:main"

[tool.hatch.build.targets.wheel]
packages = ["src/aramaki"]

[project.urls]
Homepage = "https://github.com/flyingcircusio/aramaki"
Issues = "https://github.com/flyingcircusio/aramaki/issues"

[tool.black]
line-length = 79

25 changes: 14 additions & 11 deletions src/aramaki/server/ui/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from wsgiref.simple_server import make_server
import logging

from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
return Response("Hello World!")
def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""

logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

def main():
with Configurator() as config:
config.add_route("hello", "/")
config.add_view(hello_world, route_name="hello")
app = config.make_wsgi_app()
server = make_server("0.0.0.0", 6543, app)
server.serve_forever()
with Configurator(settings=settings) as config:
config.include("pyramid_chameleon")
config.include(".routes")
config.scan()

return config.make_wsgi_app()
12 changes: 12 additions & 0 deletions src/aramaki/server/ui/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import time

from pyramid.static import QueryStringConstantCacheBuster


def includeme(config):
config.add_static_view("static", "static", cache_max_age=3600)
config.add_cache_buster(
"static", QueryStringConstantCacheBuster(str(int(time.time())))
)

config.add_route("dashboard", "/")
1 change: 1 addition & 0 deletions src/aramaki/server/ui/static/aramaki.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/aramaki/server/ui/static/htmx.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/aramaki/server/ui/static/hyperscript.js

Large diffs are not rendered by default.

Loading

0 comments on commit 77c27c9

Please sign in to comment.