Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jupyter_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

warnings.warn("Importing 'jupyter_builder' outside a proper installation.", stacklevel=1)
__version__ = "dev"

from ._yarn_info import YARN_SHA256 as YARN_SHA256
from ._yarn_info import YARN_VERSION as YARN_VERSION
25 changes: 25 additions & 0 deletions jupyter_builder/_yarn_info.py
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()

Copy link
Copy Markdown
Contributor

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.


# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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()
Loading