feat: add package handler and lint codes (#15)

diff --git a/.github/workflows/unit-test-ci.yml b/.github/workflows/runner-lint.yml
similarity index 75%
copy from .github/workflows/unit-test-ci.yml
copy to .github/workflows/runner-lint.yml
index 00b05d6..e460ca9 100644
--- a/.github/workflows/unit-test-ci.yml
+++ b/.github/workflows/runner-lint.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-name: Unit Test CI
+name: Runner Lint Check
 
 on:
   push:
@@ -27,22 +27,16 @@
     branches:
       - master
 jobs:
-  run:
+  Run:
     runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        python-version: [ 3.6, 3.7, 3.8, 3.9 ]
-      fail-fast: false
     steps:
       - name: Checkout source codes
         uses: actions/checkout@v2
         with:
           submodules: true
-      - name: Set up Python ${{ matrix.python-version }}
+      - name: Set up Python
         uses: actions/setup-python@v2
         with:
-          python-version: ${{ matrix.python-version }}
-      - name: Set up dependencies
-        run: make setup
-      - name: Run unit tests
-        run: make test
+          python-version: 3.6
+      - name: Lint codes
+        run: make lint
diff --git a/.github/workflows/unit-test-ci.yml b/.github/workflows/runner-test.yml
similarity index 95%
rename from .github/workflows/unit-test-ci.yml
rename to .github/workflows/runner-test.yml
index 00b05d6..c3ec9eb 100644
--- a/.github/workflows/unit-test-ci.yml
+++ b/.github/workflows/runner-test.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-name: Unit Test CI
+name: Runner Unit Test
 
 on:
   push:
@@ -27,7 +27,7 @@
     branches:
       - master
 jobs:
-  run:
+  Run:
     runs-on: ubuntu-latest
     strategy:
       matrix:
@@ -43,6 +43,6 @@
         with:
           python-version: ${{ matrix.python-version }}
       - name: Set up dependencies
-        run: make setup
+        run: make setup install
       - name: Run unit tests
         run: make test
diff --git a/Makefile b/Makefile
index baadfff..b290d94 100644
--- a/Makefile
+++ b/Makefile
@@ -17,11 +17,32 @@
 .PHONY: setup
 setup:
 	python3 -m pip install --upgrade pip
-	python3 -m pip install a6pluginprotos --ignore-installed
-	python3 -m pip install minicache --ignore-installed
-	python3 -m pip install click --ignore-installed
-	python3 -m pip install pytest --ignore-installed
+	python3 -m pip install -r requirements.txt --ignore-installed
+
 
 .PHONY: test
 test:
-	python3 -m pytest -v tests
+	pytest --version || python3 -m pip install pytest-cov
+	python3 -m pytest --cov=apisix/runner tests
+
+
+.PHONY: install
+install: clean
+	python3 setup.py install --force
+
+
+.PHONY: lint
+lint: clean
+	flake8 --version || python3 -m pip install flake8
+	flake8 . --count --select=E9,F63,F7,F82 --show-source
+	flake8 . --count --max-complexity=15 --max-line-length=120
+
+
+.PHONY: clean
+clean:
+	rm -rf apache_apisix.egg-info dist build .coverage
+	find . -name "__pycache__" -exec rm -r {} +
+	find . -name ".pytest_cache" -exec rm -r {} +
+	find . -name "*.pyc" -exec rm -r {} +
+
+
diff --git a/apisix/main.py b/apisix/main.py
index ad9a7d5..3da621d 100644
--- a/apisix/main.py
+++ b/apisix/main.py
@@ -15,11 +15,8 @@
 # limitations under the License.
 #
 import os
-import sys
 import click
 
-sys.path.append(os.path.dirname(os.path.dirname(__file__)))
-
 from apisix.runner.server.server import Server as NewServer
 
 RUNNER_VERSION = "0.1.0"
diff --git a/apisix/runner/http/response.py b/apisix/runner/http/response.py
index 599ead5..f998f4c 100644
--- a/apisix/runner/http/response.py
+++ b/apisix/runner/http/response.py
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from __future__ import annotations
+
 import flatbuffers
 from a6pluginproto import TextEntry as A6TextEntry
 from a6pluginproto.Err import Resp as A6ErrResp
diff --git a/apisix/runner/server/handle.py b/apisix/runner/server/handle.py
index 7c05fb5..18fcb60 100644
--- a/apisix/runner/server/handle.py
+++ b/apisix/runner/server/handle.py
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from __future__ import annotations
+
 from a6pluginproto.Err import Code as A6ErrCode
 import apisix.runner.plugin.core as RunnerPlugin
 import apisix.runner.plugin.cache as RunnerCache
diff --git a/apisix/runner/server/response.py b/apisix/runner/server/response.py
index 08b0f53..f5a2a8c 100644
--- a/apisix/runner/server/response.py
+++ b/apisix/runner/server/response.py
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from __future__ import annotations
+
 from a6pluginproto.Err import Code as A6ErrCode
 
 RUNNER_SUCCESS_CODE = 200
@@ -36,11 +36,11 @@
         self.__type = ty
         self.__data = data
 
-    def __eq__(self, other: Response) -> bool:
-        return self.code == other.code and \
-               self.message == other.message and \
-               self.data == other.data and \
-               self.type == other.type
+    def __eq__(self, response) -> bool:
+        return self.code == response.code and \
+               self.message == response.message and \
+               self.data == response.data and \
+               self.type == response.type
 
     @property
     def code(self) -> int:
diff --git a/pytest.ini b/pytest.ini
index 607c293..6d3dba5 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -15,6 +15,6 @@
 ; limitations under the License.
 ;
 [pytest]
-addopts = -vs -p no:warnings --disable-socket
+addopts = --cov=apisix/runner -p no:warnings
 testpaths = tests
 python_files = test_*
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..0cd85b8
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,3 @@
+a6pluginprotos==0.1.0
+click==8.0.1
+minicache==0.0.1
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..79aa082
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,35 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from setuptools import setup, find_packages
+
+__version__ = "0.1.0"
+
+requirements = open('requirements.txt').readlines()
+
+setup(
+    name="apache-apisix",
+    version=__version__,
+    description="Python Plugin Runner for Apache APISIX",
+    url="https://github.com/apache/apisix-python-plugin-runner",
+    author="Jinchao Shuai",
+    author_email="dev@apisix.apache.org",
+    license="Apache 2.0",
+    python_requires=">=3.6.0",
+    packages=find_packages(exclude=["tests"]),
+    install_requires=requirements,
+)