Skip to content

Commit e5d7531

Browse files
committed
Add timestamp to .bak
1 parent 26e86d5 commit e5d7531

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

cmdstanpy/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
from collections import OrderedDict
1111
from concurrent.futures import ThreadPoolExecutor
12+
from datetime import datetime
1213
from io import StringIO
1314
from multiprocessing import cpu_count
1415
from pathlib import Path
@@ -376,7 +377,12 @@ def format(
376377
if overwrite_file:
377378
if result:
378379
if backup:
379-
shutil.copyfile(self.stan_file, self.stan_file + '.bak')
380+
shutil.copyfile(
381+
self.stan_file,
382+
self.stan_file
383+
+ '.bak-'
384+
+ datetime.now().strftime("%Y%m%d%H%M%S"),
385+
)
380386
with (open(self.stan_file, 'w')) as file_handle:
381387
file_handle.write(result)
382388
else:

test/data/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
# and we re-ignore hpp and exe files
77
*.hpp
88
*.exe
9-
*.*bak
9+
*.testbak
10+
*.bak-*
1011
!return_one.hpp

test/test_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import tempfile
99
import unittest
10+
from glob import glob
1011
from test import CustomTestCase
1112
from unittest.mock import MagicMock, patch
1213

@@ -409,7 +410,7 @@ def test_model_format_deprecations(self):
409410
shutil.copy(stan, stan + '.testbak')
410411
try:
411412
model.format(overwrite_file=True, canonicalize=True)
412-
self.assertTrue(os.path.exists(stan + '.bak'))
413+
self.assertEqual(len(glob(stan + '.bak-*')), 1)
413414
finally:
414415
shutil.copy(stan + '.testbak', stan)
415416

0 commit comments

Comments
 (0)