nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1diff --git a/fipy/meshes/gmshMesh.py b/fipy/meshes/gmshMesh.py
2index fc3ff6c8..d529d532 100755
3--- a/fipy/meshes/gmshMesh.py
4+++ b/fipy/meshes/gmshMesh.py
5@@ -13,11 +13,11 @@ import sys
6 import tempfile
7 from textwrap import dedent
8 import warnings
9-from distutils.version import StrictVersion
10
11 from fipy.tools import numerix as nx
12 from fipy.tools import parallelComm
13 from fipy.tools import serialComm
14+from fipy.tools.version import Version, parse_version
15 from fipy.tests.doctestPlus import register_skipper
16
17 from fipy.meshes.mesh import Mesh
18@@ -38,7 +38,7 @@ def _checkForGmsh():
19 hasGmsh = True
20 try:
21 version = _gmshVersion(communicator=parallelComm)
22- hasGmsh = version >= StrictVersion("2.0")
23+ hasGmsh = version >= Version("2.0")
24 except Exception:
25 hasGmsh = False
26 return hasGmsh
27@@ -68,6 +68,7 @@ def gmshVersion(communicator=parallelComm):
28 while True:
29 try:
30 # gmsh returns version in stderr (Why?!?)
31+ # (newer versions of gmsh return the version in stdout)
32 # spyder on Windows throws
33 # OSError: [WinError 6] The handle is invalid
34 # if we don't PIPE stdout, too
35@@ -77,8 +78,11 @@ def gmshVersion(communicator=parallelComm):
36 break
37
38 try:
39- out, verStr = p.communicate()
40- verStr = verStr.decode('ascii').strip()
41+ out, err = p.communicate()
42+ verStr = err.decode('ascii').strip()
43+ if not verStr:
44+ # newer versions of gmsh return the version in stdout
45+ verStr = out.decode('ascii').strip()
46 break
47 except IOError:
48 # some weird conflict with things like PyQT can cause
49@@ -93,12 +97,12 @@ def gmshVersion(communicator=parallelComm):
50 def _gmshVersion(communicator=parallelComm):
51 version = gmshVersion(communicator) or "0.0"
52 try:
53- version = StrictVersion(version)
54+ version = parse_version(version)
55 except ValueError:
56 # gmsh returns the version string in stderr,
57 # which means it's often unparsable due to irrelevant warnings
58 # assume it's OK and move on
59- version = StrictVersion("3.0")
60+ version = Version("3.0")
61
62 return version
63
64@@ -133,7 +137,7 @@ def openMSHFile(name, dimensions=None, coordDimensions=None, communicator=parall
65
66 # Enforce gmsh version to be either >= 2 or 2.5, based on Nproc.
67 version = _gmshVersion(communicator=communicator)
68- if version < StrictVersion("2.0"):
69+ if version < Version("2.0"):
70 raise EnvironmentError("Gmsh version must be >= 2.0.")
71
72 # If we're being passed a .msh file, leave it be. Otherwise,
73@@ -176,9 +180,11 @@ def openMSHFile(name, dimensions=None, coordDimensions=None, communicator=parall
74 gmshFlags = ["-%d" % dimensions, "-nopopup"]
75
76 if communicator.Nproc > 1:
77- if not (StrictVersion("2.5") < version <= StrictVersion("4.0")):
78- warnstr = "Cannot partition with Gmsh version < 2.5 or >= 4.0. " \
79- + "Reverting to serial."
80+ if ((version < Version("2.5"))
81+ or (Version("4.0") <= version < Version("4.5.2"))):
82+ warnstr = ("Cannot partition with Gmsh version < 2.5 "
83+ "or 4.0 <= version < 4.5.2. "
84+ "Reverting to serial.")
85 warnings.warn(warnstr, RuntimeWarning, stacklevel=2)
86 communicator = serialComm
87
88@@ -188,13 +194,13 @@ def openMSHFile(name, dimensions=None, coordDimensions=None, communicator=parall
89 raise ValueError("'dimensions' must be specified to generate a mesh from a geometry script")
90 else: # gmsh version is adequate for partitioning
91 gmshFlags += ["-part", "%d" % communicator.Nproc]
92- if version >= StrictVersion("4.0"):
93+ if version >= Version("4.0"):
94 # Gmsh 4.x needs to be told to generate ghost cells
95- # Unfortunately, the ghosts are broken
96+ # Unfortunately, the ghosts are broken in Gmsh 4.0--4.5.1
97 # https://gitlab.onelab.info/gmsh/gmsh/issues/733
98 gmshFlags += ["-part_ghosts"]
99
100- gmshFlags += ["-format", "msh2"]
101+ gmshFlags += ["-format", "msh2", "-smooth", "8"]
102
103 if background is not None:
104 if communicator.procID == 0:
105@@ -1387,6 +1393,11 @@ class _GmshTopology(_MeshTopology):
106 class Gmsh2D(Mesh2D):
107 """Construct a 2D Mesh using Gmsh
108
109+ If called in parallel, the mesh will be partitioned based on the value
110+ of `parallelComm.Nproc`. If an `MSH` file is supplied, it must have
111+ been previously partitioned with the number of partitions matching
112+ `parallelComm.Nproc`.
113+
114 >>> radius = 5.
115 >>> side = 4.
116 >>> squaredCircle = Gmsh2D('''
117@@ -1875,6 +1886,11 @@ class Gmsh2D(Mesh2D):
118 class Gmsh2DIn3DSpace(Gmsh2D):
119 """Create a topologically 2D Mesh in 3D coordinates using Gmsh
120
121+ If called in parallel, the mesh will be partitioned based on the value
122+ of `parallelComm.Nproc`. If an `MSH` file is supplied, it must have
123+ been previously partitioned with the number of partitions matching
124+ `parallelComm.Nproc`.
125+
126 Parameters
127 ----------
128 arg : str
129@@ -1959,6 +1975,11 @@ class Gmsh2DIn3DSpace(Gmsh2D):
130 class Gmsh3D(Mesh):
131 """Create a 3D Mesh using Gmsh
132
133+ If called in parallel, the mesh will be partitioned based on the value
134+ of `parallelComm.Nproc`. If an `MSH` file is supplied, it must have
135+ been previously partitioned with the number of partitions matching
136+ `parallelComm.Nproc`.
137+
138 Parameters
139 ----------
140 arg : str
141@@ -2225,7 +2246,7 @@ class GmshGrid2D(Gmsh2D):
142 width = nx * dx
143 numLayers = int(ny / float(dy))
144
145- if _gmshVersion() < StrictVersion("2.7"):
146+ if _gmshVersion() < Version("2.7"):
147 # kludge: must offset cellSize by `eps` to work properly
148 eps = float(dx)/(nx * 10)
149 else:
150@@ -2299,7 +2320,7 @@ class GmshGrid3D(Gmsh3D):
151 width = nx * dx
152 depth = nz * dz
153
154- if _gmshVersion() < StrictVersion("2.7"):
155+ if _gmshVersion() < Version("2.7"):
156 # kludge: must offset cellSize by `eps` to work properly
157 eps = float(dx)/(nx * 10)
158 else:
159diff --git a/fipy/tools/version.py b/fipy/tools/version.py
160new file mode 100644
161index 00000000..93d89c18
162--- /dev/null
163+++ b/fipy/tools/version.py
164@@ -0,0 +1,18 @@
165+"""Shim for version checking
166+
167+`distutils.version` is deprecated, but `packaging.version` is unavailable
168+in Python 2.7
169+"""
170+from __future__ import unicode_literals
171+
172+__docformat__ = 'restructuredtext'
173+
174+
175+__all__ = ["Version", "parse_version"]
176+from future.utils import text_to_native_str
177+__all__ = [text_to_native_str(n) for n in __all__]
178+
179+try:
180+ from packaging.version import Version, parse as parse_version
181+except ImportError:
182+ from distutils.version import StrictVersion as Version, StrictVersion as parse_version