Development¶
Technology¶
Atramhasis is a python webapplication that is being developed within the pyramid framework. Other major technologies used are sqlalchemy as the ORM and Jinja2 as the templating framework.
Client side the main technologies being used are Zurb Foundation and Dojo toolkit.
While Atramhasis is an editor for creating and editing SKOS vocabularies, it uses other libraries that are more geared towards using a vocabulary in an application.
- skosprovider: This library defines a
VocabularyProvider
. This is an abstraction of usefull functionalities an application integrating SKOS needs. Different libraries can implement this interface for different datasources. This allows decoupling the interface from the concrete implementation. Out of the box this comes with a simpleDictionaryProvider
that serves a vocabulary based on a simple pythondict
as datasource. - skosprovider_sqlalchemy: An implementation of the
VocabularyProvider
interface with a SQLAlchemy backend. This allows using a RDBMS for reading, but also writing, SKOS concepts. - skosprovider_rdf: An implemenation of the
VocabularyProvider
interface with an RDF backend. Atramhasis uses this for exporting ConceptSchemes to RDF. It can also be used to get an existing SKOS vocabulary defined in RDF into Atramhasis. - pyramid_skosprovider: A library that integrates pyramid and skosprovider.
This libraries creates a
skosprovider.registry.Registry
and makes it accessible through thepyramid.request.Request
. Is also exposes a set of readonly REST services on the registered providers. - skosprovider_getty:
An implemenation of the
VocabularyProvider
against the Linked Open Data vocabularies published by the Getty Research Institute at http://vocab.getty.edu such as the Art and Architecture Thesaurus (AAT) and the Thesaurus of Geographic Names (TGN). - skosprovider_heritagedata:
An implementation of the
VocabularyProvider
against the vocabularies published by EH, RCAHMS and RCAHMW at heritagedata.org.
Atramhasis can easily be set up with a Linked Data Fragments (LDF) server. This server allows posing simple triple pattern queries of your dataset. Combined with a Linked Data Fragments client, similar functionalities to a traditional SPARQL endpoint can be achieved. Atramhasis facilitates the setup of a Linked Data Fragments server by generating a suitable config file for the Javascript server. This server can use different backends. Out of the box, Atramhasis generates Turtle files that can be used by the LDF server. It’s also possible to configre Atramhasis with a link to the rdf2hdt command (requires a separate installation). In this case, everytime the conceptschemes are dumped to RDF, the dump files are also written in HDT format.
General installation¶
We recommend installing Atramhasis in a virtual environment.
$ mkvirtualenv atramhasis_dev
To install a fully working development environment a pip requirements-dev.txt file is provided. By passing this file to pip install -r all requirements for Atramhasis and development of the software (Sphinx, py.test, tox) will be installed.
The following step will help you get the python development environment up and running. If also need to work on the javascript admin backend, please refer to the admin module documentation.
# Install dependencies
$ pip install -r requirements-dev.txt
# create or update database
$ alembic upgrade head
# insert sample data
$ initialize_atramhasis_db development.ini
# generate first RDF download
$ dump_rdf development.ini
# compile the Message Catalog Files
$ python setup.py compile_catalog
Once you’ve executed these steps, you can run a development server. This uses the standard pyramid server (Waitress) and should not be used as-is in a production environment.
# run a local development server
$ pserve --reload development.ini
Admin development¶
To work on the admin part, you’ll need npm and bower 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.
# install npm, bower and grunt-cli
$ sudo apt-get install nodejs
$ sudo apt-get install npm
$ sudo npm install -g bower grunt-cli
# install js dependencies using bower
$ cd atramhasis/static/admin
$ bower install
# install dojo build tools
$ npm install
These commands will install a couple of js libraries that Atramhasis uses in
/atramhasis/static/admin/src
and a set of tools to be able to generate
js builds. Builds are carried out through a simple grunt file:
# Build a dojo distribution
$ cd atramhasis/static/admin
$ grunt -v build
This will create a build a place the resulting files in
atramhasis/static/admin/dist
. The web application can be told to use
this build by setting dojo.mode in development.ini
to dist.
Frontend development¶
When updating the frontend templates, you might want to add extra translations. This can be done by placing {% trans %} tags in the templates
<h2>{% trans %}welcome_to{% endtrans %}</h2>
To update the message catalogs, do as follows:
$ 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
Update the catalogs accordingly and run:
$ python setup.py compile_catalog
You might also want to add a new translation. Suppose you want to add a German translation.
$ python setup.py init_catalog -l de -i atramhasis/locale/atramhasis.pot -o atramhasis/locale/de/LC_MESSAGES/atramhasis.po
Edit atramhasis/locale/do/LC_MESSAGES/atramhasis.po
and add the necessary
translations. Just as with updating the catalogs, you need to recompile them.
$ python setup.py compile_catalog
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
development.ini
(or similar file). Look for the line that says
available_languages and add your locale identifier.
available_languages = en nl fr de
After restarting your server you will now have the option of switching to German.
Running a Linked Data Fragments server¶
If you want to add a Linked Data Fragments server, Atramhasis makes it easy for you. First you need to decide if you want to run the server with HDT files. If not, you can always use raw Turtle files, but be aware that the HDT files offer much better performance.
If you want to use HDT files, please install hdt-cpp. Be aware that
you might have to download the source files and compile them yourself. Once
you have done so, add the rdf2hdt command to your development.ini file.
Supposing you installed it in /opt/hdt-cpp/hdt-lib/tools/rdf2hdt
:
# Location of rdf2hdt executable
atramhasis.rdf2hdt = /opt/hdt-cpp/hdt-lib/tools/rdf2hdt
Now, whenever Atramhasis creates rdf dumps it will also create HDT files. If you do not have rdf2hdt installed, you will still have Turtle datadumps that can be used by the LDF-server.
$ dump_rdf development.ini
Now you’re ready to generate the configuration for the LDF server. Out of the
box this file will be generated in the same directory your
development.ini
is located in, but you can override this in your ini
file by setting atramhasis.ldf.config_location or you can pass this on the
command line
# Generate config
$ generate_ldf_config development.ini
# Generate config and override config_location
$ generate_ldf_config development.ini -l /opt/my/ldf/server
Now you’re ready to run your LDF server. First we need to install it. It requires Node.js 4.0 or higher and should run on OSX and Linux. Please refer to the LDF server documentation for troubleshooting.
# Install ldf-server
$ [sudo] npm install -g ldf-server
# Run ldf-server
$ ldf-server ldf_server_config.json
Now you have an LDF server running at http://localhost:3000. Browse there and have fun!
When deploying Atramhasis with an LDF server in production, we recommend runnig both behind eg. nginx. In case you want to do this, you might run Atramhasis on port 6543 and LDF server on port 3000, but serve both through nginx. You can easily do this by setting the atramhasis.ldf.baseurl in your ini file. Suppose you want to server both on the host demo.atramhasis.org with Atramhasis as the root of your domain and the LDF server at /ldf. In this case, set atramhasis.ldf.baseurl to http://demo.atramhasis.org/ldf.
Contributing¶
Atramhasis is being developed as open source software by the Flanders Heritage Agency. All development is done on the agency’s Github page for Atramhasis.
Since we place a lot of importance of code quality, we expect to have a good amount of code coverage present and run frequent unit tests. All commits and pull requests will be tested with Travis-ci. Code coverage is being monitored with Coveralls.
Locally you can run unit tests by using pytest or tox. Running pytest manually is good for running a distinct set of unit tests. For a full test run, tox is preferred since this can run the unit tests against multiple versions of python.
# Run unit tests for all environments
$ tox
# No coverage
$ py.test
# Coverage
$ py.test --cov atramhasis --cov-report term-missing
# Only run a subset of the tests
$ py.test atramhasis/tests/test_views.py
Every pull request will be run through Travis-ci. When providing a pull request, please run the unit tests first and make sure they all pass. Please provide new unit tests to maintain 100% coverage. If you send us a pull request and this build doesn’t function, please correct the issue at hand or let us know why it’s not working.
Distribution¶
For building a distribution use the prepare command before the distribution command. This will update the requirement files in the scaffolds.
$ python setup.py prepare sdist