Skip to content

Commit

Permalink
Merge pull request #14 from xsuite/release/v0.2.0
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
freddieknets authored Oct 28, 2024
2 parents e83f4fd + 14bf05a commit 4fabad9
Show file tree
Hide file tree
Showing 33 changed files with 3,853 additions and 586 deletions.
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This product includes software developed by:
* [CERN](http://home.cern)
4 changes: 2 additions & 2 deletions install_protection_hook.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# copyright ############################### #
# This file is part of the Xcoll Package. #
# This file is part of the Xaux package. #
# Copyright (c) CERN, 2023. #
# ######################################### #

Expand All @@ -18,7 +18,7 @@ then
exit 1
fi
for file in pyproject.toml version.sh LICENSE install_protection_hook.sh xcoll/general.py
for file in pyproject.toml gh.py release.py make_release_branch.py rename_release_branch.py LICENSE install_protection_hook.sh xaux/general.py
do
git diff --name-only | grep '^'${file}'$' &> /dev/null
if [ $? -eq 0 ]
Expand Down
11 changes: 11 additions & 0 deletions make_release_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# copyright ############################### #
# This file is part of the Xaux package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

from xaux.tools import dev_make_release_branch
# sys.tracebacklimit = 0


dev_make_release_branch("xaux")
32 changes: 26 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
[tool.poetry]
name = "xaux"
version = "0.1.3"
version = "0.2.0"
description = "Support tools for Xsuite packages"
authors = ["Frederik Van der Veken <[email protected]>",
"Konstantinos Paraschou <[email protected]"]
license = "Apache 2.0"
authors = ["Frederik F. Van der Veken <[email protected]>",
"Thomas Pugnat <[email protected]>",
"Konstantinos Paraschou <[email protected]"
]
readme = "README.md"
license = "Apache 2.0"
include = ["LICENSE", "NOTICE"]


[tool.poetry.dependencies]
python = "^3.9"
python = ">=3.8, <3.12"
numpy = ">=1.0"

[tool.poetry.dev-dependencies]
pytest = ">=7.3"

[tool.poetry.extras]
tests = ["pytest"]

[build-system]
requires = ["poetry-core"]
# Needed for pip install -e (BTW: need pip version 22)
requires = ["poetry-core>=1.0.8"]
build-backend = "poetry.core.masonry.api"

# pyproject.toml
[tool.pytest.ini_options]
addopts = "-ra --durations=10 --durations-min=1"
python_functions = ["test_"]
testpaths = [
"tests",
]

11 changes: 11 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# copyright ############################### #
# This file is part of the Xaux package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

from xaux.tools import dev_release
# sys.tracebacklimit = 0


dev_release("xaux")
11 changes: 11 additions & 0 deletions rename_release_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# copyright ############################### #
# This file is part of the Xaux package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

from xaux.tools import dev_rename_release_branch
# sys.tracebacklimit = 0


dev_rename_release_branch("xaux")
62 changes: 39 additions & 23 deletions tests/_test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
# copyright ############################### #
# This file is part of the Xaux Package. #
# Copyright (c) CERN, 2024. #
# ######################################### #

import time
import json
from pathlib import Path
import shutil
import os
import signal

from xaux import ProtectFile

from xaux import ProtectFile, FsPath

ProtectFile._debug = True
ProtectFile._testing = True


def rewrite(pf, with_copy=False):
def rewrite(pf, runtime=0.2):
data = json.load(pf)
time.sleep(0.2)
time.sleep(runtime)
data["myint"] += 1
if not with_copy:
pf.seek(0) # revert point to beginning of file
json.dump(data, pf, indent=4, sort_keys=True)
pf.truncate()
else: # write to another file and copy back
cfname = "_copy_" + pf.name
with open(cfname, "w") as cf:
json.dump(data, cf, indent=4, sort_keys=True)
shutil.copyfile(cfname, pf.name)
Path.unlink(Path(cfname))


def change_file_protected(fname, with_copy=False, max_lock_time=None, error_queue=None):
pf.seek(0) # revert point to beginning of file
json.dump(data, pf, indent=4, sort_keys=True)
pf.truncate()


def change_file_protected(fname, max_lock_time=None, error_queue=None, wait=0.1, runtime=0.2, job_id=None):
try:
with ProtectFile(fname, "r+", backup=False, wait=0.1, max_lock_time=max_lock_time) as pf:
rewrite(pf, with_copy=with_copy)
if job_id:
t0 = time.time()
print(f"Job {job_id} started (stamp {t0})", flush=True)
with ProtectFile(fname, "r+", wait=wait, max_lock_time=max_lock_time) as pf:
if job_id:
t1 = time.time()
print(f"Job {job_id} in protectfile (init duration: {int(1e3*(t1 - t0))}ms)", flush=True)
rewrite(pf, runtime)
if job_id:
t2 = time.time()
print(f"Job {job_id} finished process in protectfile (process duration: {int(1e3*(t2 - t1))}ms)", flush=True)
if job_id:
t3 = time.time()
print(f"Job {job_id} done (total duration: {int(1e3*(t3-t0))}ms, exit duration {int(1e3*(t3-t2))}ms, stamp {t2})", flush=True)
except Exception as e:
if error_queue is None:
raise e
Expand All @@ -39,19 +48,26 @@ def change_file_protected(fname, with_copy=False, max_lock_time=None, error_queu
return


def change_file_standard(fname, with_copy=False):
def change_file_standard(fname):
with open(fname, "r+") as pf: # fails with this context
rewrite(pf)
return


def init_file(fname):
# Remove leftover lockfiles
for f in Path.cwd().glob(f"{fname}.lock*"):
for f in FsPath.cwd().glob(f"{fname}.lock*"):
f.unlink()

# Initialise file
with ProtectFile(fname, "w", backup=False, wait=1) as pf:
t_prev = time.time()
with ProtectFile(fname, "w", wait=0.1) as pf:
init_time = time.time() - t_prev
json.dump({"myint": 0}, pf, indent=4)
dump_time = time.time() - t_prev - init_time
exit_time = time.time() - t_prev - init_time - dump_time

return init_time, dump_time, exit_time # These are the times taken by the ProtectFile process


def propagate_child_errors(error_queue):
Expand Down
52 changes: 52 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest
from pathlib import Path
import getpass
import warnings

from xaux.fs import afs_accessible, eos_accessible


def pytest_addoption(parser):
parser.addoption(
"--user", action="store", default="sixtadm", help="Specify the user that has access to EOS and AFS."
)


@pytest.fixture(scope="session")
def test_user(request):
test_user = request.config.getoption("--user")
afs_path = f"/afs/cern.ch/user/{test_user[0]}/{test_user}/public/test_xboinc/"
eos_path = f"/eos/user/{test_user[0]}/{test_user}/test_xboinc/"
skip_afs = True
if afs_accessible:
afs_paths_tried = [afs_path]
if Path(afs_path).is_dir():
skip_afs = False
else:
test_user = getpass.getuser()
afs_path = f"/afs/cern.ch/user/{test_user[0]}/{test_user}/public/test_xboinc/"
if Path(afs_path).is_dir():
skip_afs = False
else:
afs_paths_tried.append(afs_path)
warnings.warn("AFS test directory not accessible.\nPlease ensure the directory exists and verify "
+ "your access rights (is your ticket still alive?).\nAlternatively, specify the test "
+ "user account with the option `--user username`\nI Tried the following paths:\n "
+ "\n ".join(afs_paths_tried) + "\nThe relevant AfsPath tests will be skipped.")
skip_eos = True
if eos_accessible:
eos_paths_tried = [eos_path]
if Path(eos_path).is_dir():
skip_eos = False
else:
# Do not overwrite test_user (as it will be used by the AFS ACL test)
eos_path = f"/eos/user/{getpass.getuser()[0]}/{getpass.getuser()}/test_xboinc/"
if Path(eos_path).is_dir():
skip_eos = False
else:
eos_paths_tried.append(eos_path)
warnings.warn("EOS test directory not accessible.\nPlease ensure the directory exists and verify "
+ "your access rights (is your ticket still alive?).\nAlternatively, specify the test "
+ "user account with the option `--user username`\nI Tried the following paths:\n "
+ "\n ".join(eos_paths_tried) + "\nThe relevant EosPath tests will be skipped.")
return {"test_user": test_user, "afs_path": afs_path, "skip_afs": skip_afs, "eos_path": eos_path, "skip_eos": skip_eos}
12 changes: 12 additions & 0 deletions tests/pytest_all_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# files="test_fs.py test_fs_api.py test_fs_afs.py test_fs_eos.py"
files=''

for i in 8 9 10 11 # 12 13
do
source ~/miniforge3/bin/activate python3.$i
python -c "import sys; print(f'Testing xaux FS in Python version {sys.version.split()[0]}')"
pytest $files
source ~/miniforge3/bin/activate
done
Loading

0 comments on commit 4fabad9

Please sign in to comment.