Skip to content

Commit

Permalink
Merge pull request #16 from xsuite/release/v0.2.1
Browse files Browse the repository at this point in the history
Release 0.2.1
  • Loading branch information
freddieknets authored Oct 28, 2024
2 parents 4fabad9 + e757b0d commit e5f1c5b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 69 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "xaux"
version = "0.2.0"
version = "0.2.1"
description = "Support tools for Xsuite packages"
authors = ["Frederik F. Van der Veken <[email protected]>",
"Thomas Pugnat <[email protected]>",
Expand All @@ -13,7 +13,6 @@ include = ["LICENSE", "NOTICE"]

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

[tool.poetry.dev-dependencies]
pytest = ">=7.3"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
import os
import pytest
import numpy as np

from xaux.fs import *
from xaux.fs.afs import _fs_installed
Expand Down Expand Up @@ -199,13 +198,13 @@ def test_nested_fs(test_user):
expected = [EosPath, AfsPath, EosPath, LocalPath, AfsPath,
AfsPath, AfsPath, AfsPath, AfsPath, AfsPath,
AfsPath, LocalPath, LocalPath]
assert np.all([isinstance(f, exp) for f, exp in zip(parents, expected)])
assert all([isinstance(f, exp) for f, exp in zip(parents, expected)])
assert isinstance(path.resolve(), AfsPath)
parents_res = [f.resolve() for f in path.parents]
expected_res = [LocalPath, EosPath, AfsPath, EosPath, LocalPath,
AfsPath, AfsPath, AfsPath, AfsPath, AfsPath,
AfsPath, LocalPath, LocalPath]
assert np.all([isinstance(f, exp) for f, exp in zip(parents_res, expected_res)])
assert all([isinstance(f, exp) for f, exp in zip(parents_res, expected_res)])

level1.unlink()
level2.unlink()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from xaux import __version__

def test_version():
assert __version__ == '0.2.0'
assert __version__ == '0.2.1'

2 changes: 1 addition & 1 deletion xaux/fs/fs_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ######################################### #

import os
from numpy import prod
from math import prod
from subprocess import run, PIPE, CalledProcessError


Expand Down
1 change: 0 additions & 1 deletion xaux/fs/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# ######################################### #

import os
import numpy as np
from shutil import copy2, copytree
from subprocess import run, PIPE
import warnings
Expand Down
2 changes: 1 addition & 1 deletion xaux/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# ===================
# Do not change
# ===================
__version__ = '0.2.0'
__version__ = '0.2.1'
# ===================
86 changes: 29 additions & 57 deletions xaux/protectfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,35 +259,6 @@ def __init__(self, *args, **kwargs):
self._wait(wait)
continue

except FileExistsError:
# Lockfile exists, wait and try again
self._wait(wait)
if max_lock_time is not None:
try:
kill_lock = False
try:
with self.lockfile.open('r') as fid:
info = json.load(fid)
except:
continue
if 'free_after' in info and int(info['free_after']) > 0 \
and int(info['free_after']) < time.time():
# We free the original process by deleting the lockfile
# and then we go to the next step in the while loop.
# Note that this does not necessarily imply this process
# gets to use the file; which is the intended behaviour
# (first one wins).
kill_lock = True
if kill_lock:
self.lockfile.unlink()
self._print_debug("init",f"freed {self.lockfile} because "
+ "of exceeding max_lock_time")
except FileNotFoundError:
# All is fine, the lockfile disappeared in the meanwhile.
# Return to the while loop.
continue
continue

except PermissionError:
# Special case: we can still access eos files when permission has expired, using `eos`
if isinstance(self.file, EosPath):
Expand Down Expand Up @@ -315,35 +286,36 @@ def __init__(self, *args, **kwargs):
raise PermissionError(f"Cannot access {self.lockfile}; permission denied.")

except OSError:
# An error happened while trying to generate the Lockfile. This raised an
# OSError: [Errno 5] Input/output error!
# Two typical cases: the lockfile already exists (FileExistsError, a subclass of OSError),
# or an input/output error happened while trying to generate it (generic OSError).
# In both cases, we wait a bit and try again.
self._wait(wait)
if self.lockfile.exists():
# if max_lock_time is not None and self.lockfile.exists():
try:
kill_lock = False
try:
with self.lockfile.open('r') as fid:
info = json.load(fid)
except:
continue
if 'free_after' in info and int(info['free_after']) > 0 \
and int(info['free_after']) < time.time():
# We free the original process by deleting the lockfile
# and then we go to the next step in the while loop.
# Note that this does not necessarily imply this process
# gets to use the file; which is the intended behaviour
# (first one wins).
kill_lock = True
if kill_lock:
self.lockfile.unlink()
self._print_debug("init",f"freed {self.lockfile} because "
+ "of exceeding max_lock_time")
except FileNotFoundError:
# All is fine, the lockfile disappeared in the meanwhile.
# Return to the while loop.
continue
continue
# We also have to capture the case where the lockfile expired and can be freed.
# So we try to read it and look for the timeout period; if this fails (e.g. because the
# lock disappeared in the meanwhile), we continue the mainloop
try:
kill_lock = False
with self.lockfile.open('r') as fid:
info = json.load(fid)
if 'free_after' in info and int(info['free_after']) > 0 \
and int(info['free_after']) < time.time():
# We free the original process by deleting the lockfile
# and then we go to the next step in the while loop.
# Note that this does not necessarily imply this process
# gets to use the file; which is the intended behaviour
# (first one wins).
kill_lock = True
if kill_lock:
self.lockfile.unlink()
self._print_debug("init",f"freed {self.lockfile} because "
+ "of exceeding max_lock_time")
# Whether or not the lockfile was freed, we continue to the main loop
continue

except (OSError, json.JSONDecodeError):
# Any error in trying to read (and potentially kill the lock) implies
# a return to the main loop
continue

# Success!
self._access = True
Expand Down
6 changes: 3 additions & 3 deletions xaux/tools/release_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys
import platform
import requests
import urllib.request
from .gh import *

class VersionError(OSError):
Expand Down Expand Up @@ -146,7 +146,7 @@ def dev_release(package, bump=None, force=False, allow_major=False):
git_make_tag(f"v{new_ver}")

print("Creating draft release and publishing to PyPi...")
gh_release_create(f"v{new_ver}", f"{package}.capitalize() release {new_ver}", draft=True)
gh_release_create(f"v{new_ver}", f"{package.capitalize()} release {new_ver}", draft=True)
poetry_publish(build=True)

print("All done!")
Expand Down Expand Up @@ -205,7 +205,7 @@ def _set_dependencies(package):
xsuite_pkgs.remove(package)
latest_version = {}
for pkg in xsuite_pkgs:
data = requests.get(f"https://pypi.org/pypi/{pkg}/json").json()
data = json.loads(urllib.request.urlopen(f"https://pypi.org/pypi/{pkg}/json").read())
latest_version[pkg] = data['info']['version']
with Path("pyproject.toml").open("r") as fid:
lines = fid.readlines()
Expand Down

0 comments on commit e5f1c5b

Please sign in to comment.