This is an automated email from the ASF dual-hosted git repository.

liuxiaocs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git


The following commit(s) were added to refs/heads/main by this push:
     new b878fe8  feat: add setup.py for packaging (#32)
b878fe8 is described below

commit b878fe8c2cc960fef2f6ae6963b98614cb2d7092
Author: Simon Cheung <[email protected]>
AuthorDate: Fri Mar 15 09:39:48 2024 +0800

    feat: add setup.py for packaging (#32)
---
 .github/workflows/hugegraph-python-client.yml      |  2 +-
 .../__init__.py => hugegraph-llm/MANIFEST.in       | 34 ++++++++--------
 hugegraph-llm/setup.py                             | 46 ++++++++++++++++++++++
 .../hugegraph_llm/config}/__init__.py              |  0
 .../src/{ => hugegraph_llm}/config/config.ini      |  0
 .../{ => src/hugegraph_llm}/examples/__init__.py   |  0
 .../hugegraph_llm}/examples/build_kg_test.py       |  0
 .../hugegraph_llm}/examples/graph_rag_test.py      |  0
 hugegraph-llm/src/hugegraph_llm/llms/ernie_bot.py  |  4 +-
 .../operators/common_op/nltk_helper.py             |  2 +-
 hugegraph-llm/src/hugegraph_llm/utils/config.py    | 18 +++++++--
 .../src/hugegraph_llm/utils/gradio_demo.py         |  4 +-
 hugegraph-python-client/setup.py                   | 45 +++++++++++++++++++++
 .../{example => src/pyhugegraph}/__init__.py       |  0
 .../{ => src/pyhugegraph}/example/__init__.py      |  0
 .../pyhugegraph}/example/hugegraph_example.py      |  0
 .../pyhugegraph}/example/hugegraph_test.py         |  0
 17 files changed, 128 insertions(+), 27 deletions(-)

diff --git a/.github/workflows/hugegraph-python-client.yml 
b/.github/workflows/hugegraph-python-client.yml
index 61fabb6..7754a59 100644
--- a/.github/workflows/hugegraph-python-client.yml
+++ b/.github/workflows/hugegraph-python-client.yml
@@ -32,7 +32,7 @@ jobs:
       run: |
         export PYTHONPATH=$(pwd)/hugegraph-python-client/src
         echo ${PYTHONPATH}
-        python hugegraph-python-client/example/hugegraph_example.py
+        python 
hugegraph-python-client/src/pyhugegraph/example/hugegraph_example.py
     - name: Test with pytest
       run: |
         pytest
