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 a CLI command to create a zipfile of Python libraries #3411

Merged
merged 12 commits into from
Jan 14, 2023

Conversation

ryanking13
Copy link
Member

@ryanking13 ryanking13 commented Jan 4, 2023

Description

This PR is a split-off from #3166.

This adds pyodide create-zip (open to other names) CLI command into pyodide-build,
which bundles a directory into a zipfile, so it can be imported.

Note that this is not part of our build system yet, I'll make a follow up PR after #3252 and #3253 are merged.

Checklists

@ryanking13 ryanking13 changed the title Add a new pyodide CLI command to create a zipfile for Python libraries Add a CLI command to create a zipfile for Python libraries Jan 4, 2023
@ryanking13 ryanking13 changed the title Add a CLI command to create a zipfile for Python libraries Add a CLI command to create a zipfile of Python libraries Jan 4, 2023
Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks @ryanking13 ! A few minor comments otherwise LGTM.

For the name maybe pyodide create-zipfile since that's the name of the Python stdlib module? Do we generally expect users to use this? If not maybe we shouldn't make it part of the public CLI API?

Also needs a changelog.

pyodide-build/pyodide_build/pyzip.py Show resolved Hide resolved
Bundle Python standard libraries into a zip file.

The basic idea of this function is similar to the standard library's
[PyZipFile](https://github.com/python/cpython/blob/59665d0280c2299ea87e9af45cedc90656cb6f55/Lib/zipfile/__init__.py#L2011).
Copy link
Member

@rth rth Jan 4, 2023

Choose a reason for hiding this comment

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

{ref}`zipfile.PyZipFile`

should work I think once we enable stdlib sphinx inter-linking in https://github.com/pyodide/pyodide/pull/3405/files#diff-85933aa74a2d66c3e4dcdf7a9ad8397f5a7971080d34ef1108296a7c6b69e7e3R74

temp_dir = Path(temp_dir_str)
shutil.copytree(libdir, temp_dir, ignore=filterfunc, dirs_exist_ok=True)

shutil.make_archive(str(output), "zip", temp_dir)
Copy link
Member

Choose a reason for hiding this comment

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

Does it use compression by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it does, though I think it is not a very well documented behavior. (https://github.com/python/cpython/blob/31b639a99281bd9582e88137a3be2868c4154a88/Lib/shutil.py#L978)

pyodide-build/pyodide_build/tests/test_pyzip.py Outdated Show resolved Hide resolved
pyodide-build/pyodide_build/cli/create_zip.py Outdated Show resolved Hide resolved
libdir : Path or str
Path to the directory containing the Python standard library.

output : Path or str, optional
Copy link
Member

Choose a reason for hiding this comment

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

Also now that #3405 is merged, you should be able to remove the types in docstrings and have them auto-generated from type annotations.

@ryanking13
Copy link
Member Author

ryanking13 commented Jan 5, 2023

Thanks for the thorough review @rth!

For the name maybe pyodide create-zipfile since that's the name of the Python stdlib module? Do we generally expect users to use this? If not maybe we shouldn't make it part of the public CLI API?

I think users will not use this directly, but I am thinking of using this CLI in our makefile. Probably we can hide it from the help message and docs?

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks @ryanking13 . Minor comment otherwise LGTM.

@@ -127,3 +132,52 @@ def test_config_get(cfg_name, env_var):
)

assert result.stdout.strip() == common.get_make_flag(env_var)


def test_fetch_or_build_pypi(selenium, tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

There is already a test named the same way on main. I wonder if it's badly merging with main in CI and we end up with 2 identically named tests one of which would be ignored. This would explain why coverage says it's not run in CI.

Could you merge the main in, please to see if it would help?

Copy link
Member

Choose a reason for hiding this comment

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

Merged main to resolve conflict. Otherwise, nevermind my comment, I did see the function test on main locally, but not after syncing with upstream. Still unclear why codecov doesn't see coverage here, but merging anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this test was moved to test_pypi.py in #3310. I think I made a mistake while merging main.

@rth rth merged commit ae4492a into pyodide:main Jan 14, 2023
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.

2 participants