This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/apisix-python-plugin-runner.git
The following commit(s) were added to refs/heads/master by this push:
new f6d804a feat: add package handler and lint codes (#15)
f6d804a is described below
commit f6d804a7f113f94d5507b2f074653e81dd69b4a2
Author: 帅进超 <[email protected]>
AuthorDate: Fri Aug 13 17:40:19 2021 +0800
feat: add package handler and lint codes (#15)
---
.../{unit-test-ci.yml => runner-lint.yml} | 18 +++------
.../{unit-test-ci.yml => runner-test.yml} | 6 +--
Makefile | 31 ++++++++++++---
apisix/main.py | 3 --
apisix/runner/http/response.py | 2 +-
apisix/runner/server/handle.py | 2 +-
apisix/runner/server/response.py | 12 +++---
pytest.ini | 2 +-
requirements.txt | 3 ++
apisix/main.py => setup.py | 44 ++++++++--------------
10 files changed, 62 insertions(+), 61 deletions(-)
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 @@ on:
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 @@ on:
branches:
- master
jobs:
- run:
+ Run:
runs-on: ubuntu-latest
strategy:
matrix:
@@ -43,6 +43,6 @@ jobs:
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 @@ class Response:
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/apisix/main.py b/setup.py
similarity index 53%
copy from apisix/main.py
copy to setup.py
index ad9a7d5..79aa082 100644
--- a/apisix/main.py
+++ b/setup.py
@@ -14,36 +14,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-import os
-import sys
-import click
-sys.path.append(os.path.dirname(os.path.dirname(__file__)))
+from setuptools import setup, find_packages
-from apisix.runner.server.server import Server as NewServer
+__version__ = "0.1.0"
-RUNNER_VERSION = "0.1.0"
-RUNNER_SOCKET = os.getenv("APISIX_LISTEN_ADDRESS", "/tmp/runner.sock")
+requirements = open('requirements.txt').readlines()
-
[email protected]()
[email protected]_option(version=RUNNER_VERSION)
-def runner() -> None:
- pass
-
-
[email protected]()
[email protected]('--debug/--no-debug', help='enable or disable debug, default
disable.', default=False)
-def start(debug) -> None:
- click.echo(debug)
- click.echo(RUNNER_SOCKET)
- server = NewServer(RUNNER_SOCKET)
- server.receive()
-
-
-def main() -> None:
- runner()
-
-
-if __name__ == '__main__':
- main()
+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="[email protected]",
+ license="Apache 2.0",
+ python_requires=">=3.6.0",
+ packages=find_packages(exclude=["tests"]),
+ install_requires=requirements,
+)