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 auto-generated pyi files to Metaflow #1557

Merged
merged 31 commits into from
Jan 29, 2024
Merged

Add auto-generated pyi files to Metaflow #1557

merged 31 commits into from
Jan 29, 2024

Conversation

romain-intel
Copy link
Contributor

No description provided.

Copy link
Contributor Author

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

Added a few comments to make reviewing this easier.

@@ -1,14 +1,13 @@
from collections import namedtuple
import os
from typing import Any, Optional
from typing import Any, Optional, TYPE_CHECKING
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: for full disclosure, TYPE_CHECKING was introduced in 3.5.2. I feel it should still be OK and we can still support 3.5 (just 3.5.2+)

@@ -203,6 +213,9 @@ def default_namespace() -> str:
return get_namespace()


MetaflowArtifacts = NamedTuple
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just to give it a proper type so that there are no issues in the generated pyi file. It's not very informative but I don't think we can do much better.

@@ -981,6 +950,50 @@ def __setstate__(self, state):
super(DataArtifact, self).__setstate__(state)


class MetaflowData(object):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved below to allow types to find each other.

self,
stream: str,
as_unicode: bool = True,
meta_dict: Optional[Dict[str, Any]] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed adding optional

@@ -337,17 +350,17 @@ def _get_object(self, *path_components):
raise MetaflowNotFound("%s does not exist" % self)
return result

def __iter__(self) -> Iterable["MetaflowObject"]:
def __iter__(self) -> Iterator["MetaflowObject"]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed all things that have yield to Yields in the docstring and also to return an Iterator (proper return type for yields).

@@ -143,7 +143,7 @@ def __init__(
content_type: Optional[str] = None,
metadata: Optional[Dict[str, str]] = None,
range_info: Optional[RangeInfo] = None,
last_modified: int = None,
last_modified: Optional[int] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added proper type.


MF Add To Current
-----------------
trigger -> metaflow.events.Trigger
Copy link
Contributor Author

Choose a reason for hiding this comment

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

notice that both decorators can add the same thing. The definitions should be the same (one is just picked -- no checks). It will say that this applies to BOTH decorators.


Returns
-------
Trigger
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: unindent.


MF Add To Current
-----------------
project_name -> str
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add multiple properties. Blank line between properties is optional I think but makes things clearer.

stubs/setup.py Outdated
@@ -0,0 +1,46 @@
from setuptools import find_packages, setup

version = "2.10.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably read this from common location.

@savingoyal savingoyal requested a review from saikonen October 30, 2023 15:51
@romain-intel romain-intel changed the title [WIP] Working on adding auto-generated pyi files to Metaflow Add auto-generated pyi files to Metaflow Nov 3, 2023
@nflx-mf-bot
Copy link
Collaborator

Testing[602] @ 7b279fa

savingoyal
savingoyal previously approved these changes Jan 23, 2024
Copy link
Collaborator

@savingoyal savingoyal left a comment

Choose a reason for hiding this comment

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

lgtm - few minor comments

Yields
------
Task
Control Task object for this step
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit - objects

@@ -25,6 +25,50 @@ class ProjectDecorator(FlowDecorator):
Project name. Make sure that the name is unique amongst all
projects that use the same production scheduler. The name may
contain only lowercase alphanumeric characters and underscores.

MF Add To Current
Copy link
Collaborator

Choose a reason for hiding this comment

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

MF Add To Current - is there a special significance to this string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is used to define a section to add fields to the current object. It's non standard and just our thing.

stubs/setup.py Outdated
include_package_data=True,
name="metaflow-stubs",
version=version,
description="Metaflow: More Data Science, Less Engineering",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the description to notate that this is a stubs package

stubs/setup.py Outdated
name="metaflow-stubs",
version=version,
description="Metaflow: More Data Science, Less Engineering",
long_description=open("../README.md").read(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This long description does not apply to this package

"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Copy link
Collaborator

Choose a reason for hiding this comment

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

3.12?

def step(f):
FlowSpecDerived = TypeVar("FlowSpecDerived", bound=FlowSpec)

StepFlag = NewType("StepFlag", bool)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add some comments here around the necessity for StepFlag?

romain-intel and others added 14 commits January 23, 2024 15:20
* Added a stub command; moved script to new location.

* validation of sample flow with mypy + packaging (#1676)

* validate sample flow with mypy

* also install metaflow in CI

* change commands

* package generated stubs with metaflow

* don't do editable install

* re-introduce setup.py

* update publish action

* point to dist

* check common cases with pytest-mypy plugin

* Updated stub tests; added kw only args to stub generator

* remove test flow

* kubernetes validity

* add tests for environment, card, catch, conda

* add tests for timeout, secrets, retry, resources decorators

* add tests for conda_base, schedule, trigger, trigger_on_finish decorators

* Get tests to pass again

---------

Co-authored-by: Romain Cledat <[email protected]>

* fix checking of stubs package (#1689)

* Properly uninstall packages that provide stubs before installing a new one.

* Add a few more cases to the stub generator

* add tests for pypi and pypi_base decorators (#1694)

* Remove print; better setup.py

---------

Co-authored-by: madhur-ob <[email protected]>
* use regex for mypy tests

* fix regex
* separate workflow for testing stubs

* remove 3.5 and 3.6
* install build via pip

* install pytest
@romain-intel romain-intel merged commit 0bb543d into master Jan 29, 2024
32 of 34 checks passed
@romain-intel romain-intel deleted the feat/autodocs branch January 29, 2024 23:24
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.

5 participants