Skip to content

Commit e5f1c5b

Browse files
authored
Merge pull request #16 from xsuite/release/v0.2.1
Release 0.2.1
2 parents 4fabad9 + e757b0d commit e5f1c5b

File tree

8 files changed

+38
-69
lines changed

8 files changed

+38
-69
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "xaux"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Support tools for Xsuite packages"
55
authors = ["Frederik F. Van der Veken <[email protected]>",
66
"Thomas Pugnat <[email protected]>",
@@ -13,7 +13,6 @@ include = ["LICENSE", "NOTICE"]
1313

1414
[tool.poetry.dependencies]
1515
python = ">=3.8, <3.12"
16-
numpy = ">=1.0"
1716

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

tests/test_fs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
import os
88
import pytest
9-
import numpy as np
109

1110
from xaux.fs import *
1211
from xaux.fs.afs import _fs_installed
@@ -199,13 +198,13 @@ def test_nested_fs(test_user):
199198
expected = [EosPath, AfsPath, EosPath, LocalPath, AfsPath,
200199
AfsPath, AfsPath, AfsPath, AfsPath, AfsPath,
201200
AfsPath, LocalPath, LocalPath]
202-
assert np.all([isinstance(f, exp) for f, exp in zip(parents, expected)])
201+
assert all([isinstance(f, exp) for f, exp in zip(parents, expected)])
203202
assert isinstance(path.resolve(), AfsPath)
204203
parents_res = [f.resolve() for f in path.parents]
205204
expected_res = [LocalPath, EosPath, AfsPath, EosPath, LocalPath,
206205
AfsPath, AfsPath, AfsPath, AfsPath, AfsPath,
207206
AfsPath, LocalPath, LocalPath]
208-
assert np.all([isinstance(f, exp) for f, exp in zip(parents_res, expected_res)])
207+
assert all([isinstance(f, exp) for f, exp in zip(parents_res, expected_res)])
209208

210209
level1.unlink()
211210
level2.unlink()

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
from xaux import __version__
77

88
def test_version():
9-
assert __version__ == '0.2.0'
9+
assert __version__ == '0.2.1'
1010

xaux/fs/fs_methods.py

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

66
import os
7-
from numpy import prod
7+
from math import prod
88
from subprocess import run, PIPE, CalledProcessError
99

1010

xaux/fs/io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# ######################################### #
55

66
import os
7-
import numpy as np
87
from shutil import copy2, copytree
98
from subprocess import run, PIPE
109
import warnings

xaux/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
# ===================
1111
# Do not change
1212
# ===================
13-
__version__ = '0.2.0'
13+
__version__ = '0.2.1'
1414
# ===================

xaux/protectfile.py

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -259,35 +259,6 @@ def __init__(self, *args, **kwargs):
259259
self._wait(wait)
260260
continue
261261

262-
except FileExistsError:
263-
# Lockfile exists, wait and try again
264-
self._wait(wait)
265-
if max_lock_time is not None:
266-
try:
267-
kill_lock = False
268-
try:
269-
with self.lockfile.open('r') as fid:
270-
info = json.load(fid)
271-
except:
272-
continue
273-
if 'free_after' in info and int(info['free_after']) > 0 \
274-
and int(info['free_after']) < time.time():
275-
# We free the original process by deleting the lockfile
276-
# and then we go to the next step in the while loop.
277-
# Note that this does not necessarily imply this process
278-
# gets to use the file; which is the intended behaviour
279-
# (first one wins).
280-
kill_lock = True
281-
if kill_lock:
282-
self.lockfile.unlink()
283-
self._print_debug("init",f"freed {self.lockfile} because "
284-
+ "of exceeding max_lock_time")
285-
except FileNotFoundError:
286-
# All is fine, the lockfile disappeared in the meanwhile.
287-
# Return to the while loop.
288-
continue
289-
continue
290-
291262
except PermissionError:
292263
# Special case: we can still access eos files when permission has expired, using `eos`
293264
if isinstance(self.file, EosPath):
@@ -315,35 +286,36 @@ def __init__(self, *args, **kwargs):
315286
raise PermissionError(f"Cannot access {self.lockfile}; permission denied.")
316287

317288
except OSError:
318-
# An error happened while trying to generate the Lockfile. This raised an
319-
# OSError: [Errno 5] Input/output error!
289+
# Two typical cases: the lockfile already exists (FileExistsError, a subclass of OSError),
290+
# or an input/output error happened while trying to generate it (generic OSError).
291+
# In both cases, we wait a bit and try again.
320292
self._wait(wait)
321-
if self.lockfile.exists():
322-
# if max_lock_time is not None and self.lockfile.exists():
323-
try:
324-
kill_lock = False
325-
try:
326-
with self.lockfile.open('r') as fid:
327-
info = json.load(fid)
328-
except:
329-
continue
330-
if 'free_after' in info and int(info['free_after']) > 0 \
331-
and int(info['free_after']) < time.time():
332-
# We free the original process by deleting the lockfile
333-
# and then we go to the next step in the while loop.
334-
# Note that this does not necessarily imply this process
335-
# gets to use the file; which is the intended behaviour
336-
# (first one wins).
337-
kill_lock = True
338-
if kill_lock:
339-
self.lockfile.unlink()
340-
self._print_debug("init",f"freed {self.lockfile} because "
341-
+ "of exceeding max_lock_time")
342-
except FileNotFoundError:
343-
# All is fine, the lockfile disappeared in the meanwhile.
344-
# Return to the while loop.
345-
continue
346-
continue
293+
# We also have to capture the case where the lockfile expired and can be freed.
294+
# So we try to read it and look for the timeout period; if this fails (e.g. because the
295+
# lock disappeared in the meanwhile), we continue the mainloop
296+
try:
297+
kill_lock = False
298+
with self.lockfile.open('r') as fid:
299+
info = json.load(fid)
300+
if 'free_after' in info and int(info['free_after']) > 0 \
301+
and int(info['free_after']) < time.time():
302+
# We free the original process by deleting the lockfile
303+
# and then we go to the next step in the while loop.
304+
# Note that this does not necessarily imply this process
305+
# gets to use the file; which is the intended behaviour
306+
# (first one wins).
307+
kill_lock = True
308+
if kill_lock:
309+
self.lockfile.unlink()
310+
self._print_debug("init",f"freed {self.lockfile} because "
311+
+ "of exceeding max_lock_time")
312+
# Whether or not the lockfile was freed, we continue to the main loop
313+
continue
314+
315+
except (OSError, json.JSONDecodeError):
316+
# Any error in trying to read (and potentially kill the lock) implies
317+
# a return to the main loop
318+
continue
347319

348320
# Success!
349321
self._access = True

xaux/tools/release_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import sys
77
import platform
8-
import requests
8+
import urllib.request
99
from .gh import *
1010

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

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

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

0 commit comments

Comments
 (0)