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

📝 Tutorial study functionality #58

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

bisgaard-itis
Copy link
Collaborator

@bisgaard-itis bisgaard-itis commented Jul 19, 2023

What do these changes do?

Add a first tutorial for the studies entry.

Related issue/s

How to test

@pcrespov pcrespov added this to the Sundae milestone Jul 19, 2023
@pcrespov pcrespov added the documentation Improvements or additions to documentation label Jul 19, 2023
@bisgaard-itis bisgaard-itis added documentation Improvements or additions to documentation and removed documentation Improvements or additions to documentation labels Jul 19, 2023
Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

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

@bisgaard-itis please do not forget to fill the PR issue attributes. e.g.

  • assignee
  • select project
  • add labels
  • select milestone

Also, the gh issue links render better if you use them in enumerations, ie.g. issue #1 renders
this is how it renders a flat #1

), f"The version defined in {API_DIR/'config.json'} is not present in {TUTORIAL_CLIENT_COMPATIBILITY_JSON}"


@pytest.mark.parametrize("tutorial", get_tutorials())
Copy link
Member

Choose a reason for hiding this comment

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

TIP: using ids= argument will display the parametrization much clearer.

e.g. try running it now and see the output vs

@pytest.mark.parametrize("tutorial", get_tutorials(), ids: lambda p: p.name)
def test_...
``

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a good tip. I was actually trying to figure out how to do this, but didn't find any good tips on google or perplexity

pytest.skip(
f"{tutorial.relative_to(DOCS_DIR)} is not compatible with osparc.__version__=={osparc.__version__}. See {TUTORIAL_CLIENT_COMPATIBILITY_JSON.name}"
)
print(f"Running {tutorial.relative_to(DOCS_DIR)}")
Copy link
Member

Choose a reason for hiding this comment

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

this print will be unnecessary if you use the parametrization ids above.

@pytest.mark.parametrize("tutorial", get_tutorials(), ids: lambda p: p.relative_to(DOCS_DIR))
def test_...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

), f"Some tutorial notebooks are not present in {TUTORIAL_CLIENT_COMPATIBILITY_JSON}"

# check that version of this repo is present in compatibility json
cur_version: str = json.loads((API_DIR / "config.json").read_text())["python"][
Copy link
Member

Choose a reason for hiding this comment

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

STYLE: prioritize good variable names and structure to doc.

e.g. these lines of code do not need extra doc

current_version = json.loads((API_DIR / "config.json").read_text())["python"]["version"]
compatible_versions = set(json.loads(TUTORIAL_CLIENT_COMPATIBILITY_JSON.read_text())["versions"].keys())
assert current_version in compatible_versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Will fix

@pytest.mark.parametrize("notebook", all_notebooks)
def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] = {}):
"""Run all notebooks in the documentation"""
def run_notebook(tmp_path: Path, notebook: Path, params: dict[str, Any] = {}):
Copy link
Member

Choose a reason for hiding this comment

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

STYLE: every function not being fixtures or tests in a test/*/test_*.py file are helpers.

  • The fixtures are decorated with pytest.fixture
  • Tests are named test_
  • (our convention) helpers use protected prefix, i.e. def _run_notebook(...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. I will add a _ in front of these.

@@ -45,3 +46,90 @@ def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] =
kernel_name="python3",
parameters=params,
)


def get_tutorials(osparc_version: Optional[str] = None) -> List[Path]:
Copy link
Member

Choose a reason for hiding this comment

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

TIP: I think there is a packaging.version.Version object

Copy link
Collaborator Author

@bisgaard-itis bisgaard-itis Jul 19, 2023

Choose a reason for hiding this comment

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

Yes, I know about that one. However, since here I use the input to extract something from a dict (loaded from a json). So I think it is makes sense to simply use the string here. Let me know if you disagree.

@@ -45,3 +46,90 @@ def test_run_notebooks(tmp_path: Path, notebook: Path, params: dict[str, Any] =
kernel_name="python3",
parameters=params,
)


def get_tutorials(osparc_version: Optional[str] = None) -> List[Path]:
Copy link
Member

Choose a reason for hiding this comment

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

Q: Optional or Dict annotations are because we have to be compatible with 3.6>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this has to be compatible with <3.6. Currently I use 3.9 when developing the client. I can replace the Dict by dict, but what about the Optional? Should that be replaced by <> | None?

@bisgaard-itis
Copy link
Collaborator Author

@bisgaard-itis please do not forget to fill the PR issue attributes. e.g.

* assignee

* select project

* add labels

* select milestone

Also, the gh issue links render better if you use them in enumerations, ie.g. issue #1 renders this is how it renders a flat #1

* but this is how it renders in enum [Upgrade v0.2 #1](https://github.com/ITISFoundation/osparc-simcore-clients/pull/1)

Sorry, I thought I had already filled in all the PR attributes. I will be more careful next time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants