Parcourir la source

添加打python包文件

lijunliang il y a 1 an
Parent
commit
11a363040e

+ 9 - 4
README.md

@@ -2,10 +2,12 @@
 
 
 ## *启动服务*
+
 ```python
-from a2s_server import watch, simple_params
+from a2s.a2s_server import watch, simple_params
+
 
-#方式一 使用简单方式启动   .py文件命令行参数   python server.py --h
+# 方式一 使用简单方式启动   .py文件命令行参数   python server.py --h
 @simple_params
 @watch
 def main(data: bytes, *args, **kwargs) -> bytes:
@@ -21,8 +23,10 @@ def main(data: bytes, *args, **kwargs) -> bytes:
     data += "服务端处理过了数据"
     return data.encode("utf-8")
 
+
 main()
 
+
 # 方式二 自定义启动方式
 @watch
 def main(data: bytes, *args, **kwargs) -> bytes:
@@ -38,7 +42,8 @@ def main(data: bytes, *args, **kwargs) -> bytes:
     data += "服务端处理过了数据"
     return data.encode("utf-8")
 
-main(nats_host="192.168.3.240",nats_port=19090,subject="test",queue="main")
+
+main(nats_host="192.168.3.240", nats_port=19090, subject="test", queue="main")
 ```
 #### 方式一 更简单方式启动
 #### 方法二 灵活性更高
