| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,6 +209,13 @@ pip install pytype | |||
| 209 | 209 | pytype -V 3.7 spanner_orm -d import-error | |
| 210 | 210 | ``` | |
| 211 | 211 | ||
| 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 | + | ||
| 212 | 219 | Then run tests with: | |
| 213 | 220 | ||
| 214 | 221 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + [yapf] | ||
| 2 | + based_on_style = yapf | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,6 @@ | |||
| 12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | 13 | # See the License for the specific language governing permissions and | |
| 14 | 14 | # limitations under the License. | |
| 15 | - | ||
| 16 | 15 | """Sets up shortcuts for imports from the library.""" | |
| 17 | 16 | import logging | |
| 18 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,9 +45,7 @@ def main(as_module: bool = False) -> None: | |||
| 45 | 45 | # 'subcommand' is actually required, but required subparsers are not supported | |
| 46 | 46 | # for Python < 3.7. | |
| 47 | 47 | subparsers = parser.add_subparsers( | |
| 48 | - dest='subcommand', | ||
| 49 | - title='subcommands', | ||
| 50 | - description='valid subcommands') | ||
| 48 | + dest='subcommand', title='subcommands', description='valid subcommands') | ||
| 51 | 49 | ||
| 52 | 50 | generate_parser = subparsers.add_parser( | |
| 53 | 51 | 'generate', help='Generate a new migration') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,9 @@ | |||
| 26 | 26 | ||
| 27 | 27 | CallableReturn = TypeVar('CallableReturn') | |
| 28 | 28 | ||
| 29 | + | ||
| 29 | 30 | class SpannerRetryableApi(abc.ABC): | |
| 31 | + | ||
| 30 | 32 | def _ensure_session(self, api_method, *args, **kwargs): | |
| 31 | 33 | try: | |
| 32 | 34 | return api_method(*args, **kwargs) | |
@@ -69,6 +71,7 @@ def _run_read_only(self, method, *args, **kwargs): | |||
| 69 | 71 | with self._connection.snapshot(multi_use=True) as snapshot: | |
| 70 | 72 | return method(snapshot, *args, **kwargs) | |
| 71 | 73 | ||
| 74 | + | ||
| 72 | 75 | class SpannerWriteApi(SpannerRetryableApi): | |
| 73 | 76 | """Handles sending write requests to Spanner.""" | |
| 74 | 77 | ||
@@ -95,8 +98,8 @@ def run_write(self, method: Callable[..., CallableReturn], *args: Any, | |||
| 95 | 98 | Returns: | |
| 96 | 99 | The return value from `method` will be returned from this method | |
| 97 | 100 | """ | |
| 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) | ||
| 100 | 103 | ||
| 101 | 104 | ||
| 102 | 105 | class SpannerConnection: | |
@@ -120,7 +123,8 @@ def __init__(self, | |||
| 120 | 123 | ||
| 121 | 124 | def connect(self): | |
| 122 | 125 | """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) | ||
| 124 | 128 | instance = client.instance(self._instance) | |
| 125 | 129 | self.database = instance.database( | |
| 126 | 130 | self._database, pool=self._pool, ddl_statements=self._create_ddl or ()) | |
@@ -140,12 +144,12 @@ def _connection(self): | |||
| 140 | 144 | _api = None # type: Optional[SpannerApi] | |
| 141 | 145 | ||
| 142 | 146 | ||
| 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: | ||
| 149 | 153 | """Connects to the Spanner database and sets the global spanner_api.""" | |
| 150 | 154 | connection = SpannerConnection( | |
| 151 | 155 | instance, database, project=project, credentials=credentials, pool=pool) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -431,8 +431,8 @@ def __init__( | |||
| 431 | 431 | self.foreign_key_relation = foreign_key_relation | |
| 432 | 432 | if isinstance(relation_or_name, relationship.Relationship): | |
| 433 | 433 | 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`.') | ||
| 436 | 436 | self.name = relation_or_name.name | |
| 437 | 437 | self.relation = relation_or_name | |
| 438 | 438 | elif isinstance(relation_or_name, | |
@@ -465,9 +465,9 @@ def conditions(self) -> List[Condition]: | |||
| 465 | 465 | for pair in self.relation.constraint.columns.items(): | |
| 466 | 466 | referencing_column, referenced_column = pair | |
| 467 | 467 | 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 | + | ||
| 471 | 471 | else: | |
| 472 | 472 | for constraint in self.relation.constraints: | |
| 473 | 473 | # This is backward from what you might imagine because the condition | |
@@ -940,8 +940,7 @@ def includes(relation: Union[relationship.Relationship, | |||
| 940 | 940 | Returns: | |
| 941 | 941 | A Condition subclass that will be used in the query | |
| 942 | 942 | """ | |
| 943 | - return IncludesCondition( | ||
| 944 | - relation, conditions, foreign_key_relation) | ||
| 943 | + return IncludesCondition(relation, conditions, foreign_key_relation) | ||
| 945 | 944 | ||
| 946 | 945 | ||
| 947 | 946 | def in_list(column: Union[field.Field, str], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,9 +30,7 @@ class ForeignKeyRelationshipConstraint: | |||
| 30 | 30 | class ForeignKeyRelationship(object): | |
| 31 | 31 | """Helps define a foreign key relationship between two models.""" | |
| 32 | 32 | ||
| 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]): | ||
| 36 | 34 | """Creates a ForeignKeyRelationship. | |
| 37 | 35 | ||
| 38 | 36 | Args: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,11 +45,9 @@ def __init__(self, | |||
| 45 | 45 | table: Optional[str] = None, | |
| 46 | 46 | fields: Optional[Dict[str, field.Field]] = None, | |
| 47 | 47 | relations: Optional[Dict[str, relationship.Relationship]] = None, | |
| 48 | - foreign_key_relations: Optional[ | ||
| 49 | - Dict[ | ||
| 48 | + foreign_key_relations: Optional[Dict[ | ||
| 50 | 49 | str, | |
| 51 | - foreign_key_relationship.ForeignKeyRelationship] | ||
| 52 | - ] = None, | ||
| 50 | + foreign_key_relationship.ForeignKeyRelationship]] = None, | ||
| 53 | 51 | indexes: Optional[Dict[str, index.Index]] = None, | |
| 54 | 52 | interleaved: Optional[str] = None, | |
| 55 | 53 | model_class: Optional[Type[Any]] = None): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,12 +80,9 @@ def __new__(mcs, name: str, bases: Any, attrs: Dict[str, Any], **kwargs: Any): | |||
| 80 | 80 | return cls | |
| 81 | 81 | ||
| 82 | 82 | 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]: | ||
| 89 | 86 | # Unclear why pylint doesn't like this | |
| 90 | 87 | # pylint: disable=unsupported-membership-test | |
| 91 | 88 | if name in cls.fields: | |
@@ -131,7 +128,6 @@ def foreign_key_relations( | |||
| 131 | 128 | cls) -> Dict[str, foreign_key_relationship.ForeignKeyRelationship]: | |
| 132 | 129 | return cls.meta.foreign_key_relations | |
| 133 | 130 | ||
| 134 | - | ||
| 135 | 131 | @property | |
| 136 | 132 | def fields(cls) -> Dict[str, field.Field]: | |
| 137 | 133 | return cls.meta.fields | |
@@ -603,7 +599,6 @@ def _execute_write( | |||
| 603 | 599 | else: | |
| 604 | 600 | return cls.spanner_api().run_write(db_api, *args) | |
| 605 | 601 | ||
| 606 | - | ||
| 607 | 602 | def __setattr__(self, name: str, value: Any) -> None: | |
| 608 | 603 | if name in self._relations: | |
| 609 | 604 | raise AttributeError(name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,9 +95,9 @@ def _start(self) -> None: | |||
| 95 | 95 | emulator_binary_path = os.environ[_EMULATOR_BINARY_PATH_ENV_VAR] | |
| 96 | 96 | except KeyError as key_error: | |
| 97 | 97 | 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.' | ||
| 101 | 101 | ) from key_error | |
| 102 | 102 | ||
| 103 | 103 | self._process = subprocess.Popen([ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments