Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint and add pre-commit #1261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/code_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install requirements
run: |
pip install -r requirements.txt
- name: Run pylint
shell: bash
run: |
make lint
- name: Run pre-commit
uses: pre-commit/[email protected]
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
exclude: "^docs/|/grpc_gen/|/.git/|/.tox/|/media/|/.pytest_cache/|^.idea/"
default_stages: [commit]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-xml
- id: check-executables-have-shebangs
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: check-symlinks
- id: detect-aws-credentials
args: [ '--allow-missing-credentials' ]
- id: detect-private-key
exclude: ^examples|(?:tests/ssl)/

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
hooks:
- id: pyupgrade
args: ['--py37-plus', '--keep-mock']

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
ci:
autoupdate_schedule: weekly
skip: []
submodules: false
129 changes: 86 additions & 43 deletions pymilvus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,107 @@
# or implied. See the License for the specific language governing permissions and limitations under
# the License.

from .client.stub import Milvus
from .client import __version__
from .client.prepare import Prepare
from .client.types import Status, DataType, RangeType, IndexType, Replica, Group, Shard, BulkInsertState
from .client.stub import Milvus
from .client.types import (
BulkInsertState,
DataType,
Group,
IndexType,
RangeType,
Replica,
Shard,
Status,
)
from .exceptions import (
ParamError,
ExceptionsMessage,
MilvusException,
MilvusUnavailableException,
ExceptionsMessage
ParamError,
)
from .client import __version__

from .settings import DEBUG_LOG_LEVEL, INFO_LOG_LEVEL, WARN_LOG_LEVEL, ERROR_LOG_LEVEL

from .orm import utility
from .orm.collection import Collection
from .orm.connections import connections, Connections

from .orm.connections import Connections, connections
from .orm.default_config import ENV_CONNECTION_CONF, DefaultConfig
from .orm.future import MutationFuture, SearchFuture
from .orm.index import Index
from .orm.partition import Partition
from .orm.role import Role
from .orm.schema import CollectionSchema, FieldSchema
from .orm.search import Hit, Hits, SearchResult
from .orm.utility import (
loading_progress,
index_building_progress,
wait_for_loading_complete,
wait_for_index_building_complete,
create_user,
delete_user,
do_bulk_insert,
drop_collection,
get_bulk_insert_state,
get_query_segment_info,
has_collection,
has_partition,
hybridts_to_datetime,
hybridts_to_unixtime,
index_building_progress,
list_bulk_insert_tasks,
list_collections,
drop_collection,
get_query_segment_info,
list_usernames,
load_balance,
mkts_from_hybridts, mkts_from_unixtime, mkts_from_datetime,
hybridts_to_unixtime, hybridts_to_datetime,
do_bulk_insert, get_bulk_insert_state, list_bulk_insert_tasks,
reset_password, create_user, update_password, delete_user, list_usernames,
loading_progress,
mkts_from_datetime,
mkts_from_hybridts,
mkts_from_unixtime,
reset_password,
update_password,
wait_for_index_building_complete,
wait_for_loading_complete,
)
from .settings import DEBUG_LOG_LEVEL, ERROR_LOG_LEVEL, INFO_LOG_LEVEL, WARN_LOG_LEVEL

from .orm import utility
from .orm.default_config import DefaultConfig, ENV_CONNECTION_CONF

from .orm.search import SearchResult, Hits, Hit
from .orm.schema import FieldSchema, CollectionSchema
from .orm.future import SearchFuture, MutationFuture
from .orm.role import Role

