COMPAS 2.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (468) hide show
  1. compas/__init__.py +274 -0
  2. compas/__main__.py +31 -0
  3. compas/_iotools.py +80 -0
  4. compas/_os.py +746 -0
  5. compas/colors/__init__.py +14 -0
  6. compas/colors/cmcrameri/acton.txt +256 -0
  7. compas/colors/cmcrameri/actonS.txt +100 -0
  8. compas/colors/cmcrameri/bam.txt +256 -0
  9. compas/colors/cmcrameri/bamO.txt +256 -0
  10. compas/colors/cmcrameri/bamako.txt +256 -0
  11. compas/colors/cmcrameri/bamakoS.txt +100 -0
  12. compas/colors/cmcrameri/batlow.txt +256 -0
  13. compas/colors/cmcrameri/batlowK.txt +256 -0
  14. compas/colors/cmcrameri/batlowS.txt +100 -0
  15. compas/colors/cmcrameri/batlowW.txt +256 -0
  16. compas/colors/cmcrameri/berlin.txt +256 -0
  17. compas/colors/cmcrameri/bilbao.txt +256 -0
  18. compas/colors/cmcrameri/bilbaoS.txt +100 -0
  19. compas/colors/cmcrameri/broc.txt +256 -0
  20. compas/colors/cmcrameri/brocO.txt +256 -0
  21. compas/colors/cmcrameri/buda.txt +256 -0
  22. compas/colors/cmcrameri/budaS.txt +100 -0
  23. compas/colors/cmcrameri/bukavu.txt +256 -0
  24. compas/colors/cmcrameri/cork.txt +256 -0
  25. compas/colors/cmcrameri/corkO.txt +256 -0
  26. compas/colors/cmcrameri/davos.txt +256 -0
  27. compas/colors/cmcrameri/davosS.txt +100 -0
  28. compas/colors/cmcrameri/devon.txt +256 -0
  29. compas/colors/cmcrameri/devonS.txt +100 -0
  30. compas/colors/cmcrameri/fes.txt +256 -0
  31. compas/colors/cmcrameri/grayC.txt +256 -0
  32. compas/colors/cmcrameri/grayCS.txt +100 -0
  33. compas/colors/cmcrameri/hawaii.txt +256 -0
  34. compas/colors/cmcrameri/hawaiiS.txt +100 -0
  35. compas/colors/cmcrameri/imola.txt +256 -0
  36. compas/colors/cmcrameri/imolaS.txt +100 -0
  37. compas/colors/cmcrameri/lajolla.txt +256 -0
  38. compas/colors/cmcrameri/lajollaS.txt +100 -0
  39. compas/colors/cmcrameri/lapaz.txt +256 -0
  40. compas/colors/cmcrameri/lapazS.txt +100 -0
  41. compas/colors/cmcrameri/lisbon.txt +256 -0
  42. compas/colors/cmcrameri/nuuk.txt +256 -0
  43. compas/colors/cmcrameri/nuukS.txt +100 -0
  44. compas/colors/cmcrameri/oleron.txt +256 -0
  45. compas/colors/cmcrameri/oslo.txt +256 -0
  46. compas/colors/cmcrameri/osloS.txt +100 -0
  47. compas/colors/cmcrameri/roma.txt +256 -0
  48. compas/colors/cmcrameri/romaO.txt +256 -0
  49. compas/colors/cmcrameri/tofino.txt +256 -0
  50. compas/colors/cmcrameri/tokyo.txt +256 -0
  51. compas/colors/cmcrameri/tokyoS.txt +100 -0
  52. compas/colors/cmcrameri/turku.txt +256 -0
  53. compas/colors/cmcrameri/turkuS.txt +100 -0
  54. compas/colors/cmcrameri/vanimo.txt +256 -0
  55. compas/colors/cmcrameri/vik.txt +256 -0
  56. compas/colors/cmcrameri/vikO.txt +256 -0
  57. compas/colors/color.py +1118 -0
  58. compas/colors/colordict.py +103 -0
  59. compas/colors/colormap.py +306 -0
  60. compas/colors/html_colors.py +149 -0
  61. compas/colors/mpl_colormap.py +1064 -0
  62. compas/data/__init__.py +31 -0
  63. compas/data/coercion.py +71 -0
  64. compas/data/conftest.py +10 -0
  65. compas/data/data.py +342 -0
  66. compas/data/encoders.py +240 -0
  67. compas/data/exceptions.py +2 -0
  68. compas/data/json.py +240 -0
  69. compas/data/samples/boxes.obj +250 -0
  70. compas/data/samples/butt_model.obj +2829 -0
  71. compas/data/samples/cone.stl +0 -0
  72. compas/data/samples/cube.off +16 -0
  73. compas/data/samples/cube_ascii.stl +56114 -0
  74. compas/data/samples/cube_binary.stl +0 -0
  75. compas/data/samples/cube_binary_2.stl +0 -0
  76. compas/data/samples/doosabin.json +1 -0
  77. compas/data/samples/faces.obj +63 -0
  78. compas/data/samples/faces_big.obj +9663 -0
  79. compas/data/samples/faces_reversed.obj +63 -0
  80. compas/data/samples/fink.obj +135 -0
  81. compas/data/samples/grid_irregular.obj +303 -0
  82. compas/data/samples/hypar.obj +148 -0
  83. compas/data/samples/lines.json +1 -0
  84. compas/data/samples/lines.obj +282 -0
  85. compas/data/samples/lines_big.obj +40322 -0
  86. compas/data/samples/lines_bigger.obj +161282 -0
  87. compas/data/samples/lines_noleaves.obj +422 -0
  88. compas/data/samples/mesh.obj +874 -0
  89. compas/data/samples/mesh_100_faces.json +1893 -0
  90. compas/data/samples/mesh_110_faces.json +2081 -0
  91. compas/data/samples/open_edges.obj +424 -0
  92. compas/data/samples/point.json +1 -0
  93. compas/data/samples/quadmesh.obj +183 -0
  94. compas/data/samples/quadmesh_planar.obj +181 -0
  95. compas/data/samples/saddle.obj +314 -0
  96. compas/data/samples/spline.obj +72 -0
  97. compas/data/samples/tubemesh.json +1 -0
  98. compas/data/samples/tubemesh.obj +378 -0
  99. compas/data/samples/tubemesh.off +374 -0
  100. compas/data/samples/tubemesh.ply +551 -0
  101. compas/data/schema.py +137 -0
  102. compas/data/validators.py +243 -0
  103. compas/datastructures/__init__.py +75 -0
  104. compas/datastructures/_mutablemapping.py +148 -0
  105. compas/datastructures/assembly/__init__.py +0 -0
  106. compas/datastructures/assembly/assembly.py +234 -0
  107. compas/datastructures/assembly/exceptions.py +6 -0
  108. compas/datastructures/assembly/part.py +228 -0
  109. compas/datastructures/attributes.py +85 -0
  110. compas/datastructures/cell_network/__init__.py +0 -0
  111. compas/datastructures/cell_network/cell_network.py +4190 -0
  112. compas/datastructures/datastructure.py +309 -0
  113. compas/datastructures/graph/__init__.py +0 -0
  114. compas/datastructures/graph/duality.py +197 -0
  115. compas/datastructures/graph/graph.py +2478 -0
  116. compas/datastructures/graph/operations/__init__.py +0 -0
  117. compas/datastructures/graph/operations/join.py +124 -0
  118. compas/datastructures/graph/operations/split.py +63 -0
  119. compas/datastructures/graph/planarity.py +292 -0
  120. compas/datastructures/graph/smoothing.py +59 -0
  121. compas/datastructures/mesh/__init__.py +0 -0
  122. compas/datastructures/mesh/conway.py +553 -0
  123. compas/datastructures/mesh/duality.py +104 -0
  124. compas/datastructures/mesh/mesh.py +5103 -0
  125. compas/datastructures/mesh/operations/__init__.py +0 -0
  126. compas/datastructures/mesh/operations/collapse.py +350 -0
  127. compas/datastructures/mesh/operations/extrude.py +0 -0
  128. compas/datastructures/mesh/operations/insert.py +120 -0
  129. compas/datastructures/mesh/operations/merge.py +83 -0
  130. compas/datastructures/mesh/operations/split.py +263 -0
  131. compas/datastructures/mesh/operations/substitute.py +37 -0
  132. compas/datastructures/mesh/operations/swap.py +62 -0
  133. compas/datastructures/mesh/operations/weld.py +107 -0
  134. compas/datastructures/mesh/remesh.py +234 -0
  135. compas/datastructures/mesh/slice.py +170 -0
  136. compas/datastructures/mesh/smoothing.py +187 -0
  137. compas/datastructures/mesh/subdivision.py +754 -0
  138. compas/datastructures/tree/__init__.py +0 -0
  139. compas/datastructures/tree/tree.py +504 -0
  140. compas/datastructures/volmesh/__init__.py +0 -0
  141. compas/datastructures/volmesh/volmesh.py +4203 -0
  142. compas/files/__init__.py +27 -0
  143. compas/files/_xml/__init__.py +0 -0
  144. compas/files/_xml/xml_cli.py +213 -0
  145. compas/files/_xml/xml_cpython.py +32 -0
  146. compas/files/_xml/xml_pre_38.py +58 -0
  147. compas/files/_xml/xml_shared.py +40 -0
  148. compas/files/gltf/__init__.py +0 -0
  149. compas/files/gltf/constants.py +59 -0
  150. compas/files/gltf/data_classes.py +657 -0
  151. compas/files/gltf/extensions.py +317 -0
  152. compas/files/gltf/gltf.py +92 -0
  153. compas/files/gltf/gltf_children.py +64 -0
  154. compas/files/gltf/gltf_content.py +615 -0
  155. compas/files/gltf/gltf_exporter.py +465 -0
  156. compas/files/gltf/gltf_mesh.py +273 -0
  157. compas/files/gltf/gltf_node.py +348 -0
  158. compas/files/gltf/gltf_parser.py +115 -0
  159. compas/files/gltf/gltf_reader.py +310 -0
  160. compas/files/gltf/gltf_scene.py +125 -0
  161. compas/files/gltf/helpers.py +59 -0
  162. compas/files/obj.py +680 -0
  163. compas/files/off.py +296 -0
  164. compas/files/ply.py +697 -0
  165. compas/files/stl.py +436 -0
  166. compas/files/xml.py +328 -0
  167. compas/geometry/__init__.py +772 -0
  168. compas/geometry/_core/__init__.py +0 -0
  169. compas/geometry/_core/_algebra.py +2826 -0
  170. compas/geometry/_core/angles.py +408 -0
  171. compas/geometry/_core/centroids.py +573 -0
  172. compas/geometry/_core/distance.py +895 -0
  173. compas/geometry/_core/normals.py +149 -0
  174. compas/geometry/_core/nurbs.py +367 -0
  175. compas/geometry/_core/predicates_2.py +582 -0
  176. compas/geometry/_core/predicates_3.py +1111 -0
  177. compas/geometry/_core/quaternions.py +196 -0
  178. compas/geometry/_core/size.py +204 -0
  179. compas/geometry/_core/tangent.py +56 -0
  180. compas/geometry/_core/transformations.py +1121 -0
  181. compas/geometry/_core/transformations_numpy.py +279 -0
  182. compas/geometry/bbox.py +145 -0
  183. compas/geometry/bbox_numpy.py +306 -0
  184. compas/geometry/bestfit.py +77 -0
  185. compas/geometry/bestfit_numpy.py +259 -0
  186. compas/geometry/booleans.py +297 -0
  187. compas/geometry/booleans_shapely.py +147 -0
  188. compas/geometry/brep/__init__.py +112 -0
  189. compas/geometry/brep/brep.py +1131 -0
  190. compas/geometry/brep/edge.py +302 -0
  191. compas/geometry/brep/errors.py +22 -0
  192. compas/geometry/brep/face.py +329 -0
  193. compas/geometry/brep/loop.py +87 -0
  194. compas/geometry/brep/trim.py +46 -0
  195. compas/geometry/brep/vertex.py +46 -0
  196. compas/geometry/contours.py +32 -0
  197. compas/geometry/curves/__init__.py +0 -0
  198. compas/geometry/curves/arc.py +429 -0
  199. compas/geometry/curves/bezier.py +345 -0
  200. compas/geometry/curves/circle.py +500 -0
  201. compas/geometry/curves/conic.py +16 -0
  202. compas/geometry/curves/curve.py +614 -0
  203. compas/geometry/curves/ellipse.py +408 -0
  204. compas/geometry/curves/hyperbola.py +336 -0
  205. compas/geometry/curves/line.py +431 -0
  206. compas/geometry/curves/nurbs.py +412 -0
  207. compas/geometry/curves/parabola.py +256 -0
  208. compas/geometry/curves/polyline.py +724 -0
  209. compas/geometry/frame.py +769 -0
  210. compas/geometry/geometry.py +296 -0
  211. compas/geometry/hull.py +146 -0
  212. compas/geometry/hull_numpy.py +82 -0
  213. compas/geometry/icp_numpy.py +104 -0
  214. compas/geometry/interpolation_barycentric.py +38 -0
  215. compas/geometry/interpolation_coons.py +102 -0
  216. compas/geometry/interpolation_tweening.py +87 -0
  217. compas/geometry/intersection.py +121 -0
  218. compas/geometry/intersections.py +1105 -0
  219. compas/geometry/kdtree.py +153 -0
  220. compas/geometry/offset.py +208 -0
  221. compas/geometry/pca_numpy.py +87 -0
  222. compas/geometry/plane.py +657 -0
  223. compas/geometry/point.py +664 -0
  224. compas/geometry/pointcloud.py +409 -0
  225. compas/geometry/polygon.py +473 -0
  226. compas/geometry/polyhedron.py +650 -0
  227. compas/geometry/projection.py +155 -0
  228. compas/geometry/quadmesh_planarize.py +30 -0
  229. compas/geometry/quadmesh_planarize_none.py +114 -0
  230. compas/geometry/quaternion.py +544 -0
  231. compas/geometry/reflection.py +102 -0
  232. compas/geometry/rotation.py +354 -0
  233. compas/geometry/scale.py +100 -0
  234. compas/geometry/shapes/__init__.py +0 -0
  235. compas/geometry/shapes/box.py +747 -0
  236. compas/geometry/shapes/capsule.py +472 -0
  237. compas/geometry/shapes/cone.py +309 -0
  238. compas/geometry/shapes/cylinder.py +355 -0
  239. compas/geometry/shapes/shape.py +300 -0
  240. compas/geometry/shapes/sphere.py +362 -0
  241. compas/geometry/shapes/torus.py +294 -0
  242. compas/geometry/shear.py +115 -0
  243. compas/geometry/surfaces/__init__.py +0 -0
  244. compas/geometry/surfaces/conical.py +166 -0
  245. compas/geometry/surfaces/cylindrical.py +251 -0
  246. compas/geometry/surfaces/extrusion.py +0 -0
  247. compas/geometry/surfaces/nurbs.py +380 -0
  248. compas/geometry/surfaces/planar.py +223 -0
  249. compas/geometry/surfaces/revolution.py +0 -0
  250. compas/geometry/surfaces/spherical.py +259 -0
  251. compas/geometry/surfaces/surface.py +689 -0
  252. compas/geometry/surfaces/toroidal.py +198 -0
  253. compas/geometry/transformation.py +554 -0
  254. compas/geometry/translation.py +104 -0
  255. compas/geometry/triangulation_delaunay.py +102 -0
  256. compas/geometry/triangulation_earclip.py +300 -0
  257. compas/geometry/trimesh_curvature.py +113 -0
  258. compas/geometry/trimesh_descent_numpy.py +26 -0
  259. compas/geometry/trimesh_geodistance.py +35 -0
  260. compas/geometry/trimesh_gradient_numpy.py +74 -0
  261. compas/geometry/trimesh_isolines.py +41 -0
  262. compas/geometry/trimesh_matrices.py +31 -0
  263. compas/geometry/trimesh_matrices_numpy.py +191 -0
  264. compas/geometry/trimesh_parametrisation.py +55 -0
  265. compas/geometry/trimesh_pull_points_numpy.py +216 -0
  266. compas/geometry/trimesh_remeshing.py +97 -0
  267. compas/geometry/trimesh_samplepoints_numpy.py +108 -0
  268. compas/geometry/trimesh_slicing.py +28 -0
  269. compas/geometry/trimesh_smoothing_numpy.py +34 -0
  270. compas/geometry/vector.py +889 -0
  271. compas/itertools.py +441 -0
  272. compas/linalg.py +634 -0
  273. compas/matrices.py +314 -0
  274. compas/plugins.py +488 -0
  275. compas/rpc/__init__.py +20 -0
  276. compas/rpc/__main__.py +77 -0
  277. compas/rpc/dispatcher.py +181 -0
  278. compas/rpc/errors.py +11 -0
  279. compas/rpc/proxy.py +437 -0
  280. compas/rpc/server.py +79 -0
  281. compas/rpc/services/__init__.py +0 -0
  282. compas/rpc/services/default.py +87 -0
  283. compas/rpc/services/watcher.py +43 -0
  284. compas/scene/__init__.py +56 -0
  285. compas/scene/assemblyobject.py +3 -0
  286. compas/scene/context.py +154 -0
  287. compas/scene/descriptors/__init__.py +0 -0
  288. compas/scene/descriptors/attribute.py +30 -0
  289. compas/scene/descriptors/color.py +91 -0
  290. compas/scene/descriptors/colordict.py +101 -0
  291. compas/scene/descriptors/protocol.py +12 -0
  292. compas/scene/exceptions.py +7 -0
  293. compas/scene/geometryobject.py +58 -0
  294. compas/scene/graphobject.py +173 -0
  295. compas/scene/meshobject.py +238 -0
  296. compas/scene/scene.py +144 -0
  297. compas/scene/sceneobject.py +253 -0
  298. compas/scene/volmeshobject.py +252 -0
  299. compas/tolerance.py +879 -0
  300. compas/topology/__init__.py +45 -0
  301. compas/topology/combinatorics.py +108 -0
  302. compas/topology/connectivity.py +129 -0
  303. compas/topology/orientation.py +204 -0
  304. compas/topology/traversal.py +567 -0
  305. compas/utilities/__init__.py +25 -0
  306. compas/utilities/azync.py +155 -0
  307. compas/utilities/datetime.py +40 -0
  308. compas/utilities/decorators.py +136 -0
  309. compas/utilities/remote.py +54 -0
  310. compas/utilities/ssh.py +169 -0
  311. compas-2.1.1.dist-info/AUTHORS.md +42 -0
  312. compas-2.1.1.dist-info/LICENSE +21 -0
  313. compas-2.1.1.dist-info/METADATA +132 -0
  314. compas-2.1.1.dist-info/RECORD +468 -0
  315. compas-2.1.1.dist-info/WHEEL +5 -0
  316. compas-2.1.1.dist-info/entry_points.txt +2 -0
  317. compas-2.1.1.dist-info/top_level.txt +4 -0
  318. compas_blender/__init__.py +250 -0
  319. compas_blender/collections.py +130 -0
  320. compas_blender/conversions/__init__.py +48 -0
  321. compas_blender/conversions/breps.py +0 -0
  322. compas_blender/conversions/colors.py +23 -0
  323. compas_blender/conversions/curves.py +125 -0
  324. compas_blender/conversions/geometry.py +161 -0
  325. compas_blender/conversions/meshes.py +148 -0
  326. compas_blender/conversions/surfaces.py +48 -0
  327. compas_blender/conversions/transformations.py +46 -0
  328. compas_blender/data.py +30 -0
  329. compas_blender/geometry/__init__.py +14 -0
  330. compas_blender/geometry/booleans.py +100 -0
  331. compas_blender/install.py +338 -0
  332. compas_blender/objects.py +326 -0
  333. compas_blender/print_python_path.py +18 -0
  334. compas_blender/scene/__init__.py +116 -0
  335. compas_blender/scene/boxobject.py +64 -0
  336. compas_blender/scene/capsuleobject.py +73 -0
  337. compas_blender/scene/circleobject.py +53 -0
  338. compas_blender/scene/coneobject.py +70 -0
  339. compas_blender/scene/curveobject.py +58 -0
  340. compas_blender/scene/cylinderobject.py +70 -0
  341. compas_blender/scene/frameobject.py +105 -0
  342. compas_blender/scene/graphobject.py +257 -0
  343. compas_blender/scene/lineobject.py +60 -0
  344. compas_blender/scene/meshobject.py +508 -0
  345. compas_blender/scene/planeobject.py +81 -0
  346. compas_blender/scene/pointcloudobject.py +67 -0
  347. compas_blender/scene/pointobject.py +71 -0
  348. compas_blender/scene/polygonobject.py +57 -0
  349. compas_blender/scene/polyhedronobject.py +57 -0
  350. compas_blender/scene/polylineobject.py +54 -0
  351. compas_blender/scene/sceneobject.py +249 -0
  352. compas_blender/scene/sphereobject.py +72 -0
  353. compas_blender/scene/surfaceobject.py +54 -0
  354. compas_blender/scene/torusobject.py +73 -0
  355. compas_blender/scene/vectorobject.py +69 -0
  356. compas_blender/scene/volmeshobject.py +475 -0
  357. compas_blender/utilities/__init__.py +38 -0
  358. compas_blender/utilities/drawing.py +768 -0
  359. compas_ghpython/__init__.py +124 -0
  360. compas_ghpython/components/Compas_FromJson/code.py +18 -0
  361. compas_ghpython/components/Compas_Info/code.py +15 -0
  362. compas_ghpython/components/Compas_RpcCall/code.py +31 -0
  363. compas_ghpython/components/Compas_ToJson/code.py +19 -0
  364. compas_ghpython/components/Compas_ToRhinoGeometry/code.py +15 -0
  365. compas_ghpython/components/__init__.py +99 -0
  366. compas_ghpython/install.py +29 -0
  367. compas_ghpython/scene/__init__.py +115 -0
  368. compas_ghpython/scene/boxobject.py +40 -0
  369. compas_ghpython/scene/brepobject.py +40 -0
  370. compas_ghpython/scene/capsuleobject.py +41 -0
  371. compas_ghpython/scene/circleobject.py +40 -0
  372. compas_ghpython/scene/coneobject.py +40 -0
  373. compas_ghpython/scene/curveobject.py +42 -0
  374. compas_ghpython/scene/cylinderobject.py +38 -0
  375. compas_ghpython/scene/ellipseobject.py +40 -0
  376. compas_ghpython/scene/frameobject.py +67 -0
  377. compas_ghpython/scene/graphobject.py +77 -0
  378. compas_ghpython/scene/lineobject.py +39 -0
  379. compas_ghpython/scene/meshobject.py +137 -0
  380. compas_ghpython/scene/planeobject.py +61 -0
  381. compas_ghpython/scene/pointobject.py +38 -0
  382. compas_ghpython/scene/polygonobject.py +48 -0
  383. compas_ghpython/scene/polyhedronobject.py +48 -0
  384. compas_ghpython/scene/polylineobject.py +39 -0
  385. compas_ghpython/scene/sceneobject.py +12 -0
  386. compas_ghpython/scene/sphereobject.py +39 -0
  387. compas_ghpython/scene/surfaceobject.py +42 -0
  388. compas_ghpython/scene/torusobject.py +39 -0
  389. compas_ghpython/scene/vectorobject.py +51 -0
  390. compas_ghpython/scene/volmeshobject.py +154 -0
  391. compas_ghpython/sets.py +83 -0
  392. compas_ghpython/timer.py +36 -0
  393. compas_ghpython/uninstall.py +31 -0
  394. compas_ghpython/utilities/__init__.py +33 -0
  395. compas_ghpython/utilities/drawing.py +457 -0
  396. compas_rhino/__init__.py +607 -0
  397. compas_rhino/conduits/__init__.py +16 -0
  398. compas_rhino/conduits/base.py +121 -0
  399. compas_rhino/conduits/faces.py +91 -0
  400. compas_rhino/conduits/labels.py +102 -0
  401. compas_rhino/conduits/lines.py +109 -0
  402. compas_rhino/conduits/points.py +111 -0
  403. compas_rhino/conversions/__init__.py +168 -0
  404. compas_rhino/conversions/breps.py +122 -0
  405. compas_rhino/conversions/curves.py +453 -0
  406. compas_rhino/conversions/docobjects.py +0 -0
  407. compas_rhino/conversions/exceptions.py +7 -0
  408. compas_rhino/conversions/extrusions.py +80 -0
  409. compas_rhino/conversions/geometry.py +187 -0
  410. compas_rhino/conversions/meshes.py +281 -0
  411. compas_rhino/conversions/shapes.py +291 -0
  412. compas_rhino/conversions/surfaces.py +355 -0
  413. compas_rhino/conversions/transformations.py +45 -0
  414. compas_rhino/geometry/__init__.py +44 -0
  415. compas_rhino/geometry/booleans.py +118 -0
  416. compas_rhino/geometry/brep/__init__.py +40 -0
  417. compas_rhino/geometry/brep/brep.py +554 -0
  418. compas_rhino/geometry/brep/builder.py +184 -0
  419. compas_rhino/geometry/brep/edge.py +202 -0
  420. compas_rhino/geometry/brep/face.py +285 -0
  421. compas_rhino/geometry/brep/loop.py +129 -0
  422. compas_rhino/geometry/brep/trim.py +99 -0
  423. compas_rhino/geometry/brep/vertex.py +76 -0
  424. compas_rhino/geometry/curves/__init__.py +43 -0
  425. compas_rhino/geometry/curves/curve.py +382 -0
  426. compas_rhino/geometry/curves/nurbs.py +298 -0
  427. compas_rhino/geometry/surfaces/__init__.py +50 -0
  428. compas_rhino/geometry/surfaces/nurbs.py +370 -0
  429. compas_rhino/geometry/surfaces/surface.py +407 -0
  430. compas_rhino/geometry/trimesh_curvature.py +344 -0
  431. compas_rhino/geometry/trimesh_slicing.py +65 -0
  432. compas_rhino/install.py +382 -0
  433. compas_rhino/install_plugin.py +169 -0
  434. compas_rhino/install_with_pip.py +20 -0
  435. compas_rhino/layers.py +347 -0
  436. compas_rhino/objects.py +1141 -0
  437. compas_rhino/print_python_path.py +18 -0
  438. compas_rhino/scene/__init__.py +123 -0
  439. compas_rhino/scene/boxobject.py +44 -0
  440. compas_rhino/scene/brepobject.py +41 -0
  441. compas_rhino/scene/capsuleobject.py +45 -0
  442. compas_rhino/scene/circleobject.py +43 -0
  443. compas_rhino/scene/coneobject.py +43 -0
  444. compas_rhino/scene/curveobject.py +43 -0
  445. compas_rhino/scene/cylinderobject.py +43 -0
  446. compas_rhino/scene/ellipseobject.py +44 -0
  447. compas_rhino/scene/frameobject.py +99 -0
  448. compas_rhino/scene/graphobject.py +364 -0
  449. compas_rhino/scene/helpers.py +33 -0
  450. compas_rhino/scene/lineobject.py +43 -0
  451. compas_rhino/scene/meshobject.py +673 -0
  452. compas_rhino/scene/planeobject.py +71 -0
  453. compas_rhino/scene/pointobject.py +43 -0
  454. compas_rhino/scene/polygonobject.py +45 -0
  455. compas_rhino/scene/polyhedronobject.py +45 -0
  456. compas_rhino/scene/polylineobject.py +43 -0
  457. compas_rhino/scene/sceneobject.py +123 -0
  458. compas_rhino/scene/sphereobject.py +43 -0
  459. compas_rhino/scene/surfaceobject.py +42 -0
  460. compas_rhino/scene/torusobject.py +43 -0
  461. compas_rhino/scene/vectorobject.py +49 -0
  462. compas_rhino/scene/volmeshobject.py +518 -0
  463. compas_rhino/ui.py +114 -0
  464. compas_rhino/uninstall.py +243 -0
  465. compas_rhino/uninstall_plugin.py +91 -0
  466. compas_rhino/utilities/__init__.py +37 -0
  467. compas_rhino/utilities/constructors.py +71 -0
  468. compas_rhino/utilities/drawing.py +1081 -0
