Skip to content

Commit

Permalink
Merge pull request #877 from OnroerendErfgoed/feature/876_cookiecutters
Browse files Browse the repository at this point in the history
Re-introduce the cookiecutters.
  • Loading branch information
goessebr authored Jul 2, 2024
2 parents 86ca052 + c62da15 commit 4892417
Show file tree
Hide file tree
Showing 23 changed files with 679 additions and 47 deletions.
11 changes: 4 additions & 7 deletions atramhasis/static/package-lock.json

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

5 changes: 5 additions & 0 deletions cookiecutters/demo/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root_folder": "atramhasis_demo",
"python_package": "atramhasis_demo",
"package_logger": "demo_logger"
}
4 changes: 4 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.0
---

- Initial version
2 changes: 2 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.txt *.ini *.cfg *.rst
recursive-include {{cookiecutter.python_package}} *.ico *.png *.css *.gif *.jpg *.pt *.txt *.jinja2 *.js *.html *.xml
3 changes: 3 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{cookiecutter.python_package}} README

This is an Atramhasis demo application
60 changes: 60 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = atramhasis:alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

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

ini_location = %(here)s/development.ini

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

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

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
129 changes: 129 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/development.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:{{cookiecutter.python_package}}

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid_tm
jinja2.directories =
atramhasis:templates
{{cookiecutter.python_package}}:templates
jinja2.extensions =
jinja2.ext.do
jinja2.filters =
label_sort = atramhasis.utils.label_sort
available_languages = en nl fr
sqlalchemy.url = sqlite:///%(here)s/{{cookiecutter.python_package}}.sqlite

atramhasis.session_factory.secret = test123

skosprovider.skosregistry_location = request
skosprovider.skosregistry_factory = {{cookiecutter.python_package}}.skos.create_registry

jinja2.i18n.domain = atramhasis

# Run dojo from source (src) or distribution (dist)
# If unspecified, defaults to src.
dojo.mode = dist

# cache
cache.tree.backend = dogpile.cache.memory
cache.tree.arguments.cache_size = 5000
cache.tree.expiration_time = 7000

cache.list.backend = dogpile.cache.memory
cache.list.arguments.cache_size = 5000
cache.list.expiration_time = 7000

# Filesystem location to dump exports
atramhasis.dump_location = %(here)s/datadumps

# Location of rdf2hdt executable
# atramhasis.rdf2hdt = /link/to/rdf2hdt

# Assume an LDF server is present?
# atramhasis.ldf.enabled = True

# Location of the config file for the LDF server
# atramhasis.ldf.config_location = %(here)s

# External url of the LDF server
# atramhasis.ldf.baseurl = http://demo.atramhasis.org/ldf

# Protocol the LDF server is operating under.
# See the LDF docs for more info
# atramhasis.ldf.protocol = http

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


layout.focus_conceptschemes =
HERITAGETYPE
PERIOD
GEOGRAPHY
MATERIALS

###
# wsgi server configuration
###

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

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

[loggers]
keys = root, atramhasis, sqlalchemy, {{cookiecutter.package_logger}}

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_atramhasis]
level = DEBUG
handlers =
qualname = atramhasis

[logger_sqlalchemy]
level = INFO
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_{{cookiecutter.package_logger}}]
level = DEBUG
handlers =
qualname = {{cookiecutter.python_package}}

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

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
32 changes: 32 additions & 0 deletions cookiecutters/demo/{{cookiecutter.root_folder}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = ["hatchling", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"

[project]
name = "{{ cookiecutter.python_package }}"
description = "My atramhasis setup"
version = "0.0.1"

dependencies = [
"atramhasis",
"pyramid",
"SQLAlchemy",
"skosprovider",
"skosprovider_getty",
]

[project.optional-dependencies]
dev = [
"waitress",
"pyramid_debugtoolbar",
]

[project.entry-points."paste.app_factory"]
main = "{{ cookiecutter.python_package }}:main"

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/x-rst"
fragments = [
{ path = "README.rst" },
{ path = "CHANGES.rst" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os

from atramhasis.data.models import Base
from pyramid.config import Configurator
from pyramid.session import SignedCookieSessionFactory
from pyramid.settings import aslist
from sqlalchemy import engine_from_config


def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""

# Set up sqlalchemy
engine = engine_from_config(settings, "sqlalchemy.")
Base.metadata.bind = engine

# update settings
settings["layout.focus_conceptschemes"] = aslist(
settings["layout.focus_conceptschemes"], flatten=False
)

# set up dump location
dump_location = settings["atramhasis.dump_location"]
if not os.path.exists(dump_location):
os.makedirs(dump_location)

with Configurator(settings=settings) as config:
# set default session factory
atramhasis_session_factory = SignedCookieSessionFactory(
settings["atramhasis.session_factory.secret"]
)
config.set_session_factory(atramhasis_session_factory)

# Set up atramhasis
config.include("atramhasis")
# Set up atramhasis db
config.include("atramhasis:data.db")

config.scan()
return config.make_wsgi_app()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from atramhasis.protected_resources import ProtectedResourceEvent
from atramhasis.protected_resources import ProtectedResourceException
from pyramid.events import subscriber


@subscriber(ProtectedResourceEvent)
def sample_impl(event):
if event.uri.endswith("2"):
referenced_in = ["urn:someobject", "http://test.test.org/object/2"]
raise ProtectedResourceException(
"resource {0} is still in use, preventing operation".format(event.uri),
referenced_in,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging

import requests
from atramhasis import skos
from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter
from skosprovider.registry import Registry
from skosprovider_getty.providers import AATProvider
from skosprovider_getty.providers import TGNProvider

log = logging.getLogger(__name__)
LICENSES = [
'https://creativecommons.org/licenses/by/4.0/',
'http://data.vlaanderen.be/doc/licentie/modellicentie-gratis-hergebruik/v1.0'
]


def create_registry(request):
try:
registry = Registry(instance_scope='threaded_thread')

getty_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1))

aat = AATProvider(
{'id': 'AAT', 'subject': ['external']},
session=getty_session
)

tgn = TGNProvider(
{'id': 'TGN', 'subject': ['external']},
session=getty_session
)

registry.register_provider(aat)
registry.register_provider(tgn)
skos.register_providers_from_db(registry, request.db)

return registry
except AttributeError:
log.exception("Attribute error during creation of Registry.")
raise
5 changes: 5 additions & 0 deletions cookiecutters/scaffold/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"root_folder": "atramhasis_scaffold",
"python_package": "atramhasis_scaffold",
"package_logger": "atramhasis_scaffold_logger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.0
---

- Initial version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{cookiecutter.python_package}} README

this is just a scaffold
Loading

0 comments on commit 4892417

Please sign in to comment.