diff --git a/hugegraph-python-client/example/__init__.py 
b/hugegraph-llm/MANIFEST.in
similarity index 94%
copy from hugegraph-python-client/example/__init__.py
copy to hugegraph-llm/MANIFEST.in
index e0533d9..37229fb 100644
--- a/hugegraph-python-client/example/__init__.py
+++ b/hugegraph-llm/MANIFEST.in
@@ -1,16 +1,18 @@
-# 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.
+# 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.
+
+recursive-include src/hugegraph_llm/config *
diff --git a/hugegraph-llm/setup.py b/hugegraph-llm/setup.py
new file mode 100644
index 0000000..f33ae23
--- /dev/null
+++ b/hugegraph-llm/setup.py
@@ -0,0 +1,46 @@
+# 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 setuptools
+from pkg_resources import parse_requirements
+
+with open("README.md", "r", encoding="utf-8") as fh:
+    long_description = fh.read()
+
+with open("requirements.txt", encoding="utf-8") as fp:
+    install_requires = [str(requirement) for requirement in 
parse_requirements(fp)]
+
+setuptools.setup(
+    name="hugegraph-llm",
+    version="1.3.0",
+    author="Apache HugeGraph Contributors",
+    author_email="[email protected]",
+    install_requires=install_requires,
+    include_package_data=True,
+    description="Integrating Apache HugeGraph with LLM.",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="https://github.com/apache/incubator-hugegraph-ai";,
+    packages=setuptools.find_packages(where="src", exclude=["tests"]),
+    package_dir={"": "src"},
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "License :: OSI Approved :: Apache Software License",
+        "Operating System :: OS Independent",
+    ],
+    python_requires=">=3.9",
+)
diff --git a/hugegraph-llm/examples/__init__.py 
b/hugegraph-llm/src/hugegraph_llm/config/__init__.py
similarity index 100%
copy from hugegraph-llm/examples/__init__.py
copy to hugegraph-llm/src/hugegraph_llm/config/__init__.py
diff --git a/hugegraph-llm/src/config/config.ini 
b/hugegraph-llm/src/hugegraph_llm/config/config.ini
similarity index 100%
rename from hugegraph-llm/src/config/config.ini
rename to hugegraph-llm/src/hugegraph_llm/config/config.ini
diff --git a/hugegraph-llm/examples/__init__.py 
b/hugegraph-llm/src/hugegraph_llm/examples/__init__.py
similarity index 100%
rename from hugegraph-llm/examples/__init__.py
rename to hugegraph-llm/src/hugegraph_llm/examples/__init__.py
diff --git a/hugegraph-llm/examples/build_kg_test.py 
b/hugegraph-llm/src/hugegraph_llm/examples/build_kg_test.py
similarity index 100%
rename from hugegraph-llm/examples/build_kg_test.py
rename to hugegraph-llm/src/hugegraph_llm/examples/build_kg_test.py
diff --git a/hugegraph-llm/examples/graph_rag_test.py 
b/hugegraph-llm/src/hugegraph_llm/examples/graph_rag_test.py
similarity index 100%
rename from hugegraph-llm/examples/graph_rag_test.py
rename to hugegraph-llm/src/hugegraph_llm/examples/graph_rag_test.py
diff --git a/hugegraph-llm/src/hugegraph_llm/llms/ernie_bot.py 
b/hugegraph-llm/src/hugegraph_llm/llms/ernie_bot.py
index c4ec2f2..d0838aa 100644
--- a/hugegraph-llm/src/hugegraph_llm/llms/ernie_bot.py
+++ b/hugegraph-llm/src/hugegraph_llm/llms/ernie_bot.py
@@ -63,9 +63,7 @@ class ErnieBotClient(BaseLLM):
             )
         response_json = json.loads(response.text)
         if "error_code" in response_json:
-            raise Exception(
-                f"Error {response_json['error_code']}: 
{response_json['error_msg']}"
-            )
+            raise Exception(f"Error {response_json['error_code']}: 
{response_json['error_msg']}")
         return response_json["result"]
 
     def generate_streaming(
diff --git a/hugegraph-llm/src/hugegraph_llm/operators/common_op/nltk_helper.py 
b/hugegraph-llm/src/hugegraph_llm/operators/common_op/nltk_helper.py
index eb7b4d2..dc3b1dc 100644
--- a/hugegraph-llm/src/hugegraph_llm/operators/common_op/nltk_helper.py
+++ b/hugegraph-llm/src/hugegraph_llm/operators/common_op/nltk_helper.py
@@ -77,5 +77,5 @@ class NLTKHelper:
         return str(path)
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     NLTKHelper().stopwords()
diff --git a/hugegraph-llm/src/hugegraph_llm/utils/config.py 
b/hugegraph-llm/src/hugegraph_llm/utils/config.py
index b11585a..aa73fbb 100644
--- a/hugegraph-llm/src/hugegraph_llm/utils/config.py
+++ b/hugegraph-llm/src/hugegraph_llm/utils/config.py
@@ -21,16 +21,26 @@ import os
 
 class Config:
     def __init__(self, config_file=None, section=None):
-        if config_file is None:
-            root_dir = 
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-            config_file = os.path.join(root_dir, "config", "config.ini")
         if section is None:
             raise Exception("config section cannot be none !")
-        self.config_file = config_file
+        self.config_file = self.init_config_file(config_file)
         self.config = configparser.ConfigParser()
         self.config.read(self.config_file)
         self.section = section
 
+    def init_config_file(self, config_file):
+        if config_file is None:
+            root_dir = 
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+            config_file = os.path.join(root_dir, "hugegraph_llm", "config", 
"config.ini")
+
+        if not os.path.exists(config_file):
+            config = configparser.ConfigParser()
+            config.add_section("llm")
+            config.add_section("hugegraph")
+            with open(config_file, "w", encoding="utf-8") as file:
+                config.write(file)
+        return config_file
+
     def update_config(self, updates):
         for key, value in updates.items():
             self.config.set(self.section, key, value)
diff --git a/hugegraph-llm/src/hugegraph_llm/utils/gradio_demo.py 
b/hugegraph-llm/src/hugegraph_llm/utils/gradio_demo.py
index f6122eb..de97074 100644
--- a/hugegraph-llm/src/hugegraph_llm/utils/gradio_demo.py
+++ b/hugegraph-llm/src/hugegraph_llm/utils/gradio_demo.py
@@ -125,7 +125,7 @@ def init_config(
     ip, port, user, pwd, graph, type, api_key, secret_key, llm_url, 
model_name, max_token
 ):
     root_dir = 
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-    config_file = os.path.join(root_dir, "config", "config.ini")
+    config_file = os.path.join(root_dir, "hugegraph_llm", "config", 
"config.ini")
 
     config = Config(config_file=config_file, section="hugegraph")
     config.update_config({"ip": ip, "port": port, "user": user, "pwd": pwd, 
"graph": graph})
@@ -249,7 +249,7 @@ with gr.Blocks() as hugegraph_llm:
     btn = gr.Button("Run gremlin query on HugeGraph")
     btn.click(fn=run_gremlin_query, inputs=inp, outputs=out)  # pylint: 
disable=no-member
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     app = FastAPI()
     app = gr.mount_gradio_app(app, hugegraph_llm, path="/")
     uvicorn.run(app, host="0.0.0.0", port=8001)
diff --git a/hugegraph-python-client/setup.py b/hugegraph-python-client/setup.py
new file mode 100644
index 0000000..12161f1
--- /dev/null
+++ b/hugegraph-python-client/setup.py
@@ -0,0 +1,45 @@
+# 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 setuptools
+from pkg_resources import parse_requirements
+
+with open("README.md", "r", encoding="utf-8") as fh:
+    long_description = fh.read()
+
+with open("requirements.txt", encoding="utf-8") as fp:
+    install_requires = [str(requirement) for requirement in 
parse_requirements(fp)]
+
+setuptools.setup(
+    name="hugegraph-python",
+    version="1.3.0",
+    author="Apache HugeGraph Contributors",
+    author_email="[email protected]",
+    install_requires=install_requires,
+    description="A Python SDK for Apache HugeGraph",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="https://github.com/apache/incubator-hugegraph-ai";,
+    packages=setuptools.find_packages(where="src", exclude=["tests"]),
+    package_dir={"": "src"},
+    classifiers=[
+        "Programming Language :: Python :: 3",
+        "License :: OSI Approved :: Apache Software License",
+        "Operating System :: OS Independent",
+    ],
+    python_requires=">=3.9",
+)
diff --git a/hugegraph-python-client/example/__init__.py 
b/hugegraph-python-client/src/pyhugegraph/__init__.py
similarity index 100%
copy from hugegraph-python-client/example/__init__.py
copy to hugegraph-python-client/src/pyhugegraph/__init__.py
diff --git a/hugegraph-python-client/example/__init__.py 
b/hugegraph-python-client/src/pyhugegraph/example/__init__.py
similarity index 100%
rename from hugegraph-python-client/example/__init__.py
rename to hugegraph-python-client/src/pyhugegraph/example/__init__.py
diff --git a/hugegraph-python-client/example/hugegraph_example.py 
b/hugegraph-python-client/src/pyhugegraph/example/hugegraph_example.py
similarity index 100%
rename from hugegraph-python-client/example/hugegraph_example.py
rename to hugegraph-python-client/src/pyhugegraph/example/hugegraph_example.py
diff --git a/hugegraph-python-client/example/hugegraph_test.py 
b/hugegraph-python-client/src/pyhugegraph/example/hugegraph_test.py
similarity index 100%
rename from hugegraph-python-client/example/hugegraph_test.py
rename to hugegraph-python-client/src/pyhugegraph/example/hugegraph_test.py

Reply via email to