compas/_os.py ADDED
@@ -0,0 +1,746 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ These are internal functions of the framework.
4
+ Not intended to be used outside compas* packages.
5
+ """
6
+
7
+ import os
8
+ import platform
9
+ import re
10
+ import shutil
11
+ import subprocess
12
+ import sys
13
+ import tempfile
14
+
15
+ try:
16
+ NotADirectoryError
17
+ except NameError:
18
+
19
+ class NotADirectoryError(Exception):
20
+ pass
21
+
22
+
23
+ PY2 = sys.version_info[0] == 2
24
+ PY3 = sys.version_info[0] == 3
25
+ SYMLINK_REGEX = re.compile(r"\n.*\<SYMLINKD\>\s(.*)\s\[(.*)\]\r")
26
+
27
+
28
+ __all__ = [
29
+ "absjoin",
30
+ "realpath",
31
+ "create_symlink",
32
+ "create_symlinks",
33
+ "remove_symlink",
34
+ "remove_symlinks",
35
+ "copy",
36
+ "remove",
37
+ "rename",
38
+ "user_data_dir",
39
+ "select_python",
40
+ "prepare_environment",
41
+ "is_admin",
42
+ "is_windows",
43
+ "is_linux",
44
+ "is_osx",
45
+ "is_mono",
46
+ "is_ironpython",
47
+ "is_rhino",
48
+ "is_blender",
49
+ "is_grasshopper",
50
+ ]
51
+
52
+
53
+ def is_windows():
54
+ """Check if the operating system is Windows.
55
+
56
+ Returns
57
+ -------
58
+ bool
59
+ True if the OS is Windows. False otherwise
60
+
61
+ """
62
+ if is_ironpython():
63
+ return os.name == "nt"
64
+ return sys.platform == "win32"
65
+
66
+
67
+ def is_linux():
68
+ """Check if the operating system is Linux.
69
+
70
+ Returns
71
+ -------
72
+ bool
73
+ True if the OS is Linux. False otherwise
74
+
75
+ """
76
+ return sys.platform in ("linux", "linux2")
77
+
78
+
79
+ def is_osx():
80
+ return sys.platform == "darwin"
81
+
82
+
83
+ def is_mono():
84
+ """Check if the operating system is running on Mono.
85
+
86
+ Returns
87
+ -------
88
+ bool
89
+ True if the OS is running on Mono. False otherwise
90
+
91
+ """
92
+ return "mono" in sys.version.lower()
93
+
94
+
95
+ def is_ironpython():
96
+ """Check if the Python implementation is IronPython.
97
+
98
+ Returns
99
+ -------
100
+ bool
101
+ True if the implementation is IronPython. False otherwise
102
+
103
+ """
104
+ return "ironpython" == platform.python_implementation().lower()
105
+
106
+
107
+ def is_rhino():
108
+ try:
109
+ import Rhino # noqa : F401
110
+ except ImportError:
111
+ return False
112
+ return True
113
+
114
+
115
+ def is_grasshopper():
116
+ try:
117
+ import Rhino # noqa : F401
118
+ import scriptcontext # noqa : F401
119
+ except ImportError:
120
+ return False
121
+ return not isinstance(scriptcontext.doc, Rhino.RhinoDoc)
122
+
123
+
124
+ def is_blender():
125
+ try:
126
+ import bpy # noqa : F401
127
+ except ImportError:
128
+ return False
129
+ return True
130
+
131
+
132
+ if is_windows():
133
+ import ctypes
134
+ import ctypes.wintypes
135
+
136
+ class ShellExecuteInfo(ctypes.Structure):
137
+ _fields_ = [
138
+ ("cbSize", ctypes.wintypes.DWORD),
139
+ ("fMask", ctypes.c_ulong),
140
+ ("hwnd", ctypes.wintypes.HWND),
141
+ ("lpVerb", ctypes.c_char_p),
142
+ ("lpFile", ctypes.c_char_p),
143
+ ("lpParameters", ctypes.c_char_p),
144
+ ("lpDirectory", ctypes.c_char_p),
145
+ ("nShow", ctypes.c_int),
146
+ ("hInstApp", ctypes.wintypes.HINSTANCE),
147
+ ("lpIDList", ctypes.c_void_p),
148
+ ("lpClass", ctypes.c_char_p),
149
+ ("hKeyClass", ctypes.wintypes.HKEY),
150
+ ("dwHotKey", ctypes.wintypes.DWORD),
151
+ ("hIcon", ctypes.wintypes.HANDLE),
152
+ ("hProcess", ctypes.wintypes.HANDLE),
153
+ ]
154
+
155
+ def __init__(self, **kw):
156
+ super(ShellExecuteInfo, self).__init__()
157
+ self.cbSize = ctypes.sizeof(self)
158
+ for field_name, field_value in kw.items():
159
+ setattr(self, field_name, field_value)
160
+
161
+ SEE_MASK_NOCLOSEPROCESS = 0x00000040
162
+ SEE_MASK_NO_CONSOLE = 0x00008000
163
+ INFINITE = -1
164
+
165
+
166
+ # seems a bit weird that this is done here, since it is only relevant for Rhino/GH
167
+ # also, perhasps it makes more sense this is done at the top of the file
168
+ # since it defines a few module-wide variables
169
+ try:
170
+ from compas_bootstrapper import PYTHON_DIRECTORY
171
+ except: # noqa: E722
172
+ # We re-map CONDA_PREFIX for backwards compatibility reasons
173
+ # In a few releases down the line, we can get rid of this bit
174
+ try:
175
+ from compas_bootstrapper import CONDA_PREFIX as PYTHON_DIRECTORY
176
+ except: # noqa: E722
177
+ PYTHON_DIRECTORY = None
178
+
179
+ try:
180
+ from compas_bootstrapper import CONDA_EXE
181
+ except: # noqa: E722
182
+ CONDA_EXE = None
183
+
184
+
185
+ def select_python(python_executable):
186
+ """Selects the most likely python interpreter to run.
187
+
188
+ This function detects if there is a conda environment we can use,
189
+ or if we need to default to a system-wide python interpreter instead.
190
+
191
+ Parameters
192
+ ----------
193
+ python_executable : str
194
+ Select which python executable you want to use,
195
+ either `python` or `pythonw`.
196
+ """
197
+ if PYTHON_DIRECTORY and os.path.exists(PYTHON_DIRECTORY):
198
+ python_executables = [python_executable] if python_executable else ["pythonw", "python"]
199
+
200
+ for python_exe in python_executables:
201
+ python = os.path.join(PYTHON_DIRECTORY, python_exe)
202
+ if os.path.exists(python):
203
+ return python
204
+
205
+ python = os.path.join(PYTHON_DIRECTORY, "{0}.exe".format(python_exe))
206
+ if os.path.exists(python):
207
+ return python
208
+
209
+ python = os.path.join(PYTHON_DIRECTORY, "bin", python_exe)
210
+ if os.path.exists(python):
211
+ return python
212
+
213
+ python = os.path.join(PYTHON_DIRECTORY, "bin", "{0}.exe".format(python_exe))
214
+ if os.path.exists(python):
215
+ return python
216
+
217
+ default_exe = "pythonw" if is_windows() else "python"
218
+
219
+ # Assume a system-wide install exists
220
+ return python_executable or default_exe
221
+
222
+
223
+ def prepare_environment(env=None):
224
+ """Prepares an environment context to run Python on.
225
+
226
+ If Python is being used from a conda environment, this is roughly equivalent
227
+ to activating the conda environment by setting up the correct environment
228
+ variables.
229
+
230
+ Parameters
231
+ ----------
232
+ env : dict, optional
233
+ Dictionary of environment variables to modify. If ``None`` is passed, then
234
+ this will create a copy of the current ``os.environ``.
235
+
236
+ Returns
237
+ -------
238
+ dict
239
+ Updated environment variable dictionary.
240
+ """
241
+
242
+ if env is None:
243
+ env = os.environ.copy()
244
+
245
+ if PYTHON_DIRECTORY:
246
+ if is_windows():
247
+ lib_bin = os.path.join(PYTHON_DIRECTORY, "Library", "bin")
248
+ else:
249
+ lib_bin = os.path.join(PYTHON_DIRECTORY, "bin")
250
+
251
+ if os.path.exists(lib_bin) and lib_bin not in env["PATH"]:
252
+ env["PATH"] = lib_bin + os.pathsep + env["PATH"]
253
+
254
+ if CONDA_EXE:
255
+ env["CONDA_EXE"] = CONDA_EXE
256
+
257
+ return env
258
+
259
+
260
+ def absjoin(*parts):
261
+ return os.path.abspath(os.path.join(*parts))
262
+
263
+
264
+ def realpath(path):
265
+ """Return the canonical path of the specified filename, resolving any symbolic links encountered in the path.
266
+
267
+ This function uses Python's stdlib `os.path.realpath` in most cases,
268
+ except when inside IronPython because (guess what?) it is broken and
269
+ doesn't really eliminate sym links, so, we fallback to a different
270
+ way to identifying symlinks in that situation.
271
+ """
272
+ if not PY3 and is_ironpython():
273
+ if is_windows():
274
+ return _realpath_ipy_win(path)
275
+ else:
276
+ return _realpath_ipy_posix(path)
277
+
278
+ return os.path.realpath(path)
279
+
280
+
281
+ def _realpath_ipy_win(path):
282
+ dirname = os.path.basename(path)
283
+ parent_path = os.path.join(path, "..")
284
+
285
+ args = 'dir /c "{}" /Al'.format(parent_path)
286
+ process = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
287
+
288
+ output, _error = process.communicate()
289
+ matches = SYMLINK_REGEX.finditer(output)
290
+ for match in matches:
291
+ match_name = match.groups()[0].strip()
292
+ match_link = match.groups()[1]
293
+
294
+ if match_name == dirname:
295
+ return match_link
296
+
297
+ return path
298
+
299
+
300
+ def _realpath_ipy_posix(path):
301
+ args = 'readlink -f "{}"'.format(path)
302
+ process = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
303
+ output, _error = process.communicate()
304
+ return output.strip()
305
+
306
+
307
+ # Cache whatever symlink function works (native or polyfill)
308
+ _os_symlink = None
309
+
310
+
311
+ def _polyfill_symlinks(symlinks, raise_on_error):
312
+ """Create multiple symlinks using the polyfill implementation."""
313
+ _handle, temp_path = tempfile.mkstemp(suffix=".cmd", text=True)
314
+
315
+ with open(temp_path, "w") as mklink_cmd:
316
+ mklink_cmd.write("@echo off\n")
317
+ mklink_cmd.write("SET /A symlink_result=0\n")
318
+ mklink_cmd.write("ECHO ret=%symlink_result%\n")
319
+ for i, (source, link_name) in enumerate(symlinks):
320
+ dir_symlink_arg = "/J" if os.path.isdir(source) else ""
321
+ mklink_cmd.write("mklink {} {}\n".format(dir_symlink_arg, subprocess.list2cmdline([link_name, source])))
322
+ mklink_cmd.write("IF %ERRORLEVEL% EQU 0 SET /A symlink_result += {} \n".format(2**i))
323
+
324
+ mklink_cmd.write("EXIT /B %symlink_result%\n")
325
+
326
+ ret_value = _run_as_admin([temp_path])
327
+
328
+ # The error level integer (ret_value) reflects the success/failure of
329
+ # each of the symlink operations, so we do a bit of bitwise-arithmetic
330
+ # on it to figure out which symlinks worked and which ones failed.
331
+
332
+ result = []
333
+ for i in range(len(symlinks)):
334
+ success = ret_value & 2**i != 0
335
+ result.append(success)
336
+
337
+ return result
338
+
339
+
340
+ def _native_symlinks(symlinks, raise_on_error):
341
+ """Create multiple symlinks using the native implementation."""
342
+ result = []
343
+
344
+ for source, link_name in symlinks:
345
+ try:
346
+ os.symlink(source, link_name)
347
+ result.append(True)
348
+ except OSError:
349
+ if raise_on_error:
350
+ raise
351
+
352
+ result.append(False)
353
+
354
+ return result
355
+
356
+
357
+ def _set_symlink_function(fn):
358
+ global _os_symlink
359
+ _os_symlink = fn
360
+
361
+
362
+ def _get_symlink_function():
363
+ global _os_symlink
364
+ allow_polyfill_retry = False
365
+
366
+ if not _os_symlink:
367
+ if getattr(os, "symlink", None):
368
+ _os_symlink = _native_symlinks
369
+
370
+ if is_windows():
371
+ if not callable(_os_symlink):
372
+ _os_symlink = _polyfill_symlinks
373
+ else:
374
+ allow_polyfill_retry = True
375
+
376
+ return _os_symlink, allow_polyfill_retry
377
+
378
+
379
+ def create_symlink(source, link_name):
380
+ """Create a symbolic link pointing to source named link_name.
381
+
382
+ Parameters
383
+ ----------
384
+ source: str
385
+ Source of the link
386
+ link_name: str
387
+ Link name.
388
+
389
+ Notes
390
+ -----
391
+ This function is a polyfill of the native ``os.symlink``
392
+ for Python 2.x on Windows platforms.
393
+ """
394
+ create_symlinks([(source, link_name)], raise_on_error=True)
395
+
396
+
397
+ def create_symlinks(symlinks, raise_on_error=False):
398
+ """Create multiple symbolic links in one call.
399
+
400
+ Parameters
401
+ ----------
402
+ symlinks: list[str]ing tuples
403
+ List of ``source`` and ``link_name`` of the symlinks as tuples.
404
+ """
405
+ symlink, allow_polyfill_retry = _get_symlink_function()
406
+
407
+ try:
408
+ return symlink(symlinks, raise_on_error=True)
409
+ except OSError:
410
+ if raise_on_error:
411
+ raise
412
+
413
+ _set_symlink_function(_polyfill_symlinks)
414
+ return _polyfill_symlinks(symlinks, raise_on_error=False)
415
+
416
+
417
+ def remove_symlink(symlink):
418
+ """Remove a symlink from the file system.
419
+
420
+ Parameters
421
+ ----------
422
+ symlink : str
423
+ Symlink to remove.
424
+ """
425
+ # Broken links return False on .exists(), so we need to check .islink() as well
426
+ if not (os.path.islink(symlink) or os.path.exists(symlink)):
427
+ return
428
+
429
+ if os.path.isdir(symlink):
430
+ try:
431
+ os.rmdir(symlink)
432
+ except NotADirectoryError:
433
+ os.unlink(symlink)
434
+ except PermissionError:
435
+ if not is_windows():
436
+ raise
437
+
438
+ _run_command_as_admin("rmdir", [symlink])
439
+ else:
440
+ os.unlink(symlink)
441
+
442
+
443
+ def remove_symlinks(symlinks, raise_on_error=False):
444
+ """Remove one or more symlinks.
445
+
446
+ Parameters
447
+ ----------
448
+ links
449
+ Sequence of symlinks to remove.
450
+ raise_on_error : bool
451
+ ``False`` to continue removing even on error,
452
+ otherwise ``True``.
453
+
454
+ Returns
455
+ -------
456
+ list
457
+ If ``raise_on_error`` is ``False``, returns a list
458
+ of bools indicating which links were successfully removed.
459
+ """
460
+ result = []
461
+
462
+ for symlink in symlinks:
463
+ try:
464
+ remove_symlink(symlink)
465
+ result.append(True)
466
+ except OSError:
467
+ if raise_on_error:
468
+ raise
469
+
470
+ result.append(False)
471
+
472
+ return result
473
+
474
+
475
+ def rename(src, dst):
476
+ """Rename a file or directory."""
477
+ try:
478
+ os.rename(src, dst)
479
+ except (PermissionError, OSError):
480
+ if not is_windows():
481
+ raise
482
+
483
+ _run_command_as_admin("move", [src, dst])
484
+
485
+
486
+ def remove(path):
487
+ """Remove path."""
488
+ try:
489
+ os.remove(path)
490
+ except (PermissionError, OSError):
491
+ if not is_windows():
492
+ raise
493
+
494
+ _run_command_as_admin("del", [path])
495
+
496
+
497
+ def copy(src, dst):
498
+ """Copy a file from source to destination."""
499
+ try:
500
+ shutil.copy(src, dst)
501
+ except (PermissionError, OSError):
502
+ if not is_windows():
503
+ raise
504
+
505
+ _run_command_as_admin("copy", [src, dst])
506
+
507
+
508
+ def is_admin():
509
+ """Determines whether the current user has admin rights.
510
+
511
+ Returns
512
+ -------
513
+ bool
514
+ True if the user is administrator, otherwise False.
515
+ """
516
+ if not is_windows():
517
+ return os.getuid() == 0
518
+
519
+ try:
520
+ return bool(ctypes.windll.shell32.IsUserAnAdmin())
521
+ except: # noqa: E722
522
+ return False
523
+
524
+
525
+ def _run_command_as_admin(command, arguments):
526
+ """Run a single command as admin on Windows.
527
+
528
+ Parameters
529
+ ----------
530
+ command : str
531
+ Command name.
532
+ arguments : list[str]
533
+ List of arguments.
534
+ """
535
+ _handle, temp_path = tempfile.mkstemp(suffix=".cmd", text=True)
536
+
537
+ with open(temp_path, "w") as remove_symlink_cmd:
538
+ remove_symlink_cmd.write("@echo off\n")
539
+ remove_symlink_cmd.write("{} {}\n".format(command, subprocess.list2cmdline(arguments)))
540
+
541
+ _run_as_admin([temp_path])
542
+
543
+
544
+ def _run_as_admin(command):
545
+ """Run the specified command as an admin.
546
+
547
+ Paramters
548
+ ---------
549
+ command : list[str]
550
+ List of strings of the command to run.
551
+
552
+ Returns
553
+ -------
554
+ int
555
+ Exit code of the process.
556
+ """
557
+
558
+ if not is_windows():
559
+ raise RuntimeError("Only supported on Windows")
560
+
561
+ command_file, command_args = command[0], command[1:]
562
+
563
+ params = ShellExecuteInfo(
564
+ nShow=int(False),
565
+ fMask=SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE,
566
+ lpVerb=b"runas",
567
+ lpFile=command_file.encode("cp1252"),
568
+ lpParameters=subprocess.list2cmdline(command_args).encode("cp1252"),
569
+ )
570
+
571
+ if not ctypes.windll.shell32.ShellExecuteExA(ctypes.byref(params)):
572
+ raise RuntimeError('Failed to run command "%s" as admin', command_file)
573
+
574
+ process_handle = params.hProcess
575
+ ctypes.windll.kernel32.WaitForSingleObject(process_handle, INFINITE)
576
+
577
+ ret = ctypes.wintypes.DWORD()
578
+ if ctypes.windll.kernel32.GetExitCodeProcess(process_handle, ctypes.byref(ret)) == 0:
579
+ raise RuntimeError("Failed to retrieve exit code")
580
+
581
+ return ret.value
582
+
583
+
584
+ # The following methods has been adapted from the appdirs package
585
+ #
586
+ # MIT license
587
+ # Copyright (c) 2005-2010 ActiveState Software Inc.
588
+ #
589
+ # Copyright (c) 2013 Eddy Petrișor
590
+ # http://github.com/ActiveState/appdirs
591
+
592
+
593
+ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
594
+ r"""Return full path to the user-specific data dir for this application.
595
+
596
+ Parameters
597
+ ----------
598
+ appname : str
599
+ Name of application.
600
+ If ``None``, just the system directory is returned.
601
+ appauthor : str
602
+ Only used on Windows. Name of the appauthor or distributing body
603
+ for this application. Typically it is the owning company name.
604
+ This falls back to appname. You may pass ``False`` to disable it.
605
+ version : str
606
+ Version path element to append to the path.
607
+ You might want to use this if you want multiple versions
608
+ of your app to be able to run independently. If used, this
609
+ would typically be "<major>.<minor>".
610
+ Only applied when appname is present.
611
+ roaming : bool, optional
612
+ True to use the Windows roaming appdata directory, otherwise False.
613
+ That means that for users on a Windows network setup for roaming profiles,
614
+ this user data will be sync'd on login. See
615
+ <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
616
+ for a discussion of issues.
617
+
618
+ Returns
619
+ -------
620
+ str
621
+ Full path to the user-specific data dir.
622
+ """
623
+ if is_windows():
624
+ if appauthor is None:
625
+ appauthor = appname
626
+ const = "CSIDL_APPDATA" if roaming else "CSIDL_LOCAL_APPDATA"
627
+ path = os.path.normpath(_get_win_folder(const))
628
+ if appname:
629
+ if appauthor is not False:
630
+ path = os.path.join(path, appauthor, appname)
631
+ else:
632
+ path = os.path.join(path, appname)
633
+
634
+ elif is_osx():
635
+ path = os.path.expanduser("~/Library/Application Support/")
636
+ if appname:
637
+ path = os.path.join(path, appname)
638
+
639
+ elif is_mono():
640
+ path = os.path.expanduser("~/Library/Application Support/")
641
+ if appname:
642
+ path = os.path.join(path, appname)
643
+
644
+ else:
645
+ # is_linux()
646
+ path = os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
647
+ if appname:
648
+ path = os.path.join(path, appname)
649
+
650
+ if appname and version:
651
+ path = os.path.join(path, version)
652
+
653
+ return path
654
+
655
+
656
+ def _get_win_folder_from_registry(csidl_name):
657
+ """This is a fallback technique at best. I'm not sure if using the
658
+ registry for this guarantees us the correct answer for all CSIDL_*
659
+ names.
660
+ """
661
+ if PY3:
662
+ import winreg as _winreg
663
+ else:
664
+ import _winreg
665
+
666
+ shell_folder_name = {
667
+ "CSIDL_APPDATA": "AppData",
668
+ "CSIDL_COMMON_APPDATA": "Common AppData",
669
+ "CSIDL_LOCAL_APPDATA": "Local AppData",
670
+ }[csidl_name]
671
+
672
+ key = _winreg.OpenKey(
673
+ _winreg.HKEY_CURRENT_USER,
674
+ r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
675
+ )
676
+ dir, type = _winreg.QueryValueEx(key, shell_folder_name)
677
+ return dir
678
+
679
+
680
+ def _get_win_folder_with_pywin32(csidl_name):
681
+ from win32com.shell import shell
682
+ from win32com.shell import shellcon
683
+
684
+ dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
685
+ # Try to make this a unicode path because SHGetFolderPath does
686
+ # not return unicode strings when there is unicode data in the
687
+ # path.
688
+ try:
689
+ dir = str(dir) if PY3 else unicode(dir) # noqa: F821
690
+
691
+ # Downgrade to short path name if have highbit chars. See
692
+ # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
693
+ has_high_char = False
694
+ for c in dir:
695
+ if ord(c) > 255:
696
+ has_high_char = True
697
+ break
698
+ if has_high_char:
699
+ try:
700
+ import win32api
701
+
702
+ dir = win32api.GetShortPathName(dir)
703
+ except ImportError:
704
+ pass
705
+ except UnicodeError:
706
+ pass
707
+ return dir
708
+
709
+
710
+ def _get_win_folder_with_ctypes(csidl_name):
711
+ csidl_const = {
712
+ "CSIDL_APPDATA": 26,
713
+ "CSIDL_COMMON_APPDATA": 35,
714
+ "CSIDL_LOCAL_APPDATA": 28,
715
+ }[csidl_name]
716
+
717
+ buf = ctypes.create_unicode_buffer(1024)
718
+ ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
719
+
720
+ # Downgrade to short path name if have highbit chars. See
721
+ # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
722
+ has_high_char = False
723
+ for c in buf:
724
+ if ord(c) > 255:
725
+ has_high_char = True
726
+ break
727
+ if has_high_char:
728
+ buf2 = ctypes.create_unicode_buffer(1024)
729
+ if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
730
+ buf = buf2
731
+
732
+ return buf.value
733
+
734
+
735
+ if is_windows():
736
+ try:
737
+ import win32com.shell # noqa: F401
738
+
739
+ _get_win_folder = _get_win_folder_with_pywin32
740
+ except ImportError:
741
+ try:
742
+ from ctypes import windll # noqa: F401
743
+
744
+ _get_win_folder = _get_win_folder_with_ctypes
745
+ except ImportError:
746
+ _get_win_folder = _get_win_folder_from_registry