Skip to content
Snippets Groups Projects
Commit e51bc620 authored by Valentin Rigal's avatar Valentin Rigal Committed by Bastien Abadie
Browse files

Install the worker as a python package

parent df370aa3
No related branches found
No related tags found
1 merge request!16Install the worker as a python package
Pipeline #77923 passed
{
"slug": "demo",
"name": "My demo ML Worker",
"version": "0.1",
"worker_type": "classifier"
"name": "Demo",
"description": "Demo ML worker for Arkindex",
"worker_type": [
"classifier",
"recognizer",
"ner",
"dla",
"word-segmenter",
"paragraph-creator"
],
"author": "",
"email": ""
}
......@@ -3,7 +3,6 @@ envlist = arkindex_worker
skipsdist=True
[testenv]
setenv = PYTHONPATH = {toxinidir}
passenv = ARKINDEX_API_SCHEMA_URL
commands =
pytest
......@@ -11,3 +10,7 @@ commands =
deps =
-rrequirements.txt
-rtests-requirements.txt
[pytest]
testpaths =
tests
......@@ -8,4 +8,4 @@ line_length = 88
default_section=FIRSTPARTY
known_first_party =
known_third_party = arkindex_worker
known_third_party = arkindex_worker,setuptools
FROM python:3
WORKDIR /usr/share/teklia/worker_{{ cookiecutter.slug }}
COPY worker_{{cookiecutter.slug}} .
ADD requirements.txt .
WORKDIR /src
RUN pip install -r requirements.txt
# Install worker as a package
COPY worker_{{cookiecutter.slug}} worker_{{cookiecutter.slug}}
COPY requirements.txt setup.py VERSION ./
RUN pip install .
# Add archi local CA
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 ["python", "worker.py"]
CMD ["worker-{{ cookiecutter.slug }}"]
include requirements.txt
include VERSION
# {{ cookiecutter.slug }}
{{ cookiecutter.description }}
### Development
For development and tests purpose it may be useful to install the worker as a editable package with pip.
```shell
pip3 install -e .
```
### Linter
Code syntax is analyzed before submitting the code.\
To run the linter tools suite you may use pre-commit.
```shell
pip install pre-commit
pre-commit run -a
```
### Run tests
Tests are executed with tox using [pytest](https://pytest.org).
```shell
pip install tox
tox
```
To recreate tox virtual environment (e.g. a dependencies update), you may run `tox -r`
0.1.0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pathlib import Path
from setuptools import find_packages, setup
MODULE = "worker_{{cookiecutter.slug}}"
COMMAND = "worker-{{cookiecutter.slug}}"
def parse_requirements():
path = Path(__file__).parent.resolve() / "requirements.txt"
assert path.exists(), f"Missing requirements: {path}"
return list(map(str.strip, path.read_text().splitlines()))
setup(
name=MODULE,
version=open("VERSION").read(),
description="{{ cookiecutter.description }}",
author="{{ cookiecutter.author }}",
author_email="{{ cookiecutter.email }}",
install_requires=parse_requirements(),
entry_points={"console_scripts": [f"{COMMAND}={MODULE}.worker:main"]},
packages=find_packages(),
)
# -*- coding: utf-8 -*-
import importlib
def test_dummy():
assert True
def test_import():
"""Import our newly created module, through importlib to avoid parsing issues"""
worker = importlib.import_module("worker_{{ cookiecutter.slug }}.worker")
assert hasattr(worker, "Demo")
assert hasattr(worker.Demo, "process_element")
[tox]
envlist = worker-{{ cookiecutter.slug }}
skipsdist=True
[testenv]
passenv = ARKINDEX_API_SCHEMA_URL
......
......@@ -7,5 +7,9 @@ class Demo(ElementsWorker):
print("Demo processing element", element)
def main():
Demo(description="{{ cookiecutter.description }}").run()
if __name__ == "__main__":
Demo(description="{{ cookiecutter.name }}").run()
main()
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