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

Add python typechecking for mypy on src/ci_workflow and tests/tests_ci_workflow #1582

Merged
merged 3 commits into from
Feb 2, 2022

Conversation

zelinh
Copy link
Member

@zelinh zelinh commented Feb 2, 2022

Description

pipenv run mypy src/ci_workflow tests/tests_ci_workflow runs without error

Issues Resolved

#1508

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@zelinh zelinh requested a review from a team as a code owner February 2, 2022 01:49
@dblock
Copy link
Member

dblock commented Feb 2, 2022

What's left after this one to add typechecking to the entire python codebase?

@peternied
Copy link
Member

We are tracking with meta issue, #1237, ~3 more PRs to go

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving so you can merge when you are ready, but there are a number of little issues that should be quick to clean up, or you could make a new PR if desired. Thanks!



class CiCheck(ABC):
def __init__(self, component, target, args=None):
def __init__(self, component: Any, target: CiTarget, args: Any = None) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, component: Any, target: CiTarget, args: Any = None) -> None:
def __init__(self, component: Component, target: CiTarget, args: Any = None) -> None:

Seems like component should be a Component type instead of any

@@ -23,6 +28,6 @@ class CiCheckDist(CiCheck):


class CiCheckSource(CiCheck):
def __init__(self, component, git_repo, target, args=None):
def __init__(self, component: Component, git_repo: GitRepository, target: CiTarget, args: Any = None) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make args more specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using CiArgs type for this args, however, for example CiCheckGradleDependencies inherits from this CiCheckSource isn't necessarily taking CiArgs input; it was just a simple string. This is the test case we have

def test_executes_gradle_command_with_arg(self):
check = CiCheckGradleDependenciesOpenSearchVersion(
component=MagicMock(),
git_repo=MagicMock(),
target=CiTarget(version="1.1.0", name="opensearch", snapshot=True),
args="plugin",
)

@@ -6,18 +6,22 @@

import logging
import re
from typing import Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 14 imports of Any, let's try to get this to zero or have an explanation for it. Even an untyped Dict/List is better than nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note; I'm OK with this as a follow up issue.



class CiCheckList(ABC):
def __init__(self, component, target):
def __init__(self, component: Any, target: CiTarget) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do component: Component?

from manifests.input_manifest import InputComponentFromDist, InputComponentFromSource


class CiCheckLists(ABC):
@classmethod
def from_component(self, component, target):
def from_component(self, component: Any, target: CiTarget) -> Any:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component: Component?

def __init__(self, manifest, args):

class CiManifest(ABC):
def __init__(self, manifest: Any, args: CiArgs) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should be a manifest type, maybe an InputManifest?

@zelinh
Copy link
Member Author

zelinh commented Feb 2, 2022

I'll be merging this now to unblock the process and will create a separate PR for any followup issues Thanks.

@zelinh zelinh merged commit 54cc6d9 into opensearch-project:main Feb 2, 2022
@zelinh zelinh deleted the type-check-ci branch February 2, 2022 18:35
@zelinh zelinh self-assigned this Feb 3, 2022
peterzhuamazon pushed a commit to peterzhuamazon/opensearch-build that referenced this pull request Feb 16, 2022
…i_workflow (opensearch-project#1582)

* Add python typechecking for ci-workflo

Signed-off-by: Zelin Hao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Python Typechecking] CI workflow pipenv run mypy src\ci_workflow tests\tests_ci_workflow
3 participants