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

Docs: How To Pass Objects between JavaScript and PyScript #753

Merged
merged 9 commits into from
Sep 12, 2022

Conversation

JeffersGlass
Copy link
Member

Following a conversation with @marimeireles, adds a How-To document on passing objects between PyScript and JavaScript environments at runtime, based on this writeup.

This How Tois based on the PyScript as it exists at time of writing - including the Pyodide 21 API changes - and not the most recent stable release (2022.06.1). That way, it's accurate as of the next stable release. I know the documentation release process is still in the works - I imagine the document release cycle will track the pinned releases?

@JeffersGlass JeffersGlass changed the title Howto object passing Docs: How To Pass Objects between JavaScript and PyScript Sep 7, 2022
@marimeireles
Copy link
Member

Woow!
So great! Thank you so much for this @JeffersGlass! Will review right now.
@pww217 and I were responsible for tackling this together, not sure if we'll have the time this month because we're prioritizing other features for this month... But Peter is the one that can say more about it, I don't know how to do this.

@pww217
Copy link
Contributor

pww217 commented Sep 7, 2022

Hi @JeffersGlass - you're correct, the basic documentation structure is that it will build in lockstep with tagged releases.

The reason it fails here is because its trying to run from a fork but use repo credentials it doesn't have access to. It's interesting because I thought we had disabled it running from forks. All it's doing, really, is create draft docs to make sure it can build and format them correctly.

After this PR is merged into main it will show up at docs.pyscript.net/latest and in the next versioned release under, for instance, docs.pyscript.net/2022.08.01.

The docs CI is still a work in progress but the basic implementation is there. The CI files themselves can be founds in .github/workflows.

Hopefully that all makes sense.

Copy link
Member

@marimeireles marimeireles left a comment

Choose a reason for hiding this comment

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

This is awesome!
Super great addition, very grateful @JeffersGlass :)
I just added one comment cause I was wondering if it'd make it simpler, if you disagree, you can simply ignore it and we merge it.
Cheers.

Comment on lines 31 to 33
from js import console
console.log(f"Hello {name}")
console.log("Adding 1 and 2 in Javascript: " + str(addTwoNumbers(1, 2)))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you should use print here just so it's simpler for users?

print(f'Hello' {name})
...

I feel like introducing that you can just use std JS library now might be confusing for a few, is good to make it clear that we're writing Python.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense to me! This was mostly a hedge against needing to update the examples pending the changes to things like print vs display from #635, #749 etc. But you're right it would be clearer to keep this all in Python. And I imagine a lot of the documentation will need to get updated when that overhaul happens anyway.

Change is made.

@marimeireles
Copy link
Member

Thank you @JeffersGlass, really great work :D

@marimeireles marimeireles merged commit 8657dfb into pyscript:main Sep 12, 2022
@JeffersGlass JeffersGlass deleted the howto-object-passing branch September 12, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants