FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use YAPF for formatting. · google/python-spanner-orm@16bfe2d · GitHub

Commit 16bfe2d

Browse files
committed
Use YAPF for formatting.
1 parent ab554c9 commit 16bfe2d

18 files changed

Lines changed: 219 additions & 201 deletions

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ pip install pytype
209209
pytype -V 3.7 spanner_orm -d import-error
210210
```
211211

212+
To check formatting, run (change `--diff` to `--in-place` to fix formatting):
213+
214+
```
215+
pip install yapf
216+
yapf --diff --recursive --parallel .
217+
```
218+
212219
Then run tests with:
213220

214221
```

‎setup.cfg‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[yapf]
2+
based_on_style = yapf

‎spanner_orm/__init__.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
1615
"""Sets up shortcuts for imports from the library."""
1716
import logging
1817

‎spanner_orm/admin/scripts.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def main(as_module: bool = False) -> None:
4545
# 'subcommand' is actually required, but required subparsers are not supported
4646
# for Python < 3.7.
4747
subparsers = parser.add_subparsers(
48-
dest='subcommand',
49-
title='subcommands',
50-
description='valid subcommands')
48+
dest='subcommand', title='subcommands', description='valid subcommands')
5149

5250
generate_parser = subparsers.add_parser(
5351
'generate', help='Generate a new migration')

‎spanner_orm/api.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
CallableReturn = TypeVar('CallableReturn')
2828

29+
2930
class SpannerRetryableApi(abc.ABC):
31+
3032
def _ensure_session(self, api_method, *args, **kwargs):
3133
try:
3234
return api_method(*args, **kwargs)
@@ -69,6 +71,7 @@ def _run_read_only(self, method, *args, **kwargs):
6971
with self._connection.snapshot(multi_use=True) as snapshot:
7072
return method(snapshot, *args, **kwargs)
7173

74+
7275
class SpannerWriteApi(SpannerRetryableApi):
7376
"""Handles sending write requests to Spanner."""
7477

@@ -95,8 +98,8 @@ def run_write(self, method: Callable[..., CallableReturn], *args: Any,
9598
Returns:
9699
The return value from `method` will be returned from this method
97100
"""
98-
return self._ensure_session(
99-
self._connection.run_in_transaction, method, *args, **kwargs)
101+
return self._ensure_session(self._connection.run_in_transaction, method,
102+
*args, **kwargs)
100103

101104

102105
class SpannerConnection:
@@ -120,7 +123,8 @@ def __init__(self,
120123

121124
def connect(self):
122125
"""Establish a new connection to the specified Spanner database."""
123-
client = spanner.Client(project=self._project, credentials=self._credentials)
126+
client = spanner.Client(
127+
project=self._project, credentials=self._credentials)
124128
instance = client.instance(self._instance)
125129
self.database = instance.database(
126130
self._database, pool=self._pool, ddl_statements=self._create_ddl or ())
@@ -140,12 +144,12 @@ def _connection(self):
140144
_api = None # type: Optional[SpannerApi]
141145

142146

143-
def connect(instance: str,
144-
database: str,
145-
project: Optional[str] = None,
146-
credentials: Optional[auth_credentials.Credentials] = None,
147-
pool: Optional[spanner_pool.AbstractSessionPool] = None
148-
) -> SpannerApi:
147+
def connect(
148+
instance: str,
149+
database: str,
150+
project: Optional[str] = None,
151+
credentials: Optional[auth_credentials.Credentials] = None,
152+
pool: Optional[spanner_pool.AbstractSessionPool] = None) -> SpannerApi:
149153
"""Connects to the Spanner database and sets the global spanner_api."""
150154
connection = SpannerConnection(
151155
instance, database, project=project, credentials=credentials, pool=pool)

‎spanner_orm/condition.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ def __init__(
431431
self.foreign_key_relation = foreign_key_relation
432432
if isinstance(relation_or_name, relationship.Relationship):
433433
if foreign_key_relation:
434-
raise ValueError(
435-
'Must pass foreign key relation if ''`foreign_key_relation=True`.')
434+
raise ValueError('Must pass foreign key relation if '
435+
'`foreign_key_relation=True`.')
436436
self.name = relation_or_name.name
437437
self.relation = relation_or_name
438438
elif isinstance(relation_or_name,
@@ -465,9 +465,9 @@ def conditions(self) -> List[Condition]:
465465
for pair in self.relation.constraint.columns.items():
466466
referencing_column, referenced_column = pair
467467
relation_conditions.append(
468-
ColumnsEqualCondition(referenced_column, self.model_class,
469-
referencing_column))
470-
468+
ColumnsEqualCondition(referenced_column, self.model_class,
469+
referencing_column))
470+
471471
else:
472472
for constraint in self.relation.constraints:
473473
# This is backward from what you might imagine because the condition
@@ -940,8 +940,7 @@ def includes(relation: Union[relationship.Relationship,
940940
Returns:
941941
A Condition subclass that will be used in the query
942942
"""
943-
return IncludesCondition(
944-
relation, conditions, foreign_key_relation)
943+
return IncludesCondition(relation, conditions, foreign_key_relation)
945944

946945

947946
def in_list(column: Union[field.Field, str],

‎spanner_orm/foreign_key_relationship.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class ForeignKeyRelationshipConstraint:
3030
class ForeignKeyRelationship(object):
3131
"""Helps define a foreign key relationship between two models."""
3232

33-
def __init__(self,
34-
referenced_table_name: str,
35-
columns: Mapping[str, str]):
33+
def __init__(self, referenced_table_name: str, columns: Mapping[str, str]):
3634
"""Creates a ForeignKeyRelationship.
3735
3836
Args:

‎spanner_orm/metadata.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ def __init__(self,
4545
table: Optional[str] = None,
4646
fields: Optional[Dict[str, field.Field]] = None,
4747
relations: Optional[Dict[str, relationship.Relationship]] = None,
48-
foreign_key_relations: Optional[
49-
Dict[
48+
foreign_key_relations: Optional[Dict[
5049
str,
51-
foreign_key_relationship.ForeignKeyRelationship]
52-
] = None,
50+
foreign_key_relationship.ForeignKeyRelationship]] = None,
5351
indexes: Optional[Dict[str, index.Index]] = None,
5452
interleaved: Optional[str] = None,
5553
model_class: Optional[Type[Any]] = None):

‎spanner_orm/model.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,9 @@ def __new__(mcs, name: str, bases: Any, attrs: Dict[str, Any], **kwargs: Any):
8080
return cls
8181

8282
def __getattr__(
83-
cls,
84-
name: str) -> Union[
85-
field.Field,
86-
relationship.Relationship,
87-
foreign_key_relationship.ForeignKeyRelationship,
88-
index.Index]:
83+
cls, name: str
84+
) -> Union[field.Field, relationship.Relationship,
85+
foreign_key_relationship.ForeignKeyRelationship, index.Index]:
8986
# Unclear why pylint doesn't like this
9087
# pylint: disable=unsupported-membership-test
9188
if name in cls.fields:
@@ -131,7 +128,6 @@ def foreign_key_relations(
131128
cls) -> Dict[str, foreign_key_relationship.ForeignKeyRelationship]:
132129
return cls.meta.foreign_key_relations
133130

134-
135131
@property
136132
def fields(cls) -> Dict[str, field.Field]:
137133
return cls.meta.fields
@@ -603,7 +599,6 @@ def _execute_write(
603599
else:
604600
return cls.spanner_api().run_write(db_api, *args)
605601

606-
607602
def __setattr__(self, name: str, value: Any) -> None:
608603
if name in self._relations:
609604
raise AttributeError(name)

‎spanner_orm/testlib/spanner_emulator/emulator.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def _start(self) -> None:
9595
emulator_binary_path = os.environ[_EMULATOR_BINARY_PATH_ENV_VAR]
9696
except KeyError as key_error:
9797
raise ValueError(
98-
f'Please set the environment variable {_EMULATOR_BINARY_PATH_ENV_VAR} '
99-
'to a binary with the Cloud Spanner Emulator. For more info, see '
100-
'https://github.com/GoogleCloudPlatform/cloud-spanner-emulator.'
98+
f'Please set the environment variable {_EMULATOR_BINARY_PATH_ENV_VAR} '
99+
'to a binary with the Cloud Spanner Emulator. For more info, see '
100+
'https://github.com/GoogleCloudPlatform/cloud-spanner-emulator.'
101101
) from key_error
102102

103103
self._process = subprocess.Popen([

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL