Skip to content

Commit

Permalink
add black (#178)
Browse files Browse the repository at this point in the history
* add black

* fix typo

* fix format error
  • Loading branch information
HarrisChu authored Nov 25, 2021
1 parent f17120b commit df11c01
Show file tree
Hide file tree
Showing 30 changed files with 1,266 additions and 851 deletions.
66 changes: 33 additions & 33 deletions .github/workflows/deploy_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@ jobs:
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel twine
pip install -r requirements/dev.txt
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install setuptools wheel twine
pip install -r requirements/dev.txt
- name: Test with pytest
run: |
docker-compose up -d
sleep 45
pytest -s -v -k "not TestSSLConnection and not TestSSLConnectionSelfSigned"
docker-compose down -v
working-directory: tests
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnection
working-directory: tests
- name: Test self-signed SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnectionSelfSigned
working-directory: tests
- name: Test with pytest
run: |
docker-compose up -d
sleep 45
pytest -s -v -k "not TestSSLConnection and not TestSSLConnectionSelfSigned"
docker-compose down -v
working-directory: tests
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnection
working-directory: tests
- name: Test self-signed SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnectionSelfSigned
working-directory: tests

- 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/*
- 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/*
64 changes: 33 additions & 31 deletions .github/workflows/run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Test ci

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
schedule:
- cron: '0 6 * * *'
- cron: "0 6 * * *"

jobs:
ci:
Expand All @@ -17,31 +17,33 @@ jobs:
python-version: [3.6, 3.7]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/dev.txt
- name: Test with pytest
run: |
docker-compose up -d
sleep 45
pytest -s -v -k "not TestSSLConnection and not TestSSLConnectionSelfSigned"
docker-compose down -v
working-directory: tests
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnection
working-directory: tests
- name: Test self-signed SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnectionSelfSigned
working-directory: tests
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: lint
run: make fmt-check
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/dev.txt
- name: Test with pytest
run: |
docker-compose up -d
sleep 45
pytest -s -v -k "not TestSSLConnection and not TestSSLConnectionSelfSigned"
docker-compose down -v
working-directory: tests
- name: Test SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnection
working-directory: tests
- name: Test self-signed SSL connection with pytest
run: |
enable_ssl=true docker-compose up -d
sleep 45
pytest -s -v test_ssl_connection.py::TestSSLConnectionSelfSigned
working-directory: tests
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.

.PHONY: fmt

LINUX_BLACK = ~/.local/bin/black
MAC_BLACK = black
FMT_EXCLUDE = --extend-exclude nebula2/common/\|nebula2/storage/\|nebula2/graph/\|nebula2/meta\|nebula2/common\|nebula2/fbthrift/

fmt:
pip install --user black
@if [ -x $(LINUX_BLACK) ];then \
$(LINUX_BLACK) -S $(FMT_EXCLUDE) .; \
else \
$(MAC_BLACK) -S $(FMT_EXCLUDE) .; \
fi

fmt-check:
pip install --user black
@if [ -x $(LINUX_BLACK) ];then \
$(LINUX_BLACK) -S --check $(FMT_EXCLUDE) .; \
else \
$(MAC_BLACK) -S --check $(FMT_EXCLUDE) . ; \
fi
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,9 @@ while resp.has_next():
| 2.0.0rc1 | 2.0.0-rc1 |
| 2.0.0 | 2.0.0/2.0.1 |
| 2.5.0 | 2.5.0 |

## Contributing

Using the default formatter with [black](https://github.com/psf/black).

Please run `make fmt` to format python code.
62 changes: 39 additions & 23 deletions example/GraphClientMultiThreadExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,68 @@ def main_test():
client = None
try:
space_name = 'space_' + threading.current_thread().getName()
print('thread name: %s, space_name : %s' %
(threading.current_thread().getName(), space_name))
print(
'thread name: %s, space_name : %s'
% (threading.current_thread().getName(), space_name)
)
# Get one gclient
client = connection_pool.get_session('root', 'nebula')
assert client is not None

# Create space mySpace and schema
resp = client.execute('CREATE SPACE IF NOT EXISTS {}; USE {};'
'CREATE TAG IF NOT EXISTS person(name string, age int);'
'CREATE EDGE IF NOT EXISTS like(likeness double);'
.format(space_name, space_name))
resp = client.execute(
'CREATE SPACE IF NOT EXISTS {}; USE {};'
'CREATE TAG IF NOT EXISTS person(name string, age int);'
'CREATE EDGE IF NOT EXISTS like(likeness double);'.format(
space_name, space_name
)
)
assert resp.is_succeeded(), resp.error_msg()

time.sleep(6)

# Insert vertexes
client.execute('INSERT VERTEX person(name, age) VALUES '
'\'Bob\':(\'Bob\', 10), '
'\'Lily\':(\'Lily\', 9), '
'\'Tom\':(\'Tom\', 10), '
'\'Jerry\':(\'Jerry\', 13), '
'\'John\':(\'John\', 11)')
client.execute(
'INSERT VERTEX person(name, age) VALUES '
'\'Bob\':(\'Bob\', 10), '
'\'Lily\':(\'Lily\', 9), '
'\'Tom\':(\'Tom\', 10), '
'\'Jerry\':(\'Jerry\', 13), '
'\'John\':(\'John\', 11)'
)

assert resp.is_succeeded(), resp.error_msg()

# Insert edges
client.execute('INSERT EDGE like(likeness) VALUES '
'\'Bob\'->\'Lily\':(80.0), '
'\'Bob\'->\'Tom\':(70.0), '
'\'Lily\'->\'Jerry\':(84.0), '
'\'Tom\'->\'Jerry\':(68.3), '
'\'Bob\'->\'John\':(97.2)')
client.execute(
'INSERT EDGE like(likeness) VALUES '
'\'Bob\'->\'Lily\':(80.0), '
'\'Bob\'->\'Tom\':(70.0), '
'\'Lily\'->\'Jerry\':(84.0), '
'\'Tom\'->\'Jerry\':(68.3), '
'\'Bob\'->\'John\':(97.2)'
)

# Query data
query_resp = client.execute('GO FROM \"Bob\" OVER like YIELD $^.person.name, '
'$^.person.age, like.likeness')
query_resp = client.execute(
'GO FROM \"Bob\" OVER like YIELD $^.person.name, '
'$^.person.age, like.likeness'
)
if not query_resp.is_succeeded():
print('Execute failed: %s' % query_resp.error_msg())
exit(1)

# Print the result of query
print(' \n====== The query result of thread[%s]======\n '
% threading.current_thread().getName())
print(
' \n====== The query result of thread[%s]======\n '
% threading.current_thread().getName()
)
print_resp(query_resp)

except Exception as x:
print(x)
import traceback

print(traceback.format_exc())
finally:
if client is not None:
Expand All @@ -89,7 +103,9 @@ def main_test():
for count in range(0, 3):
threads = list()
for i in range(0, 4):
threads.append(threading.Thread(target=main_test, name='thread{}'.format(i)))
threads.append(
threading.Thread(target=main_test, name='thread{}'.format(i))
)

for thread in threads:
thread.start()
Expand Down
15 changes: 9 additions & 6 deletions example/GraphClientSimpleExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@
json_obj = json.loads(resp_json)
print(json.dumps(json_obj, indent=2, sort_keys=True))

client.execute('CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30)); USE test;'
'CREATE TAG IF NOT EXISTS person(name string, age int);'
'CREATE EDGE like (likeness double);')
client.execute(
'CREATE SPACE IF NOT EXISTS test(vid_type=FIXED_STRING(30)); USE test;'
'CREATE TAG IF NOT EXISTS person(name string, age int);'
'CREATE EDGE like (likeness double);'
)

# insert data need to sleep after create schema
time.sleep(6)

# insert vertex
resp = client.execute(
'INSERT VERTEX person(name, age) VALUES "Bob":("Bob", 10), "Lily":("Lily", 9)')
'INSERT VERTEX person(name, age) VALUES "Bob":("Bob", 10), "Lily":("Lily", 9)'
)
assert resp.is_succeeded(), resp.error_msg()

# insert edges
resp = client.execute(
'INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);')
resp = client.execute('INSERT EDGE like(likeness) VALUES "Bob"->"Lily":(80.0);')
assert resp.is_succeeded(), resp.error_msg()

resp = client.execute('FETCH PROP ON person "Bob" YIELD vertex as node')
Expand All @@ -64,6 +66,7 @@

except Exception as x:
import traceback

print(traceback.format_exc())
if client is not None:
client.release()
Expand Down
Loading

0 comments on commit df11c01

Please sign in to comment.