未验证 提交 a9cf38a5 编写于 作者: K kezhenxu94 提交者: GitHub

[Core][Bug] Move generated packages into skywalking namespace (#72)

The current version generates codes from proto files into a global namespace, which causes failure when there is a package in the users' application whose name is the same as the generated one, this patch moves the generated codes into the `skywalking` module and thus avoid conflicts.

Resolves https://github.com/apache/skywalking/issues/5406
上级 a92eda3a
......@@ -10,3 +10,4 @@ dist/
/apache_skywalking.egg-info/
**/venv/
tests/**/requirements.txt
skywalking/protocol
include browser/*.py
include common/*.py
include language_agent/*.py
include management/*.py
include profile/*.py
include service_mesh_probe/*.py
\ No newline at end of file
......@@ -27,13 +27,7 @@ setup-test: setup
gen:
python3 -m grpc_tools.protoc --version || python3 -m pip install grpcio-tools
python3 -m grpc_tools.protoc -I protocol --python_out=. --grpc_python_out=. protocol/**/*.proto
touch browser/__init__.py
touch common/__init__.py
touch language_agent/__init__.py
touch management/__init__.py
touch profile/__init__.py
touch service_mesh_probe/__init__.py
python3 tools/codegen.py
lint: clean
flake8 --version || python3 -m pip install flake8
......@@ -59,10 +53,11 @@ upload: package
twine upload dist/*
clean:
rm -rf browser common language_agent management profile service_mesh_probe
rm -rf skywalking_python.egg-info dist build
rm -rf skywalking/protocol
rm -rf apache_skywalking.egg-info dist build
rm -rf skywalking-python*.tgz*
find . -name "__pycache__" -exec rm -r {} +
find . -name ".pytest_cache" -exec rm -r {} +
find . -name "*.pyc" -exec rm -r {} +
release: clean lint license
......
......@@ -20,12 +20,12 @@ from queue import Queue
import grpc
from common.Common_pb2 import KeyStringValuePair
from language_agent.Tracing_pb2 import SegmentObject, SpanObject, Log, SegmentReference
from skywalking import config
from skywalking.agent import Protocol
from skywalking.agent.protocol.interceptors import header_adder_interceptor
from skywalking.client.grpc import GrpcServiceManagementClient, GrpcTraceSegmentReportService
from skywalking.protocol.common.Common_pb2 import KeyStringValuePair
from skywalking.protocol.language_agent.Tracing_pb2 import SegmentObject, SpanObject, Log, SegmentReference
from skywalking.trace.segment import Segment
logger = logging.getLogger(__name__)
......
......@@ -18,13 +18,13 @@
import logging
import grpc
from common.Common_pb2 import KeyStringValuePair
from language_agent.Tracing_pb2_grpc import TraceSegmentReportServiceStub
from management.Management_pb2 import InstancePingPkg, InstanceProperties
from management.Management_pb2_grpc import ManagementServiceStub
from skywalking import config
from skywalking.client import ServiceManagementClient, TraceSegmentReportService
from skywalking.protocol.common.Common_pb2 import KeyStringValuePair
from skywalking.protocol.language_agent.Tracing_pb2_grpc import TraceSegmentReportServiceStub
from skywalking.protocol.management.Management_pb2 import InstancePingPkg, InstanceProperties
from skywalking.protocol.management.Management_pb2_grpc import ManagementServiceStub
logger = logging.getLogger(__name__)
......
#
# 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.
#
import glob
import os
import re
from grpc_tools import protoc
dest_dir = 'skywalking/protocol'
src_dir = 'protocol'
def touch(filename):
open(filename, 'a').close()
def codegen():
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
touch(os.path.join(dest_dir, '__init__.py'))
protoc.main(['grpc_tools.protoc',
'--proto_path=' + src_dir,
'--python_out=' + dest_dir,
'--grpc_python_out=' + dest_dir
] + [proto for proto in glob.iglob(src_dir + '/**/*.proto')])
for py_file in glob.iglob(os.path.join(dest_dir, '**/*.py')):
touch(os.path.join(os.path.dirname(py_file), '__init__.py'))
with open(py_file, 'r+') as file:
code = file.read()
file.seek(0)
file.write(re.sub(r'from (.+) (import .+_pb2.*)', 'from ..\\1 \\2', code))
file.truncate()
if __name__ == '__main__':
codegen()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册