Skip to content

Commit 74f4197

Browse files
committed
feat: use FAKETIME_FMT environment var instead of patching libfaketime
1 parent 4ea08c5 commit 74f4197

File tree

5 files changed

+11
-31
lines changed

5 files changed

+11
-31
lines changed

.github/workflows/tests.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
key: pip|${{ hashFiles('setup.py') }}|${{ hashFiles('setup.cfg') }}
3737
- run: pip install tox
3838
- run: git submodule update --init --force
39-
- run: git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/nanosecond.patch
4039
- run: env FAKETIME_COMPILE_CFLAGS="-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP" make -C libfaketime/vendor/libfaketime
4140
if: runner.os == 'Linux'
4241
- run: make -C libfaketime/vendor/libfaketime

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ Contributions are welcome! You should compile libfaketime before running tests:
165165

166166
```bash
167167
git submodule init --update
168-
git apply --directory libfaketime/vendor/libfaketime libfaketime/vendor/nanosecond.patch
169168
# For Linux:
170169
env FAKETIME_COMPILE_CFLAGS="-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP" make -C libfaketime/vendor/libfaketime
171170
# For macOS

libfaketime/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# This env var is set by reexec to ensure we don't reload more than once.
2727

2828
_DID_REEXEC_VAR = 'FAKETIME_DID_REEXEC'
29-
29+
_FAKETIME_FMT = '%Y-%m-%d %T.%f'
3030

3131
def _get_lib_path():
3232
vendor_dir = 'libfaketime'
@@ -162,7 +162,7 @@ def _should_patch_uuid(self):
162162
return None
163163

164164
def _format_datetime(self, _datetime):
165-
return _datetime.strftime('%Y-%m-%d %T %f')
165+
return _datetime.strftime(_FAKETIME_FMT)
166166

167167
def tick(self, delta=datetime.timedelta(seconds=1)):
168168
self.time_to_freeze += delta
@@ -173,11 +173,13 @@ def __enter__(self):
173173
begin_callback(self)
174174
self._prev_spec = os.environ.get('FAKETIME')
175175
self._prev_tz = os.environ.get('TZ')
176+
self._prev_fmt = os.environ.get('FAKETIME_FMT')
176177

177178
os.environ['TZ'] = self.timezone_str
178179

179180
time.tzset()
180181
os.environ['FAKETIME'] = self._format_datetime(self.time_to_freeze)
182+
os.environ['FAKETIME_FMT'] = _FAKETIME_FMT
181183

182184
func_name = self._should_patch_uuid()
183185
if func_name:
@@ -202,7 +204,13 @@ def __exit__(self, *exc):
202204
os.environ['FAKETIME'] = self._prev_spec
203205
else:
204206
del os.environ['FAKETIME']
205-
end_callback(self)
207+
208+
if self._prev_fmt is not None:
209+
os.environ['FAKETIME_FMT'] = self._prev_spec
210+
else:
211+
del os.environ['FAKETIME_FMT']
212+
213+
end_callback(self)
206214

207215
return False
208216

libfaketime/vendor/nanosecond.patch

-25
This file was deleted.

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
class CustomInstall(install):
3939
def run(self):
4040
self.my_outputs = []
41-
subprocess.check_call(['patch', '-p1', '<', '../nanosecond.patch'], cwd=_vendor_path, shell=True)
4241
if sys.platform in ("linux", "linux2"):
4342
subprocess.check_call(['env', 'FAKETIME_COMPILE_CFLAGS=-UFAKE_STAT -UFAKE_UTIME -UFAKE_SLEEP', 'make', '-C', _vendor_path])
4443
elif sys.platform == "darwin":

0 commit comments

Comments
 (0)