Re: [Rd] problem running test on a system without /etc/localtime

2017-05-17 Thread Kirill Maslinsky
On Wed, May 17, 2017 at 11:29:16AM +0200, Martin Maechler wrote:

[...]

> 
> 
> > Index: src/library/base/R/datetime.R
> > ===
> > --- src/library/base/R/datetime.R (revision 72684)
> > +++ src/library/base/R/datetime.R (working copy)
> > @@ -23,7 +23,7 @@
> > {
> > tz <- Sys.getenv("TZ", names = FALSE)
> > if(!location || nzchar(tz)) return(Sys.getenv("TZ", unset = 
> NA_character_))
> > -lt <- normalizePath("/etc/localtime") # Linux, macOS, ...
> > +lt <- normalizePath("/etc/localtime", mustWork = FALSE) # Linux, 
> macOS, ...
> > if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)
> > else if (lt == "/etc/localtime" && file.exists("/etc/timezone") &&
> > dir.exists("/usr/share/zoneinfo") &&

Done, the patch successfully fixes warning but the test failed in the other way:

$ ../bin/R --vanilla < reg-tests-1d.R

> ## PR#17186 - Sys.timezone() on some Debian-derived platforms
> (S.t <- Sys.timezone())
[1] NA
> if(is.na(S.t) || !nzchar(S.t)) stop("could not get timezone")
Error: could not get timezone
Execution halted

Which is technically correct, timezone is not set on the system, but date
utility assumes UTC in this case:

$ date +%Z
UTC

I'm not sure if R should do the same. 


Probably, setting TZ environment variable is the right way to go in this
build environment, but then another failure should be fixed:

> >> Sure, this can be worked around by setting TZ environment variable, but
> >> that causes tests to fail in another place:
> >> 
> >> [builder@localhost tests]$ TZ="GMT" ../bin/R --vanilla < reg-tests-1d.R
> >> 
> >>> ## format()ing invalid hand-constructed  POSIXlt  objects
> >>> d <- as.POSIXlt("2016-12-06"); d$zone <- 1
> >>> tools::assertError(format(d))
> >> Error: Failed to get error in evaluating format(d)
> >> Execution halted

-- 
KM

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] problem running test on a system without /etc/localtime

2017-05-17 Thread Martin Maechler
> Henrik Bengtsson 
> on Tue, 16 May 2017 20:49:02 -0700 writes:

