You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/10/28 18:38:12 UTC

[GitHub] [incubator-superset] betodealmeida opened a new pull request #11463: feat: create base class for export commands

betodealmeida opened a new pull request #11463:
URL: https://github.com/apache/incubator-superset/pull/11463


   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   All the export commands have basically the same methods for `__init__`, `run` and `validate`. I simplified their logic by creating a base `ExportModelsCommand` class implementing the common logic.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   N/A
   
   ### TEST PLAN
   <!--- What steps should be taken to verify the changes -->
   
   Added a new unit test, and verified that all unit tests pass.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] hughhhh commented on a change in pull request #11463: feat: create base class for export commands

Posted by GitBox <gi...@apache.org>.
hughhhh commented on a change in pull request #11463:
URL: https://github.com/apache/incubator-superset/pull/11463#discussion_r513888943



##########
File path: superset/importexport/commands/base.py
##########
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software 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.
+# isort:skip_file
+
+from datetime import datetime
+from datetime import timezone
+from typing import Iterator, List, Tuple
+
+import yaml
+from flask_appbuilder import Model
+
+from superset.commands.base import BaseCommand
+from superset.commands.exceptions import CommandException
+from superset.dao.base import BaseDAO
+from superset.utils.dict_import_export import IMPORT_EXPORT_VERSION
+
+
+class ExportModelsCommand(BaseCommand):
+
+    dao = BaseDAO
+    not_found = CommandException
+
+    def __init__(self, model_ids: List[int]):

Review comment:
       ```suggestion
   	def __init__(self, model_ids: List[int]) -> None:
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] hughhhh commented on a change in pull request #11463: feat: create base class for export commands

Posted by GitBox <gi...@apache.org>.
hughhhh commented on a change in pull request #11463:
URL: https://github.com/apache/incubator-superset/pull/11463#discussion_r513890283



##########
File path: superset/importexport/commands/base.py
##########
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software 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.
+# isort:skip_file
+
+from datetime import datetime
+from datetime import timezone
+from typing import Iterator, List, Tuple
+
+import yaml
+from flask_appbuilder import Model
+
+from superset.commands.base import BaseCommand
+from superset.commands.exceptions import CommandException
+from superset.dao.base import BaseDAO
+from superset.utils.dict_import_export import IMPORT_EXPORT_VERSION
+
+
+class ExportModelsCommand(BaseCommand):
+
+    dao = BaseDAO
+    not_found = CommandException
+
+    def __init__(self, model_ids: List[int]):
+        self.model_ids = model_ids
+
+        # this will be set when calling validate()
+        self._models: List[Model] = []
+
+    @staticmethod
+    def export(model: Model) -> Iterator[Tuple[str, str]]:
+        raise NotImplementedError("Subclasses MUST implement export")
+
+    def run(self) -> Iterator[Tuple[str, str]]:
+        self.validate()
+
+        metadata = {
+            "version": IMPORT_EXPORT_VERSION,
+            "type": self.dao.model_cls.__name__,  # type: ignore
+            "timestamp": datetime.now(tz=timezone.utc).isoformat(),
+        }
+        yield "metadata.yaml", yaml.safe_dump(metadata, sort_keys=False)

Review comment:
       make this constant at the top:
   `METADATA_FILE_NAME = "metadata.yaml"`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] codecov-io commented on pull request #11463: feat: create base class for export commands

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #11463:
URL: https://github.com/apache/incubator-superset/pull/11463#issuecomment-718163326


   # [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=h1) Report
   > Merging [#11463](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=desc) into [cleanup_export](https://codecov.io/gh/apache/incubator-superset/commit/0e3c99676b305a0601aea5229f289f57315e1ac2?el=desc) will **decrease** coverage by `0.94%`.
   > The diff coverage is `98.27%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-superset/pull/11463/graphs/tree.svg?width=650&height=150&src=pr&token=KsB0fHcx6l)](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=tree)
   
   ```diff
   @@                Coverage Diff                 @@
   ##           cleanup_export   #11463      +/-   ##
   ==================================================
   - Coverage           61.91%   60.97%   -0.95%     
   ==================================================
     Files                 864      419     -445     
     Lines               41047    26010   -15037     
     Branches             3693        0    -3693     
   ==================================================
   - Hits                25415    15860    -9555     
   + Misses              15453    10150    -5303     
   + Partials              179        0     -179     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | #javascript | `?` | |
   | #python | `60.97% <98.27%> (-0.39%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [superset/importexport/commands/base.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvaW1wb3J0ZXhwb3J0L2NvbW1hbmRzL2Jhc2UucHk=) | `96.87% <96.87%> (ø)` | |
   | [superset/charts/commands/export.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvY2hhcnRzL2NvbW1hbmRzL2V4cG9ydC5weQ==) | `94.11% <100.00%> (-1.24%)` | :arrow_down: |
   | [superset/dashboards/commands/export.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGFzaGJvYXJkcy9jb21tYW5kcy9leHBvcnQucHk=) | `93.75% <100.00%> (-1.38%)` | :arrow_down: |
   | [superset/databases/commands/export.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YWJhc2VzL2NvbW1hbmRzL2V4cG9ydC5weQ==) | `94.11% <100.00%> (-1.24%)` | :arrow_down: |
   | [superset/datasets/commands/export.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YXNldHMvY29tbWFuZHMvZXhwb3J0LnB5) | `93.93% <100.00%> (-1.72%)` | :arrow_down: |
   | [superset/databases/commands/create.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YWJhc2VzL2NvbW1hbmRzL2NyZWF0ZS5weQ==) | `31.91% <0.00%> (-59.58%)` | :arrow_down: |
   | [superset/views/database/mixins.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvdmlld3MvZGF0YWJhc2UvbWl4aW5zLnB5) | `59.64% <0.00%> (-21.06%)` | :arrow_down: |
   | [superset/db\_engine\_specs/mysql.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL215c3FsLnB5) | `79.59% <0.00%> (-12.25%)` | :arrow_down: |
   | [superset/databases/commands/update.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YWJhc2VzL2NvbW1hbmRzL3VwZGF0ZS5weQ==) | `85.71% <0.00%> (-8.17%)` | :arrow_down: |
   | [superset/databases/api.py](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree#diff-c3VwZXJzZXQvZGF0YWJhc2VzL2FwaS5weQ==) | `83.49% <0.00%> (-7.08%)` | :arrow_down: |
   | ... and [464 more](https://codecov.io/gh/apache/incubator-superset/pull/11463/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=footer). Last update [0e3c996...124fd59](https://codecov.io/gh/apache/incubator-superset/pull/11463?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org