Skip to content

Commit

Permalink
feat: modernize with PDM (vesoft-inc#304)
Browse files Browse the repository at this point in the history
* feat: modernize with PDM

Signed-off-by: Frost Ming <me@frostming.com>

* doc: update README

Signed-off-by: Frost Ming <me@frostming.com>

* run under pdm env

Signed-off-by: Frost Ming <me@frostming.com>

* requires-python `>=3.7`

* fix: update lockfile

Signed-off-by: Frost Ming <me@frostming.com>

* fix: separate example tests

Signed-off-by: Frost Ming <me@frostming.com>

* fix lint

Signed-off-by: Frost Ming <me@frostming.com>

* fix: try fixing by upgrading coverage

Signed-off-by: Frost Ming <me@frostming.com>

---------

Signed-off-by: Frost Ming <me@frostming.com>
Co-authored-by: Wey Gu <weyl.gu@gmail.com>
  • Loading branch information
frostming and wey-gu authored Jan 8, 2024
1 parent fce0b09 commit b63cd38
Show file tree
Hide file tree
Showing 29 changed files with 1,281 additions and 792 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/deploy_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
with:
python-version: '3.x'
cache: true
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel twine
pip install .
pip install -r requirements/dev.txt
run: pdm install
- name: Test with pytest
run: |
docker-compose -f docker-compose.yaml up -d
docker-compose -f tests/docker-compose.yaml up -d
sleep 20
pytest -s -v -k "not SSL"
working-directory: tests
pdm test
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose -f docker-compose-ssl.yaml up -d
enable_ssl=true docker-compose -f tests/docker-compose-ssl.yaml up -d
sleep 20
pytest -s -v -k "SSL"
working-directory: tests
pdm test-ssl
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_NAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 setup.py sdist bdist_wheel
twine upload dist/*
PDM_PUBLISH_USERNAME: ${{ secrets.PYPI_NAME }}
PDM_PUBLISH_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: pdm publish
57 changes: 35 additions & 22 deletions .github/workflows/run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:

jobs:
ci:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
max-parallel: 2
matrix:
python-version: [3.9, '3.10', 3.11, 3.12]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]

steps:
- name: Maximize runner space
Expand All @@ -27,35 +27,48 @@ jobs:

- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}
- name: lint
run: make fmt-check
cache: true

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r requirements/dev.txt
run: pdm install
- name: lint
run: pdm fmt-check
- name: Test with pytest
run: |
docker-compose -f docker-compose.yaml up -d
docker-compose -f tests/docker-compose.yaml up -d
sleep 20
pytest -s -v -k "not SSL" --cov=../nebula3 --cov-report=xml --cov-append
working-directory: tests
pdm test
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose -f docker-compose-ssl.yaml up -d
sleep 20
pytest -s -v -k "SSL" --cov=../nebula3 --cov-report=xml --cov-append
working-directory: tests
- name: Test example
run: |
docker-compose -f ../tests/docker-compose.yaml up -d
enable_ssl=true docker-compose -f tests/docker-compose-ssl.yaml up -d
sleep 20
for f in *.py; do python "$f"; done
working-directory: example
pdm test-ssl
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./tests/coverage.xml
files: coverage.xml

example:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11, 3.12]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: pdm-project/setup-pdm@v3
with:
python-version: ${{ matrix.python-version }}
cache: true
- name: Install dependencies
run: pdm install -G example
- name: Setup containers
run: |
docker-compose -f tests/docker-compose.yaml up -d
sleep 20
- name: Test example
run: |
for f in example/*.py; do pdm run python "$f"; done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ nebula/graph.thrift
# CI data
tests/data
tests/logs
.pdm-python
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

61 changes: 35 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This repository holds the official Python API for NebulaGraph.

[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)

## Before you start

Before you start, please read this section to choose the right branch for you. The compatibility between the API and NebulaGraph service can be found in [How to choose nebula-python](#How-to-choose-nebula-python). The current master branch is compatible with NebulaGraph 3.x.
Expand All @@ -13,24 +15,24 @@ Before you start, please read this section to choose the right branch for you. T
|
|-- nebula3 // client code
| |-- fbthrift // the fbthrift lib code
| |-- common
| |-- data
| |-- graph
| |-- meta
| |-- common
| |-- data
| |-- graph
| |-- meta
| |-- net // the net code for graph client
| |-- storage
| |-- storage
| |-- Config.py // the pool config
| |__ Exception.py // the define exception
|
|
|-- examples
| |-- GraphClientMultiThreadExample.py // the multi thread example
| |-- GraphClientSimpleExample.py // the simple example
| |__ ScanVertexEdgeExample.py
| |__ ScanVertexEdgeExample.py
|
|-- tests // the test code
|
|
|-- setup.py // used to install or package
|
|
|__ README.md // the introduction of nebula3-python
```
Expand Down Expand Up @@ -154,7 +156,7 @@ connection_pool.close()

## Quick example to use storage-client to scan vertex and edge

You should make sure the scan client can connect to the address of storage which see from `SHOW HOSTS`
You should make sure the scan client can connect to the address of storage which see from `SHOW HOSTS`

```python
from nebula3.mclient import MetaCache, HostAddr
Expand Down Expand Up @@ -182,7 +184,7 @@ while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)

resp = graph_storage_client.scan_edge(
space_name='ScanSpace',
edge_name='friend')
Expand All @@ -195,16 +197,16 @@ while resp.has_next():
## How to choose nebula-python

| Nebula-Python Version | NebulaGraph Version |
|---|---|
| 1.0 | 1.x |
| 2.0.0 | 2.0.0/2.0.1 |
| 2.5.0 | 2.5.0 |
| 2.6.0 | 2.6.0/2.6.1 |
| 3.0.0 | 3.0.0 |
| 3.1.0 | 3.1.0 |
| 3.3.0 | 3.3.0 |
| 3.4.0 | >=3.4.0 |
| master | master |
| --------------------- | ------------------- |
| 1.0 | 1.x |
| 2.0.0 | 2.0.0/2.0.1 |
| 2.5.0 | 2.5.0 |
| 2.6.0 | 2.6.0/2.6.1 |
| 3.0.0 | 3.0.0 |
| 3.1.0 | 3.1.0 |
| 3.3.0 | 3.3.0 |
| 3.4.0 | >=3.4.0 |
| master | master |

## How to contribute to nebula-python

Expand All @@ -215,18 +217,25 @@ git clone https://github.com/{username}/nebula-python.git
cd nebula-python
```

Install the package in the editable mode, then install all the dev dependencies:
We use [PMD](https://github.com/pdm-project/pdm) to manage the package, install it first:

```
pipx install pdm
```

Visit the [PDM documentation](https://pdm-project.org) for alternative installation methods.

Install the package and all dev dependencies:
```
pip install -e .
pip install -r requirements/dev.txt
pdm install
```

Make sure the Nebula server in running, then run the tests with pytest:
```
pytest
pdm test
```
Using the default formatter with [black](https://github.com/psf/black).

Please run `make fmt` to format python code before submitting.
Please run `pdm fmt` to format python code before submitting.

See [How to contribute](https://github.com/vesoft-inc/nebula-community/blob/master/Contributors/how-to-contribute.md) for the general process of contributing to Nebula projects.
1 change: 1 addition & 0 deletions example/FormatResp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pandas as pd
import prettytable

from nebula3.data.DataObject import Value, ValueWrapper
from nebula3.data.ResultSet import ResultSet

Expand Down
Loading

0 comments on commit b63cd38

Please sign in to comment.