Skip to content

Commit

Permalink
Build system change. (#865)
Browse files Browse the repository at this point in the history
* Build system change.

Issue #854

* Add docs

* Fix double quotes.

* more updates
  • Loading branch information
Wim-De-Clercq authored Jun 10, 2024
1 parent 5ef6160 commit 5ce07c1
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 157 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ before_install:
- pip install --upgrade pip
- pip install setuptools==59.6.0 #https://github.com/pypa/setuptools/issues/3293
install:
- pip install -r requirements-dev.txt
- python setup.py develop
- pip install -e .[dev]
script:
- py.test --cov atramhasis --cov-report term-missing tests
after_success:
Expand Down
25 changes: 23 additions & 2 deletions atramhasis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@
from atramhasis.renderers import json_renderer_verbose


DEFAULT_SETTINGS = {
"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",
"jinja2.extensions": "jinja2.ext.do",
"jinja2.filters": "label_sort = atramhasis.utils.label_sort",
"dojo.mode": "dist",
"layout.focus_conceptschemes": [],
"skosprovider.skosregistry_factory": "atramhasis.skos.create_registry",
"skosprovider.skosregistry_location": "request",
}


def includeme(config):
"""this function adds some configuration for the application"""
settings = config.registry.settings
for key, value in DEFAULT_SETTINGS.items():
if key not in settings:
settings[key] = value

config.include('pyramid_jinja2')
config.include('pyramid_tm')
config.add_static_view('static', 'static', cache_max_age=3600)
Expand All @@ -21,6 +42,8 @@ def includeme(config):
config.include('atramhasis.cache')
config.scan('pyramid_skosprovider')

config.add_translation_dirs('atramhasis:locale/')

config.scan()


Expand All @@ -45,8 +68,6 @@ def load_app(config, settings):

includeme(config)

config.add_translation_dirs('atramhasis:locale/')

config.include('atramhasis.data:db')

return config.make_wsgi_app()
17 changes: 17 additions & 0 deletions build_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import subprocess
from pathlib import Path

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class BuildHook(BuildHookInterface):
def initialize(self, version: str, build_data) -> None:
"""Build frontend when building the wheel."""
super().initialize(version, build_data)

root_dir = Path(__file__).parent
static = root_dir / "atramhasis" / "static"
static_admin = static / "admin"
subprocess.run(["npm", "install"], cwd=static)
subprocess.run(["npm", "install"], cwd=static_admin)
subprocess.run(["grunt", "-v", "build"], cwd=static_admin, check=True)
69 changes: 69 additions & 0 deletions docs/source/customisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,72 @@ through code in this file. Your final code should looks somewhat like this:
register_providers_from_db(registry, request.db)
return registry
Application settings
====================
These are settings you can use to change the atramhasis behaviour.
When a setting is marked with DEFAULT then writing the setting is optional.
When a setting is marked with REQUIRED then it is strongly advised to fill in the
setting. Skipping these may not prevent the application from starting, but some
functionality might fail to run properly.
.. code-block:: ini
[app:main]
use = egg:my_app
pyramid.default_locale_name = nl
# DEFAULT - If you wish to add your own values you should append to these values
jinja2.extensions =
jinja2.ext.do
# DEFAULT - If you wish to add your own values you should append to these values
jinja2.filters =
label_sort = atramhasis.utils.label_sort
available_languages = en nl it
# REQUIRED
sqlalchemy.url = sqlite:///test.db
# sqlalchemy.url = postgresql://postgres:postgres@localhost:5432/atramhasis_test
# DEFAULT
skosprovider.skosregistry_location = request
# DEFAULT
skosprovider.skosregistry_factory = tests.create_registry
# DEFAULT - cache which caches the data used for /conceptschemes/{scheme_id}/tree
cache.tree.backend = dogpile.cache.memory
cache.tree.arguments.cache_size = 5000
cache.tree.expiration_time = 7000
# DEFAULT - cache which caches the data used for /labeltypes and /notetypes
cache.list.backend = dogpile.cache.memory
cache.list.arguments.cache_size = 5000
cache.list.expiration_time = 7000
# REQUIRED - Filesystem location to dump exports
atramhasis.dump_location = path/to/folder
# REQUIRED - Assume an LDF server is present?
atramhasis.ldf.enabled = True
# External url of the LDF server
atramhasis.ldf.baseurl = http://demo.atramhasis.org/ldf
# DEFAULT empty list
layout.focus_conceptschemes =
HERITAGETYPE
PERIOD
GEOGRAPHY
MATERIALS
# DEFAULT - Run dojo from source (src) or distribution (dist)
dojo.mode = dist
# The Twitter @username the card should be attributed to.
twitter.site =
# Enter your tracking snippet
tracking_snippet =
35 changes: 24 additions & 11 deletions docs/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,24 @@ production environment.
Admin development
=================

To work on the admin part, you'll need `npm`_ installed. Consult
your operating system documentation on how to install these. The following
To work on the admin part, you'll need `npm`_, `grunt`_ and `java`_ installed.
Consult your operating system documentation on how to install these. The following
instructions will assume you're running a recent Debian based Linux distribution.

Confirmed known versions are as followed:

.. code-block:: bash
$ npm -v
8.19.4
$ node -v
v16.20.2
$ grunt -V
grunt-cli v1.4.3
.. code-block:: bash
# install npm and grunt-cli
Expand Down Expand Up @@ -158,33 +172,31 @@ To update the message catalogs, do as follows:

.. code-block:: bash
$ python setup.py extract_messages
$ python setup.py update_catalog -l fr -i atramhasis/locale/atramhasis.pot -o atramhasis/locale/fr/LC_MESSAGES/atramhasis.po
$ python setup.py update_catalog -l nl -i atramhasis/locale/atramhasis.pot -o atramhasis/locale/nl/LC_MESSAGES/atramhasis.po
$ python setup.py update_catalog -l en -i atramhasis/locale/atramhasis.pot -o atramhasis/locale/en/LC_MESSAGES/atramhasis.po
$ pybabel extract --add-comments 'TRANSLATORS:' --output-file 'atramhasis/locale/atramhasis.pot' --width 80 --mapping-file 'message-extraction.ini' atramhasis
$ pybabel update --input-file 'atramhasis/locale/atramhasis.pot' --output-dir 'atramhasis/locale' --previous true --domain atramhasis
Update the catalogs accordingly and run:

.. code-block:: bash
$ python setup.py compile_catalog
$ pybabel compile --directory 'atramhasis/locale' --domain atramhasis --statistics true
You might also want to add a new translation. Suppose you want to add a German
translation.

.. code-block:: bash
$ python setup.py init_catalog -l de -i atramhasis/locale/atramhasis.pot -o atramhasis/locale/de/LC_MESSAGES/atramhasis.po
$ pybabel init --locale de --input-file 'atramhasis/locale/atramhasis.pot' --output-dir atramhasis/locale --domain atramhasis
Edit :file:`atramhasis/locale/do/LC_MESSAGES/atramhasis.po` and add the necessary
Edit :file:`atramhasis/locale/de/LC_MESSAGES/atramhasis.po` and add the necessary
translations. Just as with updating the catalogs, you need to recompile them.

.. code-block:: bash
$ python setup.py compile_catalog
$ pybabel compile --directory 'atramhasis/locale' --domain atramhasis --statistics true
At this moment, Atramhasis will still only show the default languages in it's
language switcher. If you want to add you new language, you need to edit your
language switcher. If you want to add your new language, you need to edit your
:file:`development.ini` (or similar file). Look for the line that says
`available_languages` and add your locale identifier.

Expand Down Expand Up @@ -320,3 +332,4 @@ This will build the dojo code in the static folder.
.. _pyramid_skosprovider: http://pyramid-skosprovider.readthedocs.org
.. _skosprovider_getty: http://skosprovider-getty.readthedocs.org
.. _skosprovider_heritagedata: http://skosprovider-heritagedata.readthedocs.org
.. _java: https://www.java.com/en/download/manual.jsp
131 changes: 131 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
[build-system]
requires = ["hatchling", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"

[project]
version = "0.0.1"
name = "atramhasis"
dynamic = ["readme"]
authors = [
{ name = "Flanders Heritage Agency", email = "[email protected]" },
]
#license = "GPL-3.0-or-later"
description = "A web based editor for thesauri adhering to the SKOS specification."
requires-python = ">=3.9,<3.12"
keywords = ["web", "wsgi", "pyramid", "SKOS", "thesaurus", "vocabulary"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dependencies = [
"pyramid",
"pyramid_tm",
"SQLAlchemy<2.0.0,>=1.4.0",
"transaction",
"zope.sqlalchemy",
"skosprovider",
"skosprovider_sqlalchemy>=2.1.1",
"skosprovider_rdf",
"skosprovider_getty",
"pyramid_skosprovider",
"language_tags",
"jinja2 >= 3.0.0",
"markupsafe",
"pyramid_jinja2",
"alembic",
"babel",
"colander",
"requests",
"cachecontrol",
"dogpile.cache",
"pyramid_rewrite",
"python-dateutil",
"rdflib",
"bleach",
# Openapi stack
"pyramid_openapi3>=0.16.0,<0.17.0",
"openapi-core>=0.16.6,<0.17.0",
"openapi-schema-validator>=0.4.4,<0.5.0",
"openapi-spec-validator>=0.5.6,<0.6.0",
"jsonschema>=4.17.0,<5.0.0", # Does follow semantic versioning -- safe
]

[project.urls]
History = "https://github.com/OnroerendErfgoed/atramhasis/blob/master/CHANGES.rst"
Tracker = "https://github.com/OnroerendErfgoed/atramhasis/issues"
Source = "https://github.com/OnroerendErfgoed/atramhasis"
Documentation = "https://atramhasis.readthedocs.io/en/latest/"

[project.optional-dependencies]
dev = [
"pyramid-debugtoolbar==4.10",
"pytest==7.4.2",
"pytest-cov==4.1.0",
"coveralls==3.3.1",
"webtest==3.0.0",
"mock==5.1.0",
"testfixtures==7.2.2",
"Sphinx==6.2.1",
"sphinxcontrib-httpdomain==1.8.1",
"pygments==2.15.1",
"waitress==2.1.2",
"flake8==4.0.1",
"mccabe==0.6.1",
"pep8==1.7.1",
"pyflakes==2.4.0",
]

[project.entry-points."paste.app_factory"]
main = "atramhasis:main"

[project.scripts]
initialize_atramhasis_db = "atramhasis.scripts.initializedb:main"
import_file = "atramhasis.scripts.import_file:main"
dump_rdf = "atramhasis.scripts.dump_rdf:main"
generate_ldf_config = "atramhasis.scripts.generate_ldf_config:main"
sitemap_generator = "atramhasis.scripts.sitemap_generator:main"
delete_scheme = "atramhasis.scripts.delete_scheme:main"
migrate_sqlalchemy_providers = "atramhasis.scripts.migrate_sqlalchemy_providers:main"


##
# Build tool specific
##
[tool.hatch.build.targets.wheel]
# In the wheel we want to have atramhasis in the root as python module.
only-include = [
"/atramhasis",
"/fixtures",
]
# In the wheel we do not need the frontend sources. We provide the dist.
exclude = [
"/atramhasis/static/admin"
]
# these folders are (partially) in gitignore and would otherwise not be part of the builds
artifacts = [
"/atramhasis/static/admin/dist",
# including node_modules bloats the build but we need refactoring
"/atramhasis/static/admin/node_modules",
"/atramhasis/static/node_modules",
]

[tool.hatch.build.targets.wheel.hooks.custom]
path = "build_hook.py"


[tool.hatch.metadata]
# This allows us to use github links as dependencies
allow-direct-references = true

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/x-rst"
fragments = [
{ path = "README.rst" },
{ path = "CHANGES.rst" },
]
21 changes: 0 additions & 21 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit 5ce07c1

Please sign in to comment.