-
Notifications
You must be signed in to change notification settings - Fork 382
Move runtime.txt
parsing into base class
#1428
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import datetime | ||
import hashlib | ||
import io | ||
import logging | ||
|
@@ -750,3 +751,50 @@ def get_start_script(self): | |
# the only path evaluated at container start time rather than build time | ||
return os.path.join("${REPO_DIR}", start) | ||
return None | ||
|
||
@property | ||
def runtime(self): | ||
""" | ||
Return parsed contents of runtime.txt | ||
|
||
Returns (runtime, version, date), tuple components may be None. | ||
Returns (None, None, None) if runtime.txt not found. | ||
|
||
Supported formats: | ||
name-version | ||
name-version-yyyy-mm-dd | ||
name-yyyy-mm-dd | ||
""" | ||
if hasattr(self, "_runtime"): | ||
return self._runtime | ||
|
||
self._runtime = (None, None, None) | ||
|
||
runtime_path = self.binder_path("runtime.txt") | ||
try: | ||
with open(runtime_path) as f: | ||
runtime_txt = f.read().strip() | ||
except FileNotFoundError: | ||
return self._runtime | ||
|
||
name = None | ||
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. We only support Python and R. I prefer to validate 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 considered that, but it breaks the abstraction where subclasses are responsible for calling and validating |
||
version = None | ||
date = None | ||
|
||
parts = runtime_txt.split("-") | ||
if len(parts) not in (2, 4, 5) or any(not (p) for p in parts): | ||
raise ValueError(f"Invalid runtime.txt: {runtime_txt}") | ||
|
||
name = parts[0] | ||
|
||
if len(parts) in (2, 5): | ||
version = parts[1] | ||
|
||
if len(parts) in (4, 5): | ||
date = "-".join(parts[-3:]) | ||
if not re.match(r"\d\d\d\d-\d\d-\d\d", date): | ||
raise ValueError(f"Invalid runtime.txt date: {date}") | ||
date = datetime.datetime.fromisoformat(date).date() | ||
|
||
self._runtime = (name, version, date) | ||
return self._runtime |
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.
I believe this will require a rebase given that we made a release in August 2025, see https://github.com/jupyterhub/repo2docker/releases/tag/2025.08.0.
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.
The changelog wasn't updated for that release, I've added to reminder to fix that
#1449