Fix numpy bug with alen()

* The numpy.alen() function is deprecated. We use len() instead
* The use of pkg_resources is discouraged. We use importlib.metadata
  instead. I also removed setuptools_scm get_version. I switch to
  a simple call to "git describe", easier now that we use git flow
* The build fails with python3.10 if compiling wx from sources.
  A fix in the Makefile will be proposed in a future commit.
This commit is contained in:
Sylvain Tricot 2022-10-06 18:19:16 +02:00
parent b6f2531999
commit 2bdc9943b9
4 changed files with 22 additions and 22 deletions

View File

@ -41,6 +41,8 @@ _build_wx/wxPython.target:
@$(INSIDE_VENV) echo "Building wxPython for your `python --version 2>&1` under Linux $(DISTRO_RELEASE)..."
# Create a folder to build wx into
@mkdir -p _build_wx
@$(INSIDE_VENV) pip install attrdict sip
# TODO: attrdict is no longer compatible with collections package. The build will fail
# download the wheel or the source if it cannot find a wheel
@$(INSIDE_VENV) cd _build_wx && pip download -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/$(DISTRO_RELEASE) wxPython
# Build the source if a tar.gz was downloaded

View File

@ -18,8 +18,8 @@
# along with this msspec. If not, see <http://www.gnu.org/licenses/>.
#
# Source file : src/msspec/utils.py
# Last modified: ven. 10 avril 2020 15:49:35
# Committed by : "Sylvain Tricot <sylvain.tricot@univ-rennes1.fr>"
# Last modified: Thu, 06 Oct 2022 18:19:16 +0200
# Committed by : Sylvain Tricot <sylvain.tricot@univ-rennes1.fr> 1665073156 +0200
"""
@ -480,7 +480,7 @@ def hemispherical_cluster(cluster, emitter_tag=0, emitter_plane=0, diameter=0,
a = cell[:, 0].max() # a lattice parameter
# the number of planes in the cluster
p = np.alen(np.unique(np.round(cluster.get_positions()[:, 2], 4)))
p = len(np.unique(np.round(cluster.get_positions()[:, 2], 4)))
# the symbol of your emitter
symbol = cluster[np.where(cluster.get_tags() == emitter_tag)[0][0]].symbol
@ -585,7 +585,7 @@ def hemispherical_cluster(cluster, emitter_tag=0, emitter_plane=0, diameter=0,
# an array of all unique remaining z
all_z = np.sort(np.unique(np.round(cluster.get_positions()[:, 2], 4)))
assert emitter_plane < np.alen(all_z), ("There are not enough existing "
assert emitter_plane < len(all_z), ("There are not enough existing "
"plans.")
ze = all_z[- emitter_plane - 1] # the z-coordinate of the emitter
Atoms.translate(cluster, [0, 0, -ze]) # put the emitter in (0,0,0)

View File

@ -16,39 +16,38 @@
# along with this msspec. If not, see <http://www.gnu.org/licenses/>.
#
# Source file : src/msspec/version.py
# Last modified: ven. 10 avril 2020 17:34:38
# Committed by : "Sylvain Tricot <sylvain.tricot@univ-rennes1.fr>"
# Last modified: Thu, 06 Oct 2022 18:19:16 +0200
# Committed by : Sylvain Tricot <sylvain.tricot@univ-rennes1.fr> 1665073156 +0200
import os
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution
from pkg_resources import parse_version
from importlib.metadata import version
import subprocess
# find the version number
# 1- Try to read it from the git info
# 2- If it fails, try to read it from the distribution file
# 1- If it fails, try to read it from the distribution file
# 2- Try to read it from the git info
# 3- If it fails, try to read it from the VERSION file
PKGNAME = 'msspec'
try:
from setuptools_scm import get_version
v = get_version(root='../../', relative_to=__file__, version_scheme="post-release")
v = parse_version(v)
if v._version.post[-1] == 0:
__version__ = v.base_version
else:
__version__ = v.public
__version__ = version(PKGNAME)
except Exception as err:
try:
__version__ = get_distribution(__name__.strip('.version')).version
p = subprocess.run(["git", "describe"], capture_output=True, text=True)
if p.stdout not in ("", None):
__version__ = p.stdout.strip()
else:
raise NameError("git describe failed!")
except Exception as err:
try:
thisfile_path = os.path.abspath(__file__)
thisfile_dir = os.path.dirname(thisfile_path)
versionfile = os.path.join(thisfile_dir, "../VERSION")
with open(versionfile, "r") as fd:
__version__ = fd.readline()
__version__ = fd.readline().strip()
except Exception as err:
print("Unable to get the version number!")
__version__ = "9.9.9"

View File

@ -41,8 +41,7 @@ F2PYFLAGS_DBG = --debug-capi --debug
# /!\ DO NOT EDIT BELOW THAT LINE (unlesss you know what you're doing...) #
# CORE CONFIGURATION #
################################################################################
#VERSION:=$(shell python -c "import msspec; print(msspec.__version__)")
VERSION:=$(shell git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/')
VERSION:=$(shell git describe)
VENV_PATH := $(INSTALL_PREFIX)/src/msspec_venv_$(VERSION)