Skip to content

Commit

Permalink
Merge branch 'master' into build-package
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech authored Oct 10, 2024
2 parents c10bd4d + aa48568 commit f631f71
Show file tree
Hide file tree
Showing 29 changed files with 276 additions and 75 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# pre-commit is a tool to perform a predefined set of tasks manually and/or
# automatically before git commits are made.
#
# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level
#
# Common tasks
#
# - Register git hooks: pre-commit install
# - Run on all files: pre-commit run --all-files
#
# These pre-commit hooks are run as CI.
#
# NOTE: if it can be avoided, add configs/args in pyproject.toml or below instead of creating a new `.config.file`.
# https://pre-commit.ci/#configuration
ci:
autoupdate_schedule: monthly
autofix_commit_msg: |
[pre-commit.ci] Apply automatic pre-commit fixes
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: end-of-file-fixer
exclude: '\.svg$'
- id: trailing-whitespace
exclude: '\.svg$'
- id: check-json
- id: check-yaml
args: [--allow-multiple-documents, --unsafe]
- id: check-toml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
hooks:
- id: ruff
args: ["--fix"]
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,36 @@ All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Using `pre-commit`

To enforce style and coding standards, this repository uses
[`pre-commit`](https://pre-commit.com/). To get started:

```shell
pip install pre-commit
pre-commit install
```

### Run pre-commit on all files

By default, `pre-commit` will run its checks on files that have been modified in
a commit. To instead run it on all files, use this command:

```console
$ pre-commit run --all-files

# Alternatively
$ pre-commit run -a
```

### Skip the pre-commit checks

Run the following command:

```console
$ git commit --no-verify
```

Be aware the pre-commit checks are run on CI, so any violations will need to be
fixed before code gets merged.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
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.
limitations under the License.
20 changes: 19 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@

## Bug Fixed and Other Changes

# Version 1.16.0

## Major Features and Improvements

* N/A

## Breaking Changes

* N/A

## Deprecations

* N/A

## Bug Fixed and Other Changes

* N/A

# Version 1.15.0

## Major Features and Improvements
Expand Down Expand Up @@ -818,4 +836,4 @@
## Breaking changes
## Deprecations
## Deprecations
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ services:
environment:
PYTHON_VERSION: 311
volumes:
- .:/build:delegated
- .:/build:delegated
1 change: 1 addition & 0 deletions g3doc/get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ The list of `schema_version` used in MLMD releases are:

ml-metadata (MLMD) | schema_version
------------------ | --------------
1.16.0 | 10
1.15.0 | 10
1.14.0 | 10
1.13.1 | 10
Expand Down
2 changes: 1 addition & 1 deletion ml_metadata/.bazelversion
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# 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.
6.1.0
6.1.0
12 changes: 7 additions & 5 deletions ml_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
from ml_metadata import proto

# Import metadata_store API.
from ml_metadata.metadata_store import downgrade_schema
from ml_metadata.metadata_store import ListOptions
from ml_metadata.metadata_store import MetadataStore
from ml_metadata.metadata_store import OrderByField
from ml_metadata.metadata_store import (
ListOptions,
MetadataStore,
OrderByField,
downgrade_schema,
)

# Import version string.
from ml_metadata.version import __version__

except ImportError as err:
import sys
sys.stderr.write('Error importing: {}'.format(err))
sys.stderr.write(f'Error importing: {err}')
# pylint: enable=g-import-not-at-top
1 change: 0 additions & 1 deletion ml_metadata/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def make_exception(message: str, error_code: int):
Returns:
An exception.
"""

try:
exc_type = exception_type_from_error_code(error_code)
# log internal backend engine errors only.
Expand Down
6 changes: 3 additions & 3 deletions ml_metadata/metadata_store/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ cc_library(
":metadata_access_object_base",
":query_executor",
"@com_google_protobuf//:protobuf",

"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
Expand Down Expand Up @@ -265,7 +265,7 @@ cc_library(
":metadata_source",
":query_executor",
"@com_google_protobuf//:protobuf",

"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down Expand Up @@ -993,7 +993,7 @@ cc_library(
":query_config_executor",
":query_executor",
"@com_google_protobuf//:protobuf",

"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down
10 changes: 6 additions & 4 deletions ml_metadata/metadata_store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Init module for ML Metadata."""
from ml_metadata.metadata_store.metadata_store import downgrade_schema
from ml_metadata.metadata_store.metadata_store import ListOptions
from ml_metadata.metadata_store.metadata_store import MetadataStore
from ml_metadata.metadata_store.metadata_store import OrderByField
from ml_metadata.metadata_store.metadata_store import (
ListOptions,
MetadataStore,
OrderByField,
downgrade_schema,
)
24 changes: 13 additions & 11 deletions ml_metadata/metadata_store/metadata_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
import time
from typing import Any, Iterable, List, Optional, Sequence, Tuple

from absl import logging
import attr
import grpc
from absl import logging

from ml_metadata import errors
from ml_metadata import proto
from ml_metadata.metadata_store.pywrap.metadata_store_extension import metadata_store as metadata_store_serialized
from ml_metadata.proto import metadata_store_pb2
from ml_metadata.proto import metadata_store_service_pb2
from ml_metadata.proto import metadata_store_service_pb2_grpc

from ml_metadata import errors, proto
from ml_metadata.metadata_store.pywrap.metadata_store_extension import (
metadata_store as metadata_store_serialized,
)
from ml_metadata.proto import (
metadata_store_pb2,
metadata_store_service_pb2,
metadata_store_service_pb2_grpc,
)

# Max number of results for one call.
MAX_NUM_RESULT = 100
Expand Down Expand Up @@ -62,7 +64,7 @@ class OrderByField(enum.Enum):


@attr.s(auto_attribs=True)
class ListOptions(object):
class ListOptions:
"""Defines the available options when listing nodes.
Attributes:
Expand All @@ -84,14 +86,14 @@ class ListOptions(object):
filter_query: Optional[str] = None


class ExtraOptions(object):
class ExtraOptions:
"""Dummy Extra options to align with internal MetadataStore."""

def __init__(self, euc=None):
"""Initialize ExtraOptions."""


class MetadataStore(object):
class MetadataStore:
"""A store for the metadata."""

def __init__(self, config, enable_upgrade_migration: bool = False):
Expand Down
5 changes: 2 additions & 3 deletions ml_metadata/metadata_store/metadata_store_go_swig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static char *_swig_topofstack() {
}

/* This function does not work with Go 1.5 or later
static void *_swig_goallocate(size_t len) {
struct {
size_t len;
Expand All @@ -255,7 +255,7 @@ static void _swig_gopanic(const char *p) {


/* This function does not work with Go 1.5 or later
static _gostring_ _swig_makegostring(const char *p, size_t l) {
_gostring_ ret;
ret.p = (char*)_swig_goallocate(l + 1);
Expand Down Expand Up @@ -1546,4 +1546,3 @@ _gostring_ _wrap_ErrorMessage_metadata_store_go_wrap_111d7b2874b915fe(
#ifdef __cplusplus
}
#endif

12 changes: 6 additions & 6 deletions ml_metadata/metadata_store/metadata_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import uuid
import pytest

from absl.testing import absltest
from absl.testing import parameterized
from absl import flags
from absl.testing import absltest, parameterized

import ml_metadata as mlmd
from ml_metadata import errors
Expand Down Expand Up @@ -97,13 +97,13 @@ def _create_example_context_type(type_name, type_version=None):
class MetadataStoreTest(parameterized.TestCase):

def _get_test_type_name(self):
return "test_type_{}".format(uuid.uuid4())
return f"test_type_{uuid.uuid4()}"

def _get_test_type_version(self):
return "test_version_{}".format(uuid.uuid4())
return f"test_version_{uuid.uuid4()}"

def _get_test_db_name(self):
return "test_mlmd_{}.db".format(uuid.uuid4())
return f"test_mlmd_{uuid.uuid4()}.db"

def test_unset_connection_config(self):
connection_config = metadata_store_pb2.ConnectionConfig()
Expand Down Expand Up @@ -1800,7 +1800,7 @@ def test_get_nodes_by_filter_query(self, create_type_fn, put_type_fn,

nodes = []
for i in range(200):
nodes.append(node_cls(name="node_{}".format(i), type_id=type_id))
nodes.append(node_cls(name=f"node_{i}", type_id=type_id))
nodes[i].custom_properties["p"].int_value = i
node_ids = put_nodes_fn(store, nodes)

Expand Down
7 changes: 4 additions & 3 deletions ml_metadata/metadata_store/mlmd_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from typing import Union

from ml_metadata import errors
from ml_metadata.metadata_store.pywrap.metadata_store_extension import metadata_store as metadata_store_serialized
from ml_metadata.metadata_store.pywrap.metadata_store_extension import (
metadata_store as metadata_store_serialized,
)
from ml_metadata.proto import metadata_store_pb2
from ml_metadata.simple_types.proto import simple_types_pb2

Expand All @@ -32,7 +34,6 @@ def _make_exception(msg, error_code):
Returns:
An exception.
"""

try:
exc_type = errors.exception_type_from_error_code(error_code)
return exc_type(msg)
Expand All @@ -49,7 +50,7 @@ def _get_type_proto(
for execution_type in types.execution_types:
if execution_type.name == type_name:
return execution_type
raise _make_exception('Type name: {} is not found'.format(type_name),
raise _make_exception(f'Type name: {type_name} is not found',
errors.NOT_FOUND)


Expand Down
Loading

0 comments on commit f631f71

Please sign in to comment.