- Metax is a metadata storage for Finnish research data
- How to get started with
fairdata-metax-service
- This repository uses Poetry for managing Python dependencies securely
- Poetry generates a very strict
requirements.txtfile - Poetry enables easy updates of minor security/bug patches from pip with
pyproject.toml-defined version constraints - The generated
requirements.txtfile is guaranteed to lock all dependencies and sub-dependencies - The Poetry file
poetry.lockstores hashes of all dependencies, if the integrity of the dependency-tree ever needs to be verified - Poetry documentation
- First, install pipx
pipxis a system-wide Python application installerpipxcreates a virtualenv for every package installed and automatically includes them in your workstation's path- It can also uninstall any package installed using pipx
- After installation, you will have poetry available system-wide
# With pipx installed, install Poetry
pipx install poetry
# Upgrade if needed (minimum 1.2.0+ required)
pipx upgrade poetry- Poetry creates and manages its virtual environments in a dedicated cache directory on your workstation
- Tested with pip version
21.1.2 - Tested with poetry version
1.8.0
# First, activate a poetry virtual environment
poetry shell
# ... then, install dependencies with poetry
poetry install# Create a .env file based on .env.template
cp .env.template .env- Define
<required>variables in the.envfile - Define other non-required values as needed
# In the repository root, run
python manage.py createsuperuser# In the repository root, run
python manage.py migrate
mkdir static
python manage.py collectstatic --no-inputIf you want to run a containerized version with PostgreSQL & Mecached, see: 🐋 Docker
- make sure both metaxes have a test catalog with same identifier
- in V3, loading test data creates two test catalogs
urn:nbn:fi:att:data-catalog-testfor non-harvested datasets andurn:nbn:fi:att:data-catalog-harvested-testfor harvested datasets- created with
python manage.py load_test_data
- create these also in V2
- you might also need to patch the V3 catalogs with correct permissions:
- in V3, loading test data creates two test catalogs
PATCH /v3/data-catalogs/urn:nbn:fi:att:data-catalog-harvested-test
{
"dataset_groups_create": [
"service"
],
"dataset_groups_admin": [
"service"
]
}PATCH /v3/data-catalogs/urn:nbn:fi:att:data-catalog-test
{
"dataset_groups_create": [
"fairdata_users"
]
}- create service user for V2 in V3
# in metax-service -repo
python manage.py create_api_user service_metax_v2 --groups metax_v2 service v2_migration- create token for the user
# in metax-service -repo
python manage.py drf_create_token service_metax_v2- If V2 is in a container and V3 is not, V2 cannot access V3 if it's running at
localhost:<port>, so start the V3 development server at0.0.0.0:<port>instead. This way, V3 is available to containers at host172.17.0.1:<port>python manage.py runserver 0.0.0.0:<port>- in this case, also add
172.17.0.1toALLOWED_HOSTSin V3 development settingssrc/metax_service/settings/environments/development.py
- add these settings to
fairdata-metax/docker-compose.yaml, under metax-web environment:
METAX_V3_HOST: <your local V3 host> # 172.17.0.1:<port>, if V2 is in a container and V3 is not
METAX_V3_TOKEN: <token of V2 service user>
METAX_V3_INTEGRATION_ENABLED: "true"- redeploy metax_dev stack
- set up local V3 environment with these settings in
.env:
METAX_V2_INTEGRATION_ENABLED=True
METAX_V2_HOST=<your local V2 host> # most likely https://metax.fd-dev.csc.fi
METAX_V2_USER=metax_service
METAX_V2_PASSWORD=test-metax_service- The section below lists common development operations
You can change the port number as needed
# Default development server
python manage.py runserver 8002
# Enhanced development server
python manage.py runserver_plus 8002
# Enhanced development server, enhanced interpreter
python manage.py runserver_plus --bpython 8002Set ENABLE_BACKGROUND_TASKS=true in .env.
Run development server and run the task processing
cluster in e.g. another terminal
python manage.py qcluster- When the development server is running, access the admin panel at
localhost:<port>/v3/admin - Use the credentials generated in the "Creating superuser" part of this readme.
# Show all available management commands
python manage.py --help
# Show all setup.py commands
python setup.py --help- Run pytest managed tests with
pytestcommand - You can run tox tests with
toxcommand.
# Run tests, stop on first failure, reuse test-database, run failed tests first, 2 workers
pytest -x --reuse-db -n 2 --ff- The mkdocs port can be defined freely
# Running development server:
mkdocs serve -a localhost:8005
# Building mkdocs for production
mkdocs build- Disabled by default
- Silk profiling can be turned on by setting
ENABLE_SILK_PROFILERenv-var to true - The profiler is only available when on
developmentDJANGO_ENV
# After setting ENABLE_SILK_PROFILER env-var to True, run:
python manage.py migrate
python manage.py collectstatic --no-input- After successful setup, the profiler is available at /v3/silk endpoint
- More information about Silk can be found from official docs
- The Django Debug Toolbar can slow down SQL-queries
- Switch it off by setting
ENABLE_DEBUG_TOOLBARenv-var to False
# Adding developer dependencies
poetry add -G dev <package>
# Adding application dependencies
poetry add <package>
# Updating all dependencies
poetry update
# Removing dependencies
poetry remove (-D) <package>
# Regenerating requirements.txt after modification of pyproject.toml
poetry export --without-hashes -o requirements.txt
poetry export --with dev --without-hashes -o dev-requirements.txt- Black formatter and isort are used for code formatting
# Ignore formatting commits by configuring git as follows
git config blame.ignoreRevsFile .git-blame-ignore-revssetup.cfgis the main configuration file due to still incomplete support ofpyproject.tomlin several development tools
- The database models are based on following specifications:
- https://joinup.ec.europa.eu/collection/semantic-interoperability-community-semic/solution/dcat-application-profile-data-portals-europe/release/210
- https://www.w3.org/TR/vocab-dcat-3/
- This project has been set up using PyScaffold 3.3.1
- For details and usage information on PyScaffold see https://pyscaffold.org/.