> On Tue, May 16, 2017 at 5:35 PM, Kirill Maslinsky  
wrote:
>> Hi all,
>> 
>> A problem with tests while building R.
>> 
>> I'm packaging R for Sisyphus repository and package build environment,
>> by design, doesn't have /etc/localtime file present. This causes failure
>> with Sys.timeone during test run:
>> 
>> [builder@localhost tests]$ ../bin/R --vanilla < reg-tests-1d.R
>> 
>>> ## PR#17186 - Sys.timezone() on some Debian-derived platforms
>>> (S.t <- Sys.timezone())
>> Error in normalizePath("/etc/localtime") :
>> (converted from warning) path[1]="/etc/localtime": No such file or
>> directory
>> Calls: Sys.timezone -> normalizePath
>> Execution halted
>> 
>> This is caused by this code:
>> 
>>> Sys.timezone
>> function (location = TRUE)
>> {
>> tz <- Sys.getenv("TZ", names = FALSE)
>> if (!location || nzchar(tz))
>> return(Sys.getenv("TZ", unset = NA_character_))
 lt <- normalizePath("/etc/localtime")
>> [remainder of the code skkipped]
>> 
>> File /etc/loclatime is optional and is not guaranteed to be present on
>> any platform. And anyway, it is a good idea to first check that file
>> exists before calling normalizePath.

> Looking at the code
> 
(https://github.com/wch/r-source/blob/R-3-4-branch/src/library/base/R/datetime.R#L26),
> could it be that mustWork = FALSE (instead of the default NA) avoids
> the warning causes this check error?

Good idea.

Kirill, could you apply the minimal patch to the sources and
report back ?


> Index: src/library/base/R/datetime.R
> ===
> --- src/library/base/R/datetime.R (revision 72684)
> +++ src/library/base/R/datetime.R (working copy)
> @@ -23,7 +23,7 @@
> {
> tz <- Sys.getenv("TZ", names = FALSE)
> if(!location || nzchar(tz)) return(Sys.getenv("TZ", unset = 
NA_character_))
> -lt <- normalizePath("/etc/localtime") # Linux, macOS, ...
> +lt <- normalizePath("/etc/localtime", mustWork = FALSE) # Linux, 
macOS, ...
> if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)
> else if (lt == "/etc/localtime" && file.exists("/etc/timezone") &&
> dir.exists("/usr/share/zoneinfo") &&

> /Henrik

>> 
>> Sure, this can be worked around by setting TZ environment variable, but
>> that causes tests to fail in another place:
>> 
>> [builder@localhost tests]$ TZ="GMT" ../bin/R --vanilla < reg-tests-1d.R
>> 
>>> ## format()ing invalid hand-constructed  POSIXlt  objects
>>> d <- as.POSIXlt("2016-12-06"); d$zone <- 1
>>> tools::assertError(format(d))
>> Error: Failed to get error in evaluating format(d)
>> Execution halted
>> 
>> It seems that the best solution will be to patch Sys.timezone.
>> 
>> --
>> KM
>> 
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] problem running test on a system without /etc/localtime

2017-05-16 Thread Henrik Bengtsson
On Tue, May 16, 2017 at 5:35 PM, Kirill Maslinsky  wrote:
> Hi all,
>
> A problem with tests while building R.
>
> I'm packaging R for Sisyphus repository and package build environment,
> by design, doesn't have /etc/localtime file present. This causes failure
> with Sys.timeone during test run:
>
> [builder@localhost tests]$ ../bin/R --vanilla < reg-tests-1d.R
>
>> ## PR#17186 - Sys.timezone() on some Debian-derived platforms
>> (S.t <- Sys.timezone())
> Error in normalizePath("/etc/localtime") :
>   (converted from warning) path[1]="/etc/localtime": No such file or
>   directory
>   Calls: Sys.timezone -> normalizePath
>   Execution halted
>
> This is caused by this code:
>
>> Sys.timezone
> function (location = TRUE)
> {
> tz <- Sys.getenv("TZ", names = FALSE)
> if (!location || nzchar(tz))
> return(Sys.getenv("TZ", unset = NA_character_))
>>>  lt <- normalizePath("/etc/localtime")
> [remainder of the code skkipped]
>
> File /etc/loclatime is optional and is not guaranteed to be present on
> any platform. And anyway, it is a good idea to first check that file
> exists before calling normalizePath.

Looking at the code
(https://github.com/wch/r-source/blob/R-3-4-branch/src/library/base/R/datetime.R#L26),
could it be that mustWork = FALSE (instead of the default NA) avoids
the warning causes this check error?

Index: src/library/base/R/datetime.R
===
--- src/library/base/R/datetime.R (revision 72684)
+++ src/library/base/R/datetime.R (working copy)
@@ -23,7 +23,7 @@
 {
 tz <- Sys.getenv("TZ", names = FALSE)
 if(!location || nzchar(tz)) return(Sys.getenv("TZ", unset = NA_character_))
-lt <- normalizePath("/etc/localtime") # Linux, macOS, ...
+lt <- normalizePath("/etc/localtime", mustWork = FALSE) # Linux, macOS, ...
 if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)
 else if (lt == "/etc/localtime" && file.exists("/etc/timezone") &&
  dir.exists("/usr/share/zoneinfo") &&

/Henrik

>
> Sure, this can be worked around by setting TZ environment variable, but
> that causes tests to fail in another place:
>
> [builder@localhost tests]$ TZ="GMT" ../bin/R --vanilla < reg-tests-1d.R
>
>> ## format()ing invalid hand-constructed  POSIXlt  objects
>> d <- as.POSIXlt("2016-12-06"); d$zone <- 1
>> tools::assertError(format(d))
> Error: Failed to get error in evaluating format(d)
> Execution halted
>
> It seems that the best solution will be to patch Sys.timezone.
>
> --
> KM
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] problem running test on a system without /etc/localtime

2017-05-16 Thread Dirk Eddelbuettel

On 17 May 2017 at 03:35, Kirill Maslinsky wrote:
| I'm packaging R for Sisyphus repository and package build environment,
| by design, doesn't have /etc/localtime file present. This causes failure
| with Sys.timeone during test run:
[...]
| It seems that the best solution will be to patch Sys.timezone.

The file-based approach was AFAIK never successfully standardized.

Setting a TZ is a defensible fallback.  At some point last year I got so
annoyed about this (and have the historical Debian attitude that a config
file may be preferable to a environment variable [ which I now think is wrong
for some things like TZ ]) I wrote the 'gettz' package.   Quick demo in a
Docker container with nothing set:

edd@max:~$ docker run --rm -ti r-base /bin/bash
root@f3848979cab4:/# echo $TZ
echo $TZ

root@f3848979cab4:/# R
R

R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> Sys.getenv("TZ")  # as expected
Sys.getenv("TZ")  # as expected
[1] ""
> install.packages("gettz")
install.packages("gettz")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/gettz_0.0.3.tar.gz'
Content type 'application/x-gzip' length 9064 bytes
==
downloaded 9064 bytes

* installing *source* package ‘gettz’ ...
** package ‘gettz’ successfully unpacked and MD5 sums checked
** libs
g++  -I/usr/share/R/include -DNDEBUG  -fpic  -g -O2 
-fdebug-prefix-map=/build/r-base-3.4.0=. -fstack-protector-strong -Wformat 
-Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c gettz.cpp -o 
gettz.o
g++ -shared -L/usr/lib/R/lib -Wl,-z,relro -o gettz.so gettz.o -L/usr/lib/R/lib 
-lR
installing to /usr/local/lib/R/site-library/gettz/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (gettz)

The downloaded source packages are in
‘/tmp/RtmpLvuVz8/downloaded_packages’
> gettz::gettz()
gettz::gettz()
[1] "Etc/UTC"
>


As I recall, R got patched for R 3.3.3 or R 3.4.0 to return "" in more cases.
gettz is a little smarter about looking in more locations that R was at the
time (and hence not dissimilar to what was suggested earlier today, but
operates at compiled-code level). It uses a trick I found on StackOverflow
(and which is credited in the package).

It is certainly not perfect, but it is "good enough" for the uses I had in
packages requiring some localtime information.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

[Rd] problem running test on a system without /etc/localtime

2017-05-16 Thread Kirill Maslinsky
Hi all, 

A problem with tests while building R.

I'm packaging R for Sisyphus repository and package build environment,
by design, doesn't have /etc/localtime file present. This causes failure
with Sys.timeone during test run:

[builder@localhost tests]$ ../bin/R --vanilla < reg-tests-1d.R

> ## PR#17186 - Sys.timezone() on some Debian-derived platforms
> (S.t <- Sys.timezone())
Error in normalizePath("/etc/localtime") : 
  (converted from warning) path[1]="/etc/localtime": No such file or
  directory
  Calls: Sys.timezone -> normalizePath
  Execution halted

This is caused by this code:

> Sys.timezone
function (location = TRUE) 
{
tz <- Sys.getenv("TZ", names = FALSE)
if (!location || nzchar(tz)) 
return(Sys.getenv("TZ", unset = NA_character_))
>>  lt <- normalizePath("/etc/localtime")
[remainder of the code skkipped]

File /etc/loclatime is optional and is not guaranteed to be present on
any platform. And anyway, it is a good idea to first check that file 
exists before calling normalizePath. 

Sure, this can be worked around by setting TZ environment variable, but
that causes tests to fail in another place:

[builder@localhost tests]$ TZ="GMT" ../bin/R --vanilla < reg-tests-1d.R

> ## format()ing invalid hand-constructed  POSIXlt  objects
> d <- as.POSIXlt("2016-12-06"); d$zone <- 1
> tools::assertError(format(d))
Error: Failed to get error in evaluating format(d)
Execution halted

It seems that the best solution will be to patch Sys.timezone.

-- 
KM

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel