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

Method __python_timestamp_resolution

test/BoostBuild.py:1039–1109  ·  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

1037 pass
1038
1039 def __python_timestamp_resolution(self, path, minimum_resolution):
1040 """
1041 Returns the modification timestamp resolution for the given path
1042 supported by the used Python interpreter/OS/filesystem combination.
1043 Will not check for resolutions less than the given minimum value. Will
1044 change the path's modification timestamp in the process.
1045
1046 Return values:
1047 0 - nanosecond resolution supported
1048 positive decimal - timestamp resolution in seconds
1049
1050 """
1051 # Note on Python's floating point timestamp support:
1052 # Python interpreter versions prior to Python 2.3 did not support
1053 # floating point timestamps. Versions 2.3 through 3.3 may or may not
1054 # support it depending on the configuration (may be toggled by calling
1055 # os.stat_float_times(True/False) at program startup, disabled by
1056 # default prior to Python 2.5 and enabled by default since). Python 3.3
1057 # deprecated this configuration and 3.4 removed support for it after
1058 # which floating point timestamps are always supported.
1059 ver = sys.version_info[0:2]
1060 python_nanosecond_support = ver >= (3, 4) or (ver >= (2, 3) and
1061 os.stat_float_times())
1062
1063 # Minimal expected floating point difference used to account for
1064 # possible imprecise floating point number representations. We want
1065 # this number to be small (at least smaller than 0.0001) but still
1066 # large enough that we can be sure that increasing a floating point
1067 # value by 2 * eta guarantees the value read back will be increased by
1068 # at least eta.
1069 eta = 0.00005
1070
1071 stats_orig = os.stat(path)
1072 def test_time(diff):
1073 """Returns whether a timestamp difference is detectable."""
1074 os.utime(path, (stats_orig.st_atime, stats_orig.st_mtime + diff))
1075 return os.stat(path).st_mtime > stats_orig.st_mtime + eta
1076
1077 # Test for nanosecond timestamp resolution support.
1078 if not minimum_resolution and python_nanosecond_support:
1079 if test_time(2 * eta):
1080 return 0
1081
1082 # Detect the filesystem timestamp resolution. Note that there is no
1083 # need to make this code 'as fast as possible' as, this function gets
1084 # called before having to sleep until the next detectable modification
1085 # timestamp value and that, since we already know nanosecond resolution
1086 # is not supported, will surely take longer than whatever we do here to
1087 # detect this minimal detectable modification timestamp resolution.
1088 step = 0.1
1089 if not python_nanosecond_support:
1090 # If Python does not support nanosecond timestamp resolution we
1091 # know the minimum possible supported timestamp resolution is 1
1092 # second.
1093 minimum_resolution = max(1, minimum_resolution)
1094 index = max(1, int(minimum_resolution / step))
1095 while step * index < minimum_resolution:
1096 # Floating point number representation errors may cause our

Calls 1

Tested by

no test coverage detected