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

Method __python_timestamp_resolution

v2/test/BoostBuild.py:981–1051  ·  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

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

Callers 1

Calls 1

Tested by

no test coverage detected