Skip to content

Commit da34873

Browse files
authored
Cleanup (#40)
* Update dependencies and fix conflicts with ETOS Library * Fix pylint, pydocstyle and black * Fix tests * Add github actions * Fix hadolint errors * Fix review comments and update etos library version
1 parent 89fa890 commit da34873

File tree

16 files changed

+183
-58
lines changed

16 files changed

+183
-58
lines changed

.github/workflows/main.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events
7+
on: [push, pull_request]
8+
9+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
10+
jobs:
11+
run-tox:
12+
# The type of runner that the job will run on
13+
runs-on: ubuntu-latest
14+
15+
# Steps represent a sequence of tasks that will be executed as part of the job
16+
steps:
17+
# Checks-out your repository under , so your job can access it
18+
- uses: actions/checkout@v2
19+
20+
- name: Setup python
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: 3.9
24+
- name: Install Tox
25+
run: pip install tox
26+
- name: Upgrade setuptools
27+
run: pip install -U setuptools
28+
- name: Run Tox
29+
run: tox
30+
31+
run-hadolint:
32+
# The type of runner that the job will run on
33+
runs-on: ubuntu-latest
34+
35+
# Steps represent a sequence of tasks that will be executed as part of the job
36+
steps:
37+
# Checks-out your repository under , so your job can access it
38+
- uses: actions/checkout@v2
39+
40+
- name: Run hadolint for API
41+
uses: hadolint/hadolint-action@master
42+
with:
43+
dockerfile: Dockerfile
44+
45+
build-docker-images:
46+
# The type of runner that the job will run on
47+
runs-on: ubuntu-latest
48+
49+
# Steps represent a sequence of tasks that will be executed as part of the job
50+
steps:
51+
# Checks-out your repository under , so your job can access it
52+
- uses: actions/checkout@v2
53+
54+
- name: Build API image
55+
uses: docker/build-push-action@v2
56+
with:
57+
context: .
58+
file: ./Dockerfile

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __pycache__/*
1313
.*.swp
1414
*/.ipynb_checkpoints/*
1515
.DS_Store
16+
.tags
1617

1718
# Project files
1819
.ropeproject
@@ -48,3 +49,4 @@ MANIFEST
4849

4950
# Per-project virtualenvs
5051
.venv*/
52+
.python-version

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ WORKDIR /src
55
RUN python3 setup.py bdist_wheel
66

77
FROM python:3.9.0-slim-buster
8-
8+
ARG TZ
9+
ENV TZ=$TZ
910

1011
COPY --from=build /src/dist/*.whl /tmp
1112
# hadolint ignore=DL3013
13+
# hadolint ignore=DL3008
1214

13-
# Installing an older version of pip as we wait for a real release of gql.
14-
RUN apt-get update && apt-get install -y gcc libc-dev --no-install-recommends && pip install --no-cache-dir pip==20.1.1 && pip install --no-cache-dir /tmp/*.whl && apt-get purge -y --auto-remove gcc libc-dev
15+
RUN apt-get update && \
16+
apt-get install -y gcc libc-dev tzdata --no-install-recommends && \
17+
pip install --no-cache-dir /tmp/*.whl && \
18+
apt-get purge -y --auto-remove gcc libc-dev && \
19+
rm -rf /var/lib/apt/lists/*
1520

1621
RUN groupadd -r etos && useradd -r -m -s /bin/false -g etos etos
1722
USER etos

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
master_doc = "index"
9393

9494
# General information about the project.
95-
project = u"etos_api"
96-
copyright = u"2020, Axis Communications AB"
95+
project = "etos_api"
96+
copyright = "Axis Communications AB"
9797

9898
# The version info for the project you're documenting, acts as replacement for
9999
# |version| and |release|, also used in various other places throughout the
@@ -241,7 +241,7 @@
241241
# Grouping the document tree into LaTeX files. List of tuples
242242
# (source start file, target name, title, author, documentclass [howto/manual]).
243243
latex_documents = [
244-
("index", "user_guide.tex", u"etos_api Documentation", u"", "manual"),
244+
("index", "user_guide.tex", "etos_api Documentation", "", "manual"),
245245
]
246246

247247
# The name of an image file (relative to this directory) to place at the top of

requirements.txt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@
1111
# Add your pinned requirements so that they can be easily installed with:
1212
# pip install -r requirements.txt
1313
# Remember to also add them in setup.cfg but unpinned.
14-
# Example:
15-
# numpy==1.13.3
16-
# scipy==1.0
17-
#
18-
etos_lib==2.1.0
19-
pyscaffold==3.2.3
20-
uvicorn==0.12.2
21-
fastapi==0.61.1
22-
aiohttp[speedups]==3.6.2
2314

24-
# These are not compatible with etos library
25-
multidict==5.1.0
26-
gql==v3.0.0a3
27-
graphql-core<3.2,>=3.1
15+
etos_lib==3.2.1
16+
pyscaffold~=4.4
17+
uvicorn~=0.22
18+
fastapi~=0.96.0
19+
aiohttp[speedups]~=3.8
20+
gql[requests]~=3.4

setup.cfg

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ package_dir =
2424
# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD!
2525
setup_requires = pyscaffold>=3.2a0,<3.3a0
2626
install_requires =
27-
etos_lib==2.1.0
28-
pyscaffold==3.2.3
29-
uvicorn==0.12.2
30-
fastapi==0.61.1
31-
aiohttp[speedups]==3.6.2
32-
multidict==5.1.0
33-
gql==v3.0.0a3
34-
graphql-core<3.2,>=3.1
27+
etos_lib==3.2.1
28+
pyscaffold~=4.4
29+
uvicorn~=0.22
30+
fastapi~=0.96.0
31+
aiohttp[speedups]~=3.8
32+
gql[requests]~=3.4
3533

3634
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
3735
python_requires = >=3.4

src/etos_api/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
"""ETOS API module."""
1717
import os
1818
from importlib.metadata import version, PackageNotFoundError
19-
from etos_api.library.context_logging import ContextLogging
2019
from etos_lib.logging.logger import setup_logging
20+
from etos_api.library.context_logging import ContextLogging
21+
22+
# The API shall not send logs to RabbitMQ as it
23+
# is too early in the ETOS test run.
24+
os.environ["ETOS_ENABLE_SENDING_LOGS"] = "false"
2125

2226
try:
2327
VERSION = version("environment_provider")

src/etos_api/library/context_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""ETOS API context based logging."""
1717
import logging
1818
from contextvars import ContextVar
19-
from etos_lib.logging.logger import setup_logging, FORMAT_CONFIG
19+
from etos_lib.logging.logger import FORMAT_CONFIG
2020

2121

2222
class ContextLogging(logging.Logger):

src/etos_api/library/graphql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# limitations under the License.
1616
"""Graphql query handler."""
1717
import asyncio
18-
from gql import gql, AIOHTTPTransport, Client
18+
from gql import gql, Client
19+
from gql.transport.aiohttp import AIOHTTPTransport
1920

2021

2122
class GraphqlQueryHandler: # pylint:disable=too-few-public-methods

src/etos_api/library/validator.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
import logging
1818
from uuid import UUID
1919
from typing import Union, List
20-
from pydantic import BaseModel, validator, ValidationError, constr, conlist
20+
21+
# Pylint refrains from linting C extensions due to arbitrary code execution.
22+
from pydantic import BaseModel, constr, conlist # pylint:disable=no-name-in-module
23+
from pydantic import validator, ValidationError
2124
import requests
2225
from etos_api.library.docker import Docker
2326

27+
# pylint:disable=too-few-public-methods
28+
2429

2530
class Environment(BaseModel):
2631
"""ETOS suite definion 'ENVIRONMENT' constraint."""
@@ -119,10 +124,8 @@ def validate_constraints(
119124
for constraint in value:
120125
model = cls.__constraint_models.get(constraint.key)
121126
if model is None:
122-
raise TypeError(
123-
"Unknown key %r, valid keys: %r"
124-
% (constraint.key, tuple(cls.__constraint_models.keys()))
125-
)
127+
keys = tuple(cls.__constraint_models.keys())
128+
raise TypeError(f"Unknown key {constraint.key}, valid keys: {keys}")
126129
try:
127130
model(**constraint.dict())
128131
except ValidationError as exception:
@@ -131,12 +134,12 @@ def validate_constraints(
131134
more_than_one = [key for key, number in count.items() if number > 1]
132135
if more_than_one:
133136
raise ValueError(
134-
"Too many instances of keys %r. Only 1 allowed." % more_than_one
137+
f"Too many instances of keys {more_than_one}. Only 1 allowed."
135138
)
136139
missing = [key for key, number in count.items() if number == 0]
137140
if missing:
138141
raise ValueError(
139-
"Too few instances of keys %r. At least 1 required." % missing
142+
f"Too few instances of keys {missing}. At least 1 required."
140143
)
141144
return value
142145

@@ -149,7 +152,7 @@ class Suite(BaseModel):
149152
recipes: List[Recipe]
150153

151154

152-
class SuiteValidator: # pylint:disable=too-few-public-methods
155+
class SuiteValidator:
153156
"""Validate ETOS suite definitions to make sure they are executable."""
154157

155158
logger = logging.getLogger(__name__)
@@ -163,11 +166,11 @@ async def _download_suite(self, test_suite_url):
163166
:rtype: list
164167
"""
165168
try:
166-
suite = requests.get(test_suite_url)
169+
suite = requests.get(test_suite_url, timeout=60)
167170
suite.raise_for_status()
168171
except Exception as exception: # pylint:disable=broad-except
169172
raise AssertionError(
170-
"Unable to download suite from %r" % test_suite_url
173+
f"Unable to download suite from {test_suite_url}"
171174
) from exception
172175
return suite.json()
173176

0 commit comments

Comments
 (0)