Skip to content

Commit

Permalink
Add generate command in coordinator setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lidongze0629 committed Jan 30, 2024
1 parent 1f494b1 commit 4580f18
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 21 deletions.
1 change: 0 additions & 1 deletion flex/coordinator/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ gs_flex_coordinator/test/__init__.py
gs_flex_coordinator/typing_utils.py
gs_flex_coordinator/util.py
requirements.txt
setup.py
test-requirements.txt
tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self):
# receivers
self._receivers = {}
# pickle path
self._receiver_path = os.path.join(ALERT_WORKSPACE, "receiver.pickle")
self._receiver_path = os.path.join(ALERT_WORKSPACE, "receiver", "data.pickle")
os.makedirs(self._receiver_path, exist_ok=True)
# recover
self._try_to_recover_from_disk()
# message collector
Expand Down
132 changes: 116 additions & 16 deletions flex/coordinator/setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,117 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2024 Alibaba Group Holding Limited.
#
# Licensed 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 os
import shutil
import subprocess
import sys
from setuptools import setup, find_packages
import tempfile
from distutils.cmd import Command

from setuptools import find_packages, setup

NAME = "gs_flex_coordinator"
VERSION = "1.0.0"

# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
pkg_root = os.path.dirname(os.path.abspath(__file__))

REQUIRES = ["connexion>=2.0.2", "swagger-ui-bundle>=0.0.2", "python_dateutil>=2.6.0"]


class GenerateFlexServer(Command):
description = "generate flex server from openapi specification file"
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
# generate server code, note that controllers are not included here,
# see from .openapi-generator-ignore
specification = os.path.join(
pkg_root, "..", "openapi", "openapi_coordinator.yaml"
)
cmd = [
"openapi-generator-cli",
"generate",
"-g",
"python-flask",
"-i",
str(specification),
"-o",
str(pkg_root),
"--package-name",
"gs_flex_coordinator",
]
print(" ".join(cmd))
subprocess.check_call(
cmd,
env=os.environ.copy(),
)


class GenerateInteractiveSDK(Command):
description = "generate interactive client sdk from openapi specification file"
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
# remove
tempdir = os.path.join("/", tempfile.gettempprefix(), "flex_interactive")
if os.path.exists(tempdir):
shutil.rmtree(tempdir)
targetdir = os.path.join(
pkg_root, "gs_flex_coordinator", "core", "interactive", "hiactor_client"
)
if os.path.exists(targetdir):
shutil.rmtree(targetdir)
# generate
specification = os.path.join(
pkg_root, "..", "openapi", "openapi_interactive.yaml"
)
cmd = [
"openapi-generator-cli",
"generate",
"-g",
"python",
"-i",
str(specification),
"-o",
str(tempdir),
"--package-name",
"hiactor_client",
]
print(" ".join(cmd))
subprocess.check_call(
cmd,
env=os.environ.copy(),
)
# cp
subprocess.run(["cp", "-r", os.path.join(tempdir, "hiactor_client"), targetdir])

Check notice on line 113 in flex/coordinator/setup.py

View check run for this annotation

codefactor.io / CodeFactor

flex/coordinator/setup.py#L113

Starting a process with a partial executable path (B607)

REQUIRES = [
"connexion>=2.0.2",
"swagger-ui-bundle>=0.0.2",
"python_dateutil>=2.6.0"
]

setup(
name=NAME,
Expand All @@ -26,12 +122,16 @@
keywords=["OpenAPI", "GraphScope FLEX HTTP SERVICE API"],
install_requires=REQUIRES,
packages=find_packages(),
package_data={'': ['openapi/openapi.yaml']},
package_data={"": ["openapi/openapi.yaml"]},
cmdclass={
"generate_flex_server": GenerateFlexServer,
"generate_interactive_sdk": GenerateInteractiveSDK,
},
include_package_data=True,
entry_points={
'console_scripts': ['gs_flex_coordinator=gs_flex_coordinator.__main__:main']},
"console_scripts": ["gs_flex_coordinator=gs_flex_coordinator.__main__:main"]
},
long_description="""\
This is a specification for GraphScope FLEX HTTP service based on the OpenAPI 3.0 specification. You can find out more details about specification at [doc](https://swagger.io/specification/v3/). Some useful links: - [GraphScope Repository](https://github.com/alibaba/GraphScope) - [The Source API definition for GraphScope Interactive](https://github.com/GraphScope/portal/tree/main/httpservice)
"""
""",
)

6 changes: 3 additions & 3 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def run(self):
)


class GenerateFlexClient(Command):
description = "generate flex client from openapi specification file"
class GenerateFlexSDK(Command):
description = "generate flex client sdk from openapi specification file"
user_options = []

def initialize_options(self):
Expand Down Expand Up @@ -456,7 +456,7 @@ def parse_version(root, **kwargs):
"build_gltorch_ext": BuildGLTorchExt,
"build_proto": BuildProto,
"build_py": CustomBuildPy,
"generate_flex_client": GenerateFlexClient,
"generate_flex_sdk": GenerateFlexSDK,
"bdist_wheel": CustomBDistWheel,
"sdist": CustomSDist,
"develop": CustomDevelop,
Expand Down

0 comments on commit 4580f18

Please sign in to comment.