Skip to content
Snippets Groups Projects
Commit 826d964b authored by Eva Bardou's avatar Eva Bardou :frog: Committed by Yoann Schneider
Browse files

Normalize cookiecutter parameters for the worker package and module names

parent b6443693
No related branches found
No related tags found
1 merge request!470Normalize cookiecutter parameters for the worker package and module names
Pipeline #147945 passed
......@@ -131,9 +131,9 @@ to get a basic structure for your worker.
Cookiecutter will ask you for several options:
`slug`
: A slug for the worker. This should use lowercase alphanumeric characters or
underscores to meet the code formatting requirements that the template
automatically enforces via [black].
: A slug for the worker. This should use lowercase alphanumeric characters,
underscores or hyphens to meet the code formatting requirements that the
template automatically enforces via [black].
`name`
: A name for the worker, purely used for display purposes.
......@@ -159,6 +159,16 @@ Cookiecutter will ask you for several options:
`email`
: Your e-mail address. This will be used to contact you if any administrative need arise
Cookiecutter will also automatically normalize your worker's `slug` in new parameters:
`__package`
: The name of the Python package for your worker, generated by normalizing the `slug`
with characters' lowering and replacing underscores with hyphens.
`__module`
: The name of the Python module for your worker, generated by normalizing the `slug`
with characters' lowering and replacing hyphens with underscores.
### Pushing to GitLab
This section guides you through pushing the newly created worker from your
......@@ -169,7 +179,7 @@ This section assumes you have Maintainer or Owner access to the GitLab project.
#### To push to GitLab
1. Enter the newly created directory, starting in `worker-` and ending with your
worker's slug.
worker's `slug`.
2. Add your GitLab project as a Git remote:
......
......@@ -115,6 +115,6 @@ in the browser's address bar when browsing an element on Arkindex.
1. Activate the Python environment: run `workon X` where `X` is the name of
your Python environment.
2. Run `worker-X`, where `X` is the slug of your worker, followed by
2. Run `worker-X`, where `X` is the `__package` name of your worker, followed by
`--element=Y` where `Y` is the ID of an element. You can repeat `--element`
as many times as you need to process multiple elements.
......@@ -68,10 +68,10 @@ package, a Docker build, with the best development practices:
TODO: For more information, see [Writing tests for your worker](tests).
-->
`worker_[slug]/__init__.py`
`worker_[__module]/__init__.py`
: Declares the folder as a Python package.
`worker_[slug]/worker.py`
`worker_[__module]/worker.py`
: The core part of the worker. This is where you can write code that processes
Arkindex elements.
......
......@@ -54,7 +54,7 @@ All attributes are optional unless explicitly specified.
: Mandatory. Name of the worker, for display purposes.
`slug`
: Mandatory. Slug of this worker. The slug must be unique across the repository and must only hold alphanumerical characters, underscores or dashes.
: Mandatory. Slug of this worker. The slug must be unique across the repository and must only hold alphanumerical characters, underscores or hyphens.
`type`
: Mandatory. Type of the worker, for display purposes only. Some common values
......
# Normalize the slug to generate __package and __module private variables
{{cookiecutter.update({"__package": cookiecutter.slug.lower().replace("_", "-")})}} # noqa: F821
{{cookiecutter.update({"__module": cookiecutter.slug.lower().replace("-", "_")})}} # noqa: F821
......@@ -7,7 +7,7 @@ ENV DEBIAN_FRONTEND=non-interactive
RUN apt-get update -q -y && apt-get install -q -y --no-install-recommends curl
# Install worker as a package
COPY worker_{{cookiecutter.slug}} worker_{{cookiecutter.slug}}
COPY worker_{{cookiecutter.__module}} worker_{{cookiecutter.__module}}
COPY requirements.txt setup.py pyproject.toml ./
RUN pip install . --no-cache-dir
......@@ -15,4 +15,4 @@ RUN pip install . --no-cache-dir
RUN curl https://assets.teklia.com/teklia_dev_ca.pem > /usr/local/share/ca-certificates/arkindex-dev.crt && update-ca-certificates
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt
CMD ["worker-{{ cookiecutter.slug }}"]
CMD ["worker-{{ cookiecutter.__package }}"]
# {{ cookiecutter.slug }}
# {{ cookiecutter.name }}
{{ cookiecutter.description }}
......
......@@ -3,7 +3,7 @@ requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "worker_{{ cookiecutter.slug }}"
name = "worker_{{ cookiecutter.__module }}"
version = "0.1.0"
description = "{{ cookiecutter.description }}"
dynamic = ["dependencies"]
......@@ -24,7 +24,7 @@ classifiers = [
]
[project.scripts]
worker-{{ cookiecutter.slug }} = "worker_{{ cookiecutter.slug }}.worker:main"
worker-{{ cookiecutter.__package }} = "worker_{{ cookiecutter.__module }}.worker:main"
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
......@@ -60,7 +60,7 @@ select = [
[tool.ruff.per-file-ignores]
# Ignore `pytest-composite-assertion` rules of `flake8-pytest-style` linter for non-test files
"worker_{{ cookiecutter.slug }}/**/*.py" = ["PT018"]
"worker_{{ cookiecutter.__module }}/**/*.py" = ["PT018"]
[tool.ruff.isort]
known-first-party = ["arkindex", "arkindex_worker"]
......
......@@ -7,6 +7,6 @@ def test_dummy():
def test_import():
"""Import our newly created module, through importlib to avoid parsing issues"""
worker = importlib.import_module("worker_{{ cookiecutter.slug }}.worker")
worker = importlib.import_module("worker_{{ cookiecutter.__module }}.worker")
assert hasattr(worker, "Demo")
assert hasattr(worker.Demo, "process_element")
[tox]
envlist = worker-{{ cookiecutter.slug }}
envlist = worker-{{ cookiecutter.__package }}
[testenv]
passenv = ARKINDEX_API_SCHEMA_URL
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment