Skip to content

Commit 0c9bb81

Browse files
authored
Merge pull request #10 from xsuite/release/v0.1.1
Release 0.1.1
2 parents 7f6a620 + 905c4b2 commit 0c9bb81

File tree

16 files changed

+232
-72
lines changed

16 files changed

+232
-72
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
xboinc/user_data.json
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[tool.poetry]
77
name = "xboinc"
8-
version = "0.1.0"
8+
version = "0.1.1"
99
description = "Xsuite BOINC interface"
1010
homepage = "https://github.com/xsuite/xboinc"
1111
repository = "https://github.com/xsuite/xboinc"

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from xboinc import __version__
22

33
def test_version():
4-
assert __version__ == '0.1.0'
4+
assert __version__ == '0.1.1'
55

version.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ fi
1919
bump=$1
2020
force=$2
2121

22+
# Check our working directory is clean
23+
git diff --quiet
24+
if [ $? -ne 0 ]
25+
then
26+
echo "Some changes are not staged."
27+
echo "Stage and commit before bumping the version."
28+
exit 1
29+
fi
30+
git diff --staged --quiet
31+
if [ $? -ne 0 ]
32+
then
33+
echo "Some changes are staged."
34+
echo "Commit before bumping the version."
35+
exit 1
36+
fi
37+
2238
# Check we are not on main
2339
branch=$(git status | head -1 | awk '{print $NF}')
2440
if [[ "$branch" == "main" ]]
@@ -35,7 +51,7 @@ fi
3551
expected_ver=$(poetry version $bump --dry-run | awk '{print $6;}')
3652
if [[ "$force" != "--force" ]]
3753
then
38-
if [[ "$branch" != "release$expected_ver" ]]
54+
if [[ "$branch" != "release/v$expected_ver" ]]
3955
then
4056
echo "Error: you are bumping to $expected_ver but this branch is $branch."
4157
echo "If this is intentional, use version.sh 'value' --force."
@@ -73,6 +89,7 @@ esac
7389
current_ver=(${current_ver//./ })
7490
current_ver=${current_ver[0]}.${current_ver[1]}
7591
minor_ver=(${expected_ver//./ })
92+
# TODO: exec_ver should come from python app_version_int
7693
exec_ver=$(( 1000*${minor_ver[0]} + ${minor_ver[1]} ))
7794
minor_ver=${minor_ver[0]}.${minor_ver[1]}
7895
if [[ "$minor_ver" != "$current_ver" ]]

xboinc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .register import register
1313
from .submit import SubmitJobs
1414

15-
from .simulation_io import SimState, SimConfig
15+
from .simulation_io import SimState, SimConfig, app_version, app_version_int
1616
from .executable import generate_executable_source, generate_executable
1717

1818

xboinc/executable/generate_executable_source.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ######################################### #
55

66
import xobjects as xo
7-
from ..simulation_io import SimState, SimConfig, SimVersion, get_default_tracker
7+
from ..simulation_io import SimState, SimConfig, SimVersion, app_version, get_default_tracker
88
from ..general import _pkg_root, __version__
99

1010
from pathlib import Path
@@ -78,8 +78,7 @@ def generate_executable(keep_source=False):
7878
else:
7979
raise RuntimeError("Neither clang or gcc are found. Install a C compiler.")
8080

81-
tag = '_'
82-
tag += '.'.join(__version__.split('.')[:2])
81+
tag = f'_{app_version}'
8382
cmd = subprocess.run(['uname', '-ms'], stdout=subprocess.PIPE)
8483
if cmd.returncode == 0:
8584
tag += '-' + cmd.stdout.decode('UTF-8').strip().lower().replace(' ','-')

xboinc/executable/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ int main(){
6464
// Get sim config
6565
SimConfig sim_config = (SimConfig) sim_buffer;
6666
int64_t input_version = SimConfig_get_sim_state_version_xboinc_version(sim_config);
67-
// Compatible if major and minor versions match (no new executables are made at patches)
68-
input_version = input_version/1000;
6967
if (input_version != xboinc_exec_version){
7068
printf("Error: Xboinc version of executable and input file do not match!\n");
7169
return -1; // error

xboinc/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Do not change
1313
# ==========================================================================================
1414

15-
__version__ = '0.1.0'
15+
__version__ = '0.1.1'
1616

1717
# These are the xsuite modules that are used by boinc and the versions they are tied to.
1818
# This will be automatically updated from the active environment when making a minor release.

xboinc/register.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from pathlib import Path
88

99
from .general import _pkg_root
10+
from .user import update_user_data
1011
from .server import server_account
1112
from .server.paths import dropdir
12-
from .server.eos import cp_to_eos
13+
from .server.eos import eos_exists, eos_rm, cp_to_eos
1314
from .server.afs import afs_add_acl
1415

1516

@@ -28,7 +29,7 @@ def _create_json(user, folder):
2829
data = {'user': user, 'folder': folder.as_posix(), 'domain': domain}
2930
with user_file.open('w') as f:
3031
json.dump(data, f)
31-
return user_file, domain
32+
return user_file, data
3233

3334

3435
def _set_rights(folder, domain):
@@ -42,15 +43,19 @@ def register(user, folder):
4243
folder = Path(folder).expanduser().resolve()
4344
if not folder.is_dir():
4445
raise ValueError(f"Folder {folder} not found or not a folder (or no permissions)!")
45-
user_file, domain = _create_json(user, folder)
46+
user_file, data = _create_json(user, folder)
4647
try:
47-
_set_rights(folder, domain)
48+
_set_rights(folder, data['domain'])
4849
except Exception as e:
4950
user_file.unlink()
5051
raise Exception(e)
52+
if eos_exists(dropdir / user_file.name):
53+
eos_rm(dropdir / user_file.name)
54+
print("Replaced existing registration file on server dropdir.")
5155
if cp_to_eos(user_file, dropdir, maximum_trials=1): # returncode 1 means error
5256
user_file.unlink()
5357
raise Exception(f"Failed to copy register file to server dropdir.\n"
5458
+ "Do you have permissions?\n"
5559
+ "If not, add yourself to the CERN xboinc-submitters egroup.")
56-
user_file.rename(user_data_file)
60+
user_file.unlink()
61+
update_user_data(user, data)

xboinc/server/afs.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,75 @@ def afs_print_acl(folder, is_server=False):
7272
log_error(f"Failed to remove ACL on {folder} for user {user}.\n{stderr}", e, is_server=is_server)
7373
return 1
7474

75+
76+
def afs_rm(path, is_server=False):
77+
try:
78+
path = Path(path).expanduser().resolve()
79+
cmd = subprocess.run(['rm', path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
80+
if cmd.returncode == 0:
81+
return 0
82+
else:
83+
stderr = cmd.stderr.decode('UTF-8').strip().split('\n')
84+
log_error(f"Failed afs_rm for {path}!\n{stderr}", is_server=is_server)
85+
return 1
86+
except Exception as e:
87+
log_error(f"Failed afs_rm for {path}!\n", e, is_server=is_server)
88+
return 1
89+
90+
91+
# Always use this file by file, not for a list of files
92+
def cp_from_afs(source, target, maximum_trials=10, wait=2.7, is_server=False):
93+
try:
94+
source = Path(source).expanduser().resolve()
95+
target = Path(target).expanduser().resolve()
96+
for i in range(maximum_trials):
97+
cmd = subprocess.run(['cp', source.as_posix(), target.as_posix()])
98+
if cmd.returncode == 0 and target.exists() and target.stat().st_size!=0:
99+
return 0
100+
if i != maximum_trials-1:
101+
log_debug(f"Failed to copy {str(source)} to {str(target)}!\nRetrying ({i})..", is_server=is_server)
102+
sleep(abs(wait+random.normalvariate(0, 0.1*wait)))
103+
log_error(f"Failed to copy {str(source)} to {str(target)}!", is_server=is_server)
104+
if not target.exists() or target.stat().st_size==0:
105+
log_error(f"Command succeeds but destination file is not created!", is_server=is_server)
106+
else:
107+
stderr = cmd.stderr.decode('UTF-8').strip().split('\n')
108+
log_error(f"Command failed: {stderr}", is_server=is_server)
109+
log_error("\nGiving up.", is_server=is_server)
110+
return 1
111+
except Exception as e:
112+
log_error(f"Failed to copy {str(source)} to {str(target)}!\n", e, is_server=is_server)
113+
return 1
114+
115+
def mv_from_afs(source, target, maximum_trials=10, wait=2.7, is_server=False):
116+
if not cp_from_afs(source, target, maximum_trials, wait, is_server=is_server): # returncode 0 means success
117+
afs_rm(source, is_server=is_server)
118+
119+
120+
# Always use this file by file, not for a list of files
121+
def cp_to_afs(source, target, maximum_trials=10, wait=2.7, is_server=False):
122+
try:
123+
source = Path(source).expanduser().resolve()
124+
target = Path(target).expanduser().resolve()
125+
for i in range(maximum_trials):
126+
cmd = subprocess.run(['cp', source.as_posix(), target.as_posix()])
127+
if cmd.returncode == 0 and target.exists() and target.stat().st_size!=0:
128+
return 0
129+
if i != maximum_trials-1:
130+
log_debug(f"Failed to copy {str(source)} to {str(target)}!\nRetrying ({i})..", is_server=is_server)
131+
sleep(abs(wait+random.normalvariate(0, 0.1*wait)))
132+
log_error(f"Failed to copy {str(source)} to {str(target)}!", is_server=is_server)
133+
if not target.exists() or target.stat().st_size==0:
134+
log_error(f"Command succeeds but destination file is not created!", is_server=is_server)
135+
else:
136+
stderr = cmd.stderr.decode('UTF-8').strip().split('\n')
137+
log_error(f"Command failed: {stderr}", is_server=is_server)
138+
log_error("\nGiving up.", is_server=is_server)
139+
return 1
140+
except Exception as e:
141+
log_error(f"Failed to copy {str(source)} to {str(target)}!\n", e, is_server=is_server)
142+
return 1
143+
144+
def mv_to_afs(source, target, maximum_trials=10, wait=2.7, is_server=False):
145+
if not cp_to_afs(source, target, maximum_trials, wait, is_server=is_server): # returncode 0 means success
146+
source.unlink()

0 commit comments

Comments
 (0)