__all__ = [
'Collection', 'Index', 'Partition',
'connections',
'loading_progress', 'index_building_progress', 'wait_for_loading_complete', 'has_collection', 'has_partition',
'list_collections', 'wait_for_loading_complete', 'wait_for_index_building_complete', 'drop_collection',
'mkts_from_hybridts', 'mkts_from_unixtime', 'mkts_from_datetime',
'hybridts_to_unixtime', 'hybridts_to_datetime',
'reset_password', 'create_user', 'update_password', 'delete_user', 'list_usernames',
'SearchResult', 'Hits', 'Hit', 'Replica', 'Group', 'Shard',
'FieldSchema', 'CollectionSchema',
'SearchFuture', 'MutationFuture',
'utility', 'DefaultConfig', 'ExceptionsMessage', 'MilvusUnavailableException', 'BulkInsertState',
'Role',

'Milvus', 'Prepare', 'Status', 'DataType',
'MilvusException',
'__version__'
"Collection",
"Index",
"Partition",
"connections",
"loading_progress",
"index_building_progress",
"wait_for_loading_complete",
"has_collection",
"has_partition",
"list_collections",
"wait_for_loading_complete",
"wait_for_index_building_complete",
"drop_collection",
"mkts_from_hybridts",
"mkts_from_unixtime",
"mkts_from_datetime",
"hybridts_to_unixtime",
"hybridts_to_datetime",
"reset_password",
"create_user",
"update_password",
"delete_user",
"list_usernames",
"SearchResult",
"Hits",
"Hit",
"Replica",
"Group",
"Shard",
"FieldSchema",
"CollectionSchema",
"SearchFuture",
"MutationFuture",
"utility",
"DefaultConfig",
"ExceptionsMessage",
"MilvusUnavailableException",
"BulkInsertState",
"Role",
"Milvus",
"Prepare",
"Status",
"DataType",
"MilvusException",
"__version__",
]
34 changes: 22 additions & 12 deletions pymilvus/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import subprocess
import re
from pkg_resources import get_distribution, DistributionNotFound
import subprocess

from pkg_resources import DistributionNotFound, get_distribution


__version__ = '0.0.0.dev'
__version__ = "0.0.0.dev"

try:
__version__ = get_distribution('pymilvus').version
__version__ = get_distribution("pymilvus").version
except DistributionNotFound:
# package is not installed
pass


def get_commit(version="", short=True) -> str:
"""get commit return the commit for a specific version like `xxxxxx.dev12` """
"""get commit return the commit for a specific version like `xxxxxx.dev12`"""

version_info = r'((\d+)\.(\d+)\.(\d+))((rc)(\d+))?(\.dev(\d+))?'
version_info = r"((\d+)\.(\d+)\.(\d+))((rc)(\d+))?(\.dev(\d+))?"
# 2.0.0rc9.dev12
# ('2.0.0', '2', '0', '0', 'rc9', 'rc', '9', '.dev12', '12')
p = re.compile(version_info)
Expand All @@ -27,23 +29,31 @@ def get_commit(version="", short=True) -> str:
if match_version[7] is not None:
if match_version[4] is not None:
v = str(int(match_version[6]) - 1)
target_tag = 'v' + match_version[0] + match_version[5] + v
target_tag = "v" + match_version[0] + match_version[5] + v
else:
target_tag = 'v' + ".".join(str(int("".join(match_version[1:4])) - 1).split(""))
target_tag = "v" + ".".join(
str(int("".join(match_version[1:4])) - 1).split("")
)
target_num = int(match_version[-1])
elif match_version[4] is not None:
target_tag = 'v' + match_version[0] + match_version[4]
target_tag = "v" + match_version[0] + match_version[4]
target_num = 0
else:
target_tag = 'v' + match_version[0]
target_tag = "v" + match_version[0]
target_num = 0
else:
return f"Version: {target_v} isn't the right form"

try:
cmd = ['git', 'rev-list', '--reverse', '--ancestry-path', f'{target_tag}^..HEAD']
cmd = [
"git",
"rev-list",
"--reverse",
"--ancestry-path",
f"{target_tag}^..HEAD",
]
print(f"git cmd: {' '.join(cmd)}")
result = subprocess.check_output(cmd).decode('ascii').strip().split('\n')
result = subprocess.check_output(cmd).decode("ascii").strip().split("\n")

length = 7 if short else 40
return result[target_num][:length]
Expand Down
Loading