From c702e370dc02bfdaac1b956a86533a0484f3d0d0 Mon Sep 17 00:00:00 2001 From: Morgan Williams Date: Thu, 6 Jul 2023 20:29:46 +0800 Subject: [PATCH] Rearrange dependencies, make some optional --- .github/workflows/unittest.yml | 12 ------------ environment.yml | 3 --- pyrolite/util/spatial.py | 12 +++++++++--- setup.py | 12 ++++-------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 720b5188..64354ee1 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -18,18 +18,6 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: [3.8, 3.9, "3.10", "3.11"] - # exclude: - # # excludes py38 on macOS, which seems to stall currently - # - os: macos-latest - # python-version: 3.8 - # - os: macos-latest - # python-version: 3.9 - # - os: macos-latest - # python-version: "3.10" - # - os: macos-latest - # python-version: "3.11" - # - os: windows-latest - # python-version: "3.11" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 diff --git a/environment.yml b/environment.yml index 62efa708..6b380fc0 100644 --- a/environment.yml +++ b/environment.yml @@ -20,7 +20,6 @@ dependencies: - tinydb - periodictable - mpltern>=0.4.0 - - mpmath - sympy>=1.7 # import changes after sympy 1.6 - joblib - requests @@ -35,8 +34,6 @@ dependencies: - pip - black - isort - - jedi<0.18.0 # for use on atom/ipython - - pyzmq - pytest - pytest-runner - pytest-cov diff --git a/pyrolite/util/spatial.py b/pyrolite/util/spatial.py index 73942910..1ce4151b 100644 --- a/pyrolite/util/spatial.py +++ b/pyrolite/util/spatial.py @@ -4,7 +4,11 @@ import itertools import numpy as np -from psutil import virtual_memory # memory check + +try: + from psutil import virtual_memory # memory check +except ImportError: + virtual_memory = None from .log import Handle @@ -176,14 +180,16 @@ def great_circle_distance( # but, with large arrays it'll spit out a memory error # so instead we can try to build it numerically size = np.max([a.shape[0] for a in [φ1, φ2, λ1, λ2]]) - mem = virtual_memory().total # total physical memory available estimated_matrix_size = np.array([[1.0]], dtype=dtype).nbytes * size**2 logger.debug( "Attempting to build {}x{} array of size {:.2f} Gb.".format( size, size, estimated_matrix_size / 1024**3 ) ) - if estimated_matrix_size > (mem * max_memory_fraction): + + infeasible = estimated_matrix_size > (virtual_memory().total * max_memory_fraction) if virtual_memory is not None else False + + if infeasible: logger.warn( "Angle array for segmented distance matrix larger than maximum memory " "fraction, computing mean global distances instead." diff --git a/setup.py b/setup.py index 163f6f90..3f6f8657 100644 --- a/setup.py +++ b/setup.py @@ -15,9 +15,10 @@ ] dev_require = ["pytest", "versioneer", "black", "isort", "twine"] + tests_require + docs_require db_require = ["pyodbc", "psycopg2"] -skl_require = ["scikit-learn"] +skl_require = ["scikit-learn", "joblib"] stats_require = ["statsmodels", "scikit-learn"] -spatial_require = ["owslib", "geojson"] # this needs pyproj -> C compiler +spatial_require = ["owslib", "geojson", "psutil"] # this needs pyproj -> C compiler +excel_require = ["xlrd", "openpyxl"] # reading excel from pandas, writing excel from pandas with open("README.md", "r") as src: LONG_DESCRIPTION = src.read() @@ -56,18 +57,12 @@ "numpy", "numpydoc", "tinydb>4.1", # >4.1 required for read-only access mode for JSON storage - "typing-extensions", # required for newer tinydb versions? - "psutil", "periodictable", "matplotlib", "mpltern>=0.4.0", "scipy>=1.2", # uses scipy.optimize.Bounds, added around 1.2 - "mpmath", "sympy>=1.7", "pandas>=1.0", # dataframe acccessors, attrs attribute - "xlrd", # reading excel from pandas - "openpyxl", # writing excel from pandas - "joblib", "requests", # used by alphaMELTS utilities, util.web ], extras_require={ @@ -77,6 +72,7 @@ "spatial": spatial_require, "db": db_require, "stats": stats_require, + "excel": excel_require }, tests_require=tests_require, test_suite="test",