-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expose YARN_VERSION and YARN_SHA256
#110
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright (c) Jupyter Development Team. | ||
| # Distributed under the terms of the Modified BSD License. | ||
| """Yarn version and integrity information for the vendored yarn.js.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
| _yarn_js = Path(__file__).resolve().parent / "yarn.js" | ||
| _yarn_bytes = _yarn_js.read_bytes() | ||
|
|
||
| # Minified yarn berry embeds the version as: YarnVersion:()=>VarName ... var VarName="x.y.z" | ||
| _match = re.search(rb"YarnVersion:\(\)=>(\w+)", _yarn_bytes) | ||
| if _match: | ||
| _var = re.escape(_match.group(1)) | ||
| _match = re.search(rb"var " + _var + rb'="([^"]+)"', _yarn_bytes) | ||
|
|
||
| if not _match: | ||
| msg = "Could not extract YARN_VERSION from vendored yarn.js" | ||
| raise RuntimeError(msg) | ||
|
Comment on lines
+14
to
+22
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a bit fragile, I think a minimum countermeasure would be adding a test case for this. |
||
|
|
||
| YARN_VERSION: str = _match.group(1).decode() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend storing the version and hash as constants and comparing the hash instead with an assertion. If the hash hasn't changed, the version will be correct. |
||
| YARN_SHA256: str = hashlib.sha256(_yarn_bytes).hexdigest() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider deleting this when it is no longer required as it takes significant memory to store.