File tree Expand file tree Collapse file tree 13 files changed +224
-0
lines changed Expand file tree Collapse file tree 13 files changed +224
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Python CI
2
+ on : [pull_request]
3
+
4
+ jobs :
5
+ test :
6
+ runs-on : ubuntu-18.04
7
+ steps :
8
+ - name : Checkout
9
+ uses : actions/checkout@v2
10
+ - name : Set up Python 3.8
11
+ uses : actions/setup-python@v2
12
+ with :
13
+ python-version : ' 3.8'
14
+ architecture : ' x64'
15
+ - name : Install Library
16
+ run : |
17
+ cd python_ci
18
+ python3 -m pip install --upgrade pip
19
+ pip install -r requirements-dev.txt
20
+ pip install -r requirements.txt
21
+ - name : Run flake8
22
+ run : |
23
+ cd python_ci
24
+ make flake8
25
+ - name : Run mypy
26
+ run : |
27
+ cd python_ci
28
+ make mypy
29
+ - name : Run unittest
30
+ run : |
31
+ cd python_ci
32
+ make test
Original file line number Diff line number Diff line change
1
+ FROM python:3.8-slim
2
+
3
+ COPY requirements.txt .
4
+ COPY requirements-dev.txt .
5
+
6
+ RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
7
+ && pip install --no-cache-dir -r requirements.txt \
8
+ && pip install --no-cache-dir -r requirements-dev.txt
Original file line number Diff line number Diff line change
1
+ image = python-ci
2
+ tag = 0.1.0
3
+ curdir := ` pwd `
4
+
5
+ .PHONY : dbuild
6
+ dbuild :
7
+ docker build -t $(image ) :$(tag ) .
8
+
9
+ .PHONY : drun
10
+ drun :
11
+ docker run --rm -it -v $(curdir ) :/opt -w /opt $(image ) :$(tag ) bash
12
+
13
+ .PHONY : drmi
14
+ drmi :
15
+ docker rmi -f $(image ) :$(tag )
16
+
17
+ .PHONY : flake8
18
+ flake8 :
19
+ flake8 --config=config/tox.ini src
20
+
21
+ .PHONY : mypy
22
+ mypy :
23
+ mypy --config=config/mypy.ini src
24
+
25
+ .PHONY : test
26
+ test :
27
+ python3 -m unittest discover --verbose src
Original file line number Diff line number Diff line change
1
+ [mypy]
2
+ python_version = 3.8
3
+ disallow_untyped_defs = True
4
+ ignore_missing_imports = True
5
+ warn_redundant_casts = True
6
+ no_implicit_optional = True
7
+
8
+ [mypy-src.tests.*]
9
+ disallow_untyped_defs = False
Original file line number Diff line number Diff line change
1
+ [flake8]
2
+ max-line-length = 79
3
+ per-file-ignores =
4
+ src/tests/*:E501
Original file line number Diff line number Diff line change
1
+ flake8 == 3.8.3
2
+ mypy == 0.782
Original file line number Diff line number Diff line change
1
+ requests == 2.24.0
Original file line number Diff line number Diff line change
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass (frozen = True )
5
+ class BaseConfig :
6
+ version : str
7
+ model_path : str
8
+ model_s3_bucket : str
9
+ model_file_name : str
10
+
11
+ def generate_model_path (self ) -> str :
12
+ return "{}/{}/{}" .format (
13
+ self .model_path ,
14
+ self .version ,
15
+ self .model_file_name
16
+ )
17
+
18
+ def generate_model_s3_path (self ) -> str :
19
+ return "s3://{}/{}/{}" .format (
20
+ self .model_s3_bucket ,
21
+ self .version ,
22
+ self .model_file_name
23
+ )
24
+
25
+
26
+ @dataclass (frozen = True )
27
+ class Train :
28
+ batch_size : int = 16
29
+ epoch : int = 10
30
+
31
+
32
+ @dataclass (frozen = True )
33
+ class Test :
34
+ batch_size : int = 16
35
+
36
+
37
+ @dataclass (frozen = True )
38
+ class Config (BaseConfig ):
39
+ version : str = "v1.0.0"
40
+ model_path : str = "/ops/models"
41
+ model_s3_bucket : str = "models"
42
+ model_file_name : str = "model.pth"
43
+ train : Train = Train ()
44
+ test : Test = Test ()
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+
4
+ class Sample :
5
+ def fetch_json (self , url : str ) -> dict :
6
+ response = self ._get_response (url )
7
+ return response .json ()
8
+
9
+ def _get_response (self , url : str ) -> requests .models .Response :
10
+ return requests .get (url )
You can’t perform that action at this time.
0 commit comments