@@ -50,7 +55,7 @@ a2s_client # 简化a2s客户端调用
 
 ```python
 
-from a2s_client import a2s_execute
+from a2s.a2s_client import a2s_execute
 
 if __name__ == '__main__':
     # bytes_data 调用端的 data 记得编码

+ 0 - 0
a2s/__init__.py


+ 1 - 1
a2s_client.py → a2s/a2s_client.py

@@ -1,7 +1,7 @@
 # coding:utf-8
 
 import grpc
-from proto import service_pb2, service_pb2_grpc
+from a2s.proto import service_pb2, service_pb2_grpc
 import logging
 
 

+ 1 - 1
a2s_server.py → a2s/a2s_server.py

@@ -2,7 +2,7 @@
 import argparse
 from functools import wraps
 from pynats import NATSClient
-from proto.service_pb2 import NatsRequest, NatsResponse
+from a2s.proto.service_pb2 import NatsRequest, NatsResponse
 import time
 import logging
 

+ 0 - 0
a2s/demo/__init__.py


+ 1 - 1
demo/client.py → a2s/demo/client.py

@@ -1,5 +1,5 @@
 # coding:utf-8
-from a2s_client import a2s_execute
+from a2s.a2s_client import a2s_execute
 
 if __name__ == '__main__':
     result = a2s_execute(a2s_ip="192.168.3.240:19094", topic="test", timeout=10, bytes_data=b"hello")

+ 1 - 1
demo/server.py → a2s/demo/server.py

@@ -1,4 +1,4 @@
-from a2s_server import watch, simple_params
+from a2s.a2s_server import watch, simple_params
 
 #方式一 使用简单方式启动   .py文件命令行参数   python server.py --h
 @simple_params

+ 0 - 0
a2s/proto/__init__.py


+ 0 - 0
proto/service.proto → a2s/proto/service.proto


+ 0 - 0
proto/service_pb2.py → a2s/proto/service_pb2.py


+ 1 - 1
proto/service_pb2_grpc.py → a2s/proto/service_pb2_grpc.py

@@ -1,7 +1,7 @@
 # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
 import grpc
 
-import proto.service_pb2 as service__pb2
+import a2s.proto.service_pb2 as service__pb2
 
 
 class CallerStub(object):

+ 1 - 1
tools.py → a2s/tools.py

@@ -28,7 +28,7 @@ def json_serialize(dict_data):
     :return:
     """
     # 将字典转换为 JSON 格式的字符串
-    json_data = json.dumps(dict_data)
+    json_data = json.dumps(dict_data, ensure_ascii=False)
 
     # 将 JSON 字符串转换为字节流
     bytes_data = json_data.encode('utf-8')

+ 0 - 12
proto/text2vector.proto

@@ -1,12 +0,0 @@
-syntax = "proto3";
-package proto;
-
-//请求
-message Text2VectorReq{
-    string text = 1;
-}
-
-//响应
-message Text2VectorResp{
-  repeated float vector = 1;
-}

+ 0 - 107
proto/text2vector_pb2.py

@@ -1,107 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by the protocol buffer compiler.  DO NOT EDIT!
-# source: text2vector.proto
-
-from google.protobuf import descriptor as _descriptor
-from google.protobuf import message as _message
-from google.protobuf import reflection as _reflection
-from google.protobuf import symbol_database as _symbol_database
-# @@protoc_insertion_point(imports)
-
-_sym_db = _symbol_database.Default()
-
-
-
-
-DESCRIPTOR = _descriptor.FileDescriptor(
-  name='text2vector.proto',
-  package='proto',
-  syntax='proto3',
-  serialized_options=None,
-  serialized_pb=b'\n\x11text2vector.proto\x12\x05proto\"\x1e\n\x0eText2VectorReq\x12\x0c\n\x04text\x18\x01 \x01(\t\"!\n\x0fText2VectorResp\x12\x0e\n\x06vector\x18\x01 \x03(\x02\x62\x06proto3'
-)
-
-
-
-
-_TEXT2VECTORREQ = _descriptor.Descriptor(
-  name='Text2VectorReq',
-  full_name='proto.Text2VectorReq',
-  filename=None,
-  file=DESCRIPTOR,
-  containing_type=None,
-  fields=[
-    _descriptor.FieldDescriptor(
-      name='text', full_name='proto.Text2VectorReq.text', index=0,
-      number=1, type=9, cpp_type=9, label=1,
-      has_default_value=False, default_value=b"".decode('utf-8'),
-      message_type=None, enum_type=None, containing_type=None,
-      is_extension=False, extension_scope=None,
-      serialized_options=None, file=DESCRIPTOR),
-  ],
-  extensions=[
-  ],
-  nested_types=[],
-  enum_types=[
-  ],
-  serialized_options=None,
-  is_extendable=False,
-  syntax='proto3',
-  extension_ranges=[],
-  oneofs=[
-  ],
-  serialized_start=28,
-  serialized_end=58,
-)
-
-
-_TEXT2VECTORRESP = _descriptor.Descriptor(
-  name='Text2VectorResp',
-  full_name='proto.Text2VectorResp',
-  filename=None,
-  file=DESCRIPTOR,
-  containing_type=None,
-  fields=[
-    _descriptor.FieldDescriptor(
-      name='vector', full_name='proto.Text2VectorResp.vector', index=0,
-      number=1, type=2, cpp_type=6, label=3,
-      has_default_value=False, default_value=[],
-      message_type=None, enum_type=None, containing_type=None,
-      is_extension=False, extension_scope=None,
-      serialized_options=None, file=DESCRIPTOR),
-  ],
-  extensions=[
-  ],
-  nested_types=[],
-  enum_types=[
-  ],
-  serialized_options=None,
-  is_extendable=False,
-  syntax='proto3',
-  extension_ranges=[],
-  oneofs=[
-  ],
-  serialized_start=60,
-  serialized_end=93,
-)
-
-DESCRIPTOR.message_types_by_name['Text2VectorReq'] = _TEXT2VECTORREQ
-DESCRIPTOR.message_types_by_name['Text2VectorResp'] = _TEXT2VECTORRESP
-_sym_db.RegisterFileDescriptor(DESCRIPTOR)
-
-Text2VectorReq = _reflection.GeneratedProtocolMessageType('Text2VectorReq', (_message.Message,), {
-  'DESCRIPTOR' : _TEXT2VECTORREQ,
-  '__module__' : 'text2vector_pb2'
-  # @@protoc_insertion_point(class_scope:proto.Text2VectorReq)
-  })
-_sym_db.RegisterMessage(Text2VectorReq)
-
-Text2VectorResp = _reflection.GeneratedProtocolMessageType('Text2VectorResp', (_message.Message,), {
-  'DESCRIPTOR' : _TEXT2VECTORRESP,
-  '__module__' : 'text2vector_pb2'
-  # @@protoc_insertion_point(class_scope:proto.Text2VectorResp)
-  })
-_sym_db.RegisterMessage(Text2VectorResp)
-
-
-# @@protoc_insertion_point(module_scope)

+ 0 - 3
proto/text2vector_pb2_grpc.py

@@ -1,3 +0,0 @@
-# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
-import grpc
-

+ 0 - 0
requirement.txt → requement.txt


+ 23 - 0
setup.py

@@ -0,0 +1,23 @@
+import setuptools
+
+with open("README.md", "r") as fh:
+    long_description = fh.read()
+
+setuptools.setup(
+    name="a2s",
+    version="0.0.1",
+    author="LJL",
+    author_email="author@example.com",
+    description="A small example package",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="http://ai-01:8080/",
+    packages=setuptools.find_packages(),
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+    ],
+   install_requires=[]
+
+)