11import datetime
22import os
3- import re
3+ import warnings
44from functools import lru_cache
55
66import requests
@@ -45,21 +45,6 @@ class RBuildPack(PythonBuildPack):
4545 R is installed from https://docs.rstudio.com/resources/install-r/
4646 """
4747
48- @property
49- def runtime (self ):
50- """
51- Return contents of runtime.txt if it exists, '' otherwise
52- """
53- if not hasattr (self , "_runtime" ):
54- runtime_path = self .binder_path ("runtime.txt" )
55- try :
56- with open (runtime_path ) as f :
57- self ._runtime = f .read ().strip ()
58- except FileNotFoundError :
59- self ._runtime = ""
60-
61- return self ._runtime
62-
6348 @property
6449 def r_version (self ):
6550 """Detect the R version for a given `runtime.txt`
@@ -91,11 +76,11 @@ def r_version(self):
9176 r_version = version_map ["4.4" ]
9277
9378 if not hasattr (self , "_r_version" ):
94- parts = self .runtime . split ( "-" )
79+ _ , version , date = self .runtime
9580 # If runtime.txt is not set, or if it isn't of the form r-<version>-<yyyy>-<mm>-<dd>,
9681 # we don't use any of it in determining r version and just use the default
97- if len ( parts ) == 5 :
98- r_version = parts [ 1 ]
82+ if version and date :
83+ r_version = version
9984 # For versions of form x.y, we want to explicitly provide x.y.z - latest patchlevel
10085 # available. Users can however explicitly specify the full version to get something specific
10186 if r_version in version_map :
@@ -117,15 +102,11 @@ def checkpoint_date(self):
117102 Returns '' if no date is specified
118103 """
119104 if not hasattr (self , "_checkpoint_date" ):
120- match = re . match ( r"r-(\d.\d(.\d)?-)?(\d\d\d\d)-(\d\d)-(\d\d)" , self .runtime )
121- if not match :
122- self ._checkpoint_date = False
105+ name , version , date = self .runtime
106+ if name == "r" and date :
107+ self ._checkpoint_date = date
123108 else :
124- # turn the last three groups of the match into a date
125- self ._checkpoint_date = datetime .date (
126- * [int (s ) for s in match .groups ()[- 3 :]]
127- )
128-
109+ self ._checkpoint_date = False
129110 return self ._checkpoint_date
130111
131112 def detect (self ):
@@ -143,13 +124,9 @@ def detect(self):
143124
144125 description_R = "DESCRIPTION"
145126 if not self .binder_dir and os .path .exists (description_R ):
146- if not self .checkpoint_date :
147- # no R snapshot date set through runtime.txt
148- # Set it to two days ago from today
149- self ._checkpoint_date = datetime .date .today () - datetime .timedelta (
150- days = 2
151- )
152- self ._runtime = f"r-{ str (self ._checkpoint_date )} "
127+ # no R snapshot date set through runtime.txt
128+ # Set it to two days ago from today
129+ self ._checkpoint_date = datetime .date .today () - datetime .timedelta (days = 2 )
153130 return True
154131
155132 @lru_cache
0 commit comments