MCPcopy Create free account
hub / github.com/boostorg/build / __python_timestamp_resolution

Method __python_timestamp_resolution

test/BoostBuild.py:983–1053  ·  view source on GitHub ↗

Returns the modification timestamp resolution for the given path supported by the used Python interpreter/OS/filesystem combination. Will not check for resolutions less than the given minimum value. Will change the path's modification timestamp in the process.

(self, path, minimum_resolution)

Source from the content-addressed store, hash-verified

981 pass
982
983 def __python_timestamp_resolution(self, path, minimum_resolution):
984 """
985 Returns the modification timestamp resolution for the given path
986 supported by the used Python interpreter/OS/filesystem combination.
987 Will not check for resolutions less than the given minimum value. Will
988 change the path's modification timestamp in the process.
989
990 Return values:
991 0 - nanosecond resolution supported
992 positive decimal - timestamp resolution in seconds
993
994 """
995 # Note on Python's floating point timestamp support:
996 # Python interpreter versions prior to Python 2.3 did not support
997 # floating point timestamps. Versions 2.3 through 3.3 may or may not
998 # support it depending on the configuration (may be toggled by calling
999 # os.stat_float_times(True/False) at program startup, disabled by
1000 # default prior to Python 2.5 and enabled by default since). Python 3.3
1001 # deprecated this configuration and 3.4 removed support for it after
1002 # which floating point timestamps are always supported.
1003 ver = sys.version_info[0:2]
1004 python_nanosecond_support = ver >= (3, 4) or (ver >= (2, 3) and
1005 os.stat_float_times())
1006
1007 # Minimal expected floating point difference used to account for
1008 # possible imprecise floating point number representations. We want
1009 # this number to be small (at least smaller than 0.0001) but still
1010 # large enough that we can be sure that increasing a floating point
1011 # value by 2 * eta guarantees the value read back will be increased by
1012 # at least eta.
1013 eta = 0.00005
1014
1015 stats_orig = os.stat(path)
1016 def test_time(diff):
1017 """Returns whether a timestamp difference is detectable."""
1018 os.utime(path, (stats_orig.st_atime, stats_orig.st_mtime + diff))
1019 return os.stat(path).st_mtime > stats_orig.st_mtime + eta
1020
1021 # Test for nanosecond timestamp resolution support.
1022 if not minimum_resolution and python_nanosecond_support:
1023 if test_time(2 * eta):
1024 return 0
1025
1026 # Detect the filesystem timestamp resolution. Note that there is no
1027 # need to make this code 'as fast as possible' as, this function gets
1028 # called before having to sleep until the next detectable modification
1029 # timestamp value and that, since we already know nanosecond resolution
1030 # is not supported, will surely take longer than whatever we do here to
1031 # detect this minimal detectable modification timestamp resolution.
1032 step = 0.1
1033 if not python_nanosecond_support:
1034 # If Python does not support nanosecond timestamp resolution we
1035 # know the minimum possible supported timestamp resolution is 1
1036 # second.
1037 minimum_resolution = max(1, minimum_resolution)
1038 index = max(1, int(minimum_resolution / step))
1039 while step * index < minimum_resolution:
1040 # Floating point number representation errors may cause our

Callers 1

Calls 1

Tested by

no test coverage detected