Skip to content
Snippets Groups Projects
Commit 4035b53e authored by Szymon Ciombor's avatar Szymon Ciombor
Browse files

updated for python3.6 and readied for Rancher

parent 85e78dd2
No related branches found
No related tags found
1 merge request!2Python 3.6 port, CI, ready for deployment on Rancher
Pipeline #953 failed
image: 'clarinpl/python:3.6'
cache:
paths:
- .tox
stages:
- check_style
- build
before_script:
- pip install tox==2.9.1
pep8:
stage: check_style
script:
- tox -v -e pep8
docstyle:
stage: check_style
script:
- tox -v -e docstyle
build_image:
stage: build
image: 'docker:18.09.7'
only:
- master
services:
- 'docker:18.09.7-dind'
before_script:
- ''
script:
- docker build -t clarinpl/mwe .
- echo $DOCKER_PASSWORD > pass.txt
- cat pass.txt | docker login --username $DOCKER_USERNAME --password-stdin
- rm pass.txt
- docker push clarinpl/mwe
FROM clarinpl/builder AS builder FROM clarinpl/python:3.6
FROM clarinpl/python:2.7
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
libxml++2.6-dev \ corpus2-python3.6 \
libloki-dev \ wccl-python3.6 \
libboost-all-dev \ corpus2mwe-python3.6
libicu-dev \
libffi-dev \
libssl-dev \
libxml2-utils
COPY --from=builder /install/corpus2 /
COPY --from=builder /install/wccl /
COPY --from=builder /install/corpus2mwe /
RUN ldconfig
WORKDIR /home/worker WORKDIR /home/worker
COPY requirements.txt . COPY requirements.txt .
COPY mwe_worker.py . COPY main.py .
RUN pip install -r requirements.txt COPY ./src ./src
CMD ["python", "mwe_worker.py"] RUN python3.6 -m pip install -r requirements.txt
CMD ["python", "main.py", "service"]
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
tool = mwe tool = mwe
root = /samba/requests/ root = /samba/requests/
rabbit_host = rabbit.clarin.ws rabbit_host = rabbitmq
rabbit_user = clarin rabbit_user = test
rabbit_password = clarin123 rabbit_password = test
queue_prefix =nlp_
[tool] [tool]
workers_number = 5 workers_number = 5
processed_lines = 1000
[logging] [logging]
port = 0 port = 9912
local_log_level = INFO local_log_level = INFO
[logging_levels] [logging_levels]
__main__ = INFO __main__ = INFO
wsd_worker = INFO
version: '3'
services:
mwe:
container_name: clarin_mwe
build: ./
working_dir: /home/worker
entrypoint:
- python2
- mwe_worker.py
volumes:
- /samba:/samba
- ./config.ini:/home/worker/config.ini
- ./mwe_worker.py:/home/worker/mwe_worker.py
restart: always
\ No newline at end of file
main.py 0 → 100644
"""Implementation of mwe service."""
import argparse
import nlp_ws
from src.worker import Worker
def get_args():
"""Gets command line arguments."""
parser = argparse.ArgumentParser(description="mwe implementation")
subparsers = parser.add_subparsers(dest="algorithm")
subparsers.required = True
subparsers.add_parser("service", help="Run as a service")
return parser.parse_args()
def main():
"""Runs the program."""
args = get_args()
generators = {
"service": lambda: nlp_ws.NLPService.main(Worker),
}
gen_fn = generators.get(args.algorithm, lambda: None)
gen_fn()
if __name__ == "__main__":
main()
corpus-ccl
nlp-ws nlp-ws
corpus-ccl
\ No newline at end of file
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging
import subprocess
import nlp_ws
from corpus_ccl import cclutils as ccl from corpus_ccl import cclutils as ccl
import corpus2mwe as mwe import corpus2mwe as mwe
import subprocess import nlp_ws
import logging
_log = logging.getLogger(__name__)
_log = logging.getLogger(__name__)
class MWEWorker(nlp_ws.NLPWorker):
class Worker(nlp_ws.NLPWorker):
@classmethod @classmethod
def static_init(cls, config): def static_init(cls, config):
_log.info("Static init") _log.info("Static init")
def init(self): def init(self):
_log.info("Worker started loading models %s", "AS") _log.info("Worker started loading models %s", "AS")
self.tagset = ccl.get_tagset('nkjp') self.tagset = ccl.get_tagset("nkjp")
self.reader = None self.reader = None
def process(self, inputFile, taskOptions, outputFile): def process(self, inputFile, taskOptions, outputFile):
...@@ -33,23 +31,24 @@ class MWEWorker(nlp_ws.NLPWorker): ...@@ -33,23 +31,24 @@ class MWEWorker(nlp_ws.NLPWorker):
mwe_doc = self.reader.read() mwe_doc = self.reader.read()
ccl.write_ccl(mwe_doc, str(outputFile)) ccl.write_ccl(mwe_doc, str(outputFile))
class _InvalidXMLInRequest(Exception): class _InvalidXMLInRequest(Exception):
pass pass
def _validate_xml(xmlfile): def _validate_xml(xmlfile):
""" """
This will do nothing if XML is valid and raise exception if it's not. This will do nothing if XML is valid and raise exception if it's not.
""" """
lint_call = subprocess.Popen( lint_call = subprocess.Popen(
('xmllint', '--nonet', '--noout', xmlfile), ("xmllint", "--nonet", "--noout", xmlfile), stderr=subprocess.PIPE,
stderr=subprocess.PIPE,
) )
xml_err = lint_call.communicate()[1] xml_err = lint_call.communicate()[1]
if lint_call.returncode != 0: if lint_call.returncode != 0:
raise _InvalidXMLInRequest("Wrong XML in input data") raise _InvalidXMLInRequest("Wrong XML in input data")
if __name__ == '__main__':
nlp_ws.NLPService.main(MWEWorker)
if __name__ == "__main__":
nlp_ws.NLPService.main(Worker)
tox.ini 0 → 100644
[tox]
envlist = pep8,docstyle
skipsdist = True
[testenv:pep8]
deps =
flake8
basepython = python3
commands =
flake8 {posargs}
[testenv:docstyle]
deps =
pydocstyle
basepython = python3
commands =
pydocstyle --verbose {posargs}
[flake8]
# W503 line break before binary operator
# W504 skipped because it is overeager and unnecessary
ignore = W503,W504
show-source = True
exclude = .git,.venv,.tox,dist,doc,*egg,build,venv
import-order-style = pep8
max-line-length = 80
[pydocstyle]
# D104 Missing docstring in public package
# D203 1 blank line required before class docstring
# D213 Multi-line docstring summary should start at the second line
# D214 Section is over-indented
# D215 Section underline is over-indented
# D401 First line should be in imperative mood; try rephrasing
# D405 Section name should be properly capitalized
# D406 Section name should end with a newline
# D407 Missing dashed underline after section
# D408 Section underline should be in the line following the section’s name
# D409 Section underline should match the length of its name
# D410 Missing blank line after section
# D411 Missing blank line before section
ignore = D104,D203,D213,D214,D215,D401,D405,D406,D407,D408,D409,D410,D411
match-dir = ^(?!\.tox|venv).*
match = ^(?!setup).*\.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment