-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from xsuite/release/v0.2.2
Release 0.2.2
- Loading branch information
Showing
21 changed files
with
330 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "xaux" | ||
version = "0.2.1" | ||
version = "0.2.2" | ||
description = "Support tools for Xsuite packages" | ||
authors = ["Frederik F. Van der Veken <[email protected]>", | ||
"Thomas Pugnat <[email protected]>", | ||
|
@@ -12,7 +12,7 @@ include = ["LICENSE", "NOTICE"] | |
|
||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.8, <3.12" | ||
python = ">=3.8" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = ">=7.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
for f in example_broken_link.txt example_link.txt | ||
do | ||
if [ -h $f ] | ||
then | ||
rm $f | ||
fi | ||
done | ||
|
||
for f in example_file.txt | ||
do | ||
if [ -e $f ] | ||
then | ||
rm $f | ||
fi | ||
done | ||
|
||
rm -r /eos/user/s/sixtadm/test_xboinc/* | ||
rm -r /afs/cern.ch/user/s/sixtadm/public/test_xboinc | ||
rm -r level1 level5_res | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
from xaux import __version__ | ||
|
||
def test_version(): | ||
assert __version__ == '0.2.1' | ||
assert __version__ == '0.2.2' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# copyright ############################### # | ||
# This file is part of the Xaux Package. # | ||
# Copyright (c) CERN, 2024. # | ||
# ######################################### # | ||
|
||
from .release_tools import make_release, make_release_branch, rename_release_branch | ||
from .package_manager import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# copyright ############################### # | ||
# This file is part of the Xaux Package. # | ||
# Copyright (c) CERN, 2024. # | ||
# ######################################### # | ||
|
||
import os | ||
import sys | ||
import json | ||
import importlib | ||
import urllib.request | ||
from shutil import rmtree | ||
from subprocess import run | ||
from contextlib import contextmanager | ||
from packaging.version import Version | ||
|
||
from ..general import _pkg_root | ||
|
||
|
||
_PACKAGE_PATH = _pkg_root / "lib" / "_xaux_pkg_vers" | ||
|
||
xsuite_pkgs = ['xaux', 'xobjects', 'xdeps', 'xtrack', 'xpart', 'xfields', 'xcoll', 'xdyna', 'xboinc'] | ||
|
||
|
||
@contextmanager | ||
def import_package_version(package_name, version, wipe_cache=False): | ||
""" | ||
Context manager to temporarily import a specific version of a package. | ||
""" | ||
package_path = _PACKAGE_PATH / package_name / version | ||
if not package_path.exists(): | ||
install_package_version(package_name, version) | ||
|
||
original_sys_path = sys.path.copy() | ||
original_sys_modules = sys.modules.copy() | ||
original_sys_meta_path = sys.meta_path.copy() | ||
pkgs = _get_available_packages_in_path(package_path) | ||
for pkg in pkgs: | ||
_remove_import_from_sys(pkg) | ||
for finder_name in sys.meta_path: | ||
if package_name in str(finder_name): | ||
sys.meta_path.remove(finder_name) | ||
if wipe_cache: | ||
importlib.invalidate_caches() | ||
for finder_name in sys.meta_path: | ||
if 'editable' in str(finder_name): | ||
sys.meta_path.remove(finder_name) | ||
sys.path.insert(0, package_path.as_posix()) | ||
try: | ||
module = importlib.import_module(package_name) | ||
yield module | ||
finally: | ||
sys.path = original_sys_path | ||
sys.modules = original_sys_modules | ||
sys.meta_path = original_sys_meta_path | ||
|
||
|
||
def install_package_version(package_name, version, overwrite=False): | ||
""" | ||
Installs a specific version of a package. | ||
""" | ||
full_package_name = f"{package_name}=={version}" | ||
package_path = _PACKAGE_PATH / package_name / version | ||
if package_path.exists() and not overwrite: | ||
print(f"Package already installed in {package_path}. " | ||
+ "Use `overwrite=True` if this is the intended goal.") | ||
else: | ||
if package_path.exists(): | ||
rmtree(package_path) | ||
package_path.mkdir(parents=True) | ||
try: | ||
print(f"Installing package {full_package_name}") | ||
cmd = run([sys.executable, "-m", "pip", "install", full_package_name, | ||
f"--target={package_path}"], capture_output=True) | ||
if cmd.returncode != 0: | ||
print(f"Installation failed for {full_package_name}:\n{cmd.stderr.decode()}") | ||
except Exception as e: | ||
print(f"An error occurred: {e}\nCommand output:{cmd.stderr.decode()}") | ||
|
||
|
||
def get_package_versions(package_name): | ||
""" | ||
Get all available versions of a package from PyPI, sorted by newest last. | ||
""" | ||
data = json.loads(urllib.request.urlopen(f"https://pypi.org/pypi/{package_name}/json").read()) | ||
return sorted(list(data['releases'].keys()), key=Version) | ||
|
||
|
||
def get_latest_package_version(package_name): | ||
""" | ||
Get the latest version of a package from PyPI. | ||
""" | ||
data = json.loads(urllib.request.urlopen(f"https://pypi.org/pypi/{package_name}/json").read()) | ||
return data['info']['version'] | ||
|
||
|
||
def get_package_dependencies(package_name): | ||
""" | ||
Get the dependencies of a package from PyPI. | ||
""" | ||
data = json.loads(urllib.request.urlopen(f"https://pypi.org/pypi/{package_name}/json").read()) | ||
return data['info']['requires_dist'] | ||
|
||
|
||
def get_package_version_dependencies(package_name, version, skip=[]): | ||
""" | ||
Get the package versions of the dependencies for a specific version of `package_name`. | ||
TODO: This function is not working as intended when `numpy` is a dependency and already imported. | ||
""" | ||
if not hasattr(skip, '__iter__') or isinstance(skip, str): | ||
skip = [skip] | ||
deps = {} | ||
with import_package_version(package_name, version, wipe_cache=True): | ||
package_path = _PACKAGE_PATH / package_name / version | ||
pkgs = _get_available_packages_in_path(package_path) | ||
pkgs = [pkg for pkg in pkgs if pkg not in skip] | ||
# for pkg in pkgs: | ||
# _remove_import_from_sys(pkg) | ||
for pkg in pkgs: | ||
if pkg in ['numpy', 'numba', 'scipy']: | ||
# These are being difficult | ||
deps[pkg] = None | ||
else: | ||
# mod = _import_package_from_path(pkg, package_path) | ||
mod = importlib.import_module(pkg) | ||
assert mod.__file__.startswith(package_path.as_posix()) | ||
deps[pkg] = mod.__version__ if hasattr(mod, '__version__') else None | ||
return deps | ||
|
||
|
||
def _get_available_packages_in_path(path): | ||
return [pkg.name for pkg in path.glob('*') if (path / pkg).is_dir() \ | ||
and not pkg.name.startswith('_') and not '.' in pkg.name \ | ||
and not pkg.name.endswith('dist-info') and not pkg.name == 'bin'] | ||
|
||
|
||
def _remove_import_from_sys(package_name): | ||
for mod_name in list(sys.modules): | ||
if package_name == mod_name or mod_name.startswith(package_name + '.'): | ||
del sys.modules[mod_name] | ||
|
||
def _import_package_from_path(package_name, package_path): | ||
original_sys_path = sys.path.copy() | ||
original_sys_meta_path = sys.meta_path.copy() | ||
for finder_name in sys.meta_path: | ||
if package_name in str(finder_name): | ||
sys.meta_path.remove(finder_name) | ||
sys.path.insert(0, package_path.as_posix()) | ||
module = importlib.import_module(package_name) | ||
sys.path = original_sys_path | ||
sys.meta_path = original_sys_meta_path | ||
return module |
Oops, something went wrong.