diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..00a56bf --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,42 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + python -m pip install numpy scipy periodictable + python setup.py install + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/README.md b/README.md index 1dccb0a..817bc77 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ For more examples, take a look at the `examples` folder. * Using PhreeqPython on Windows requires installing [Visual C++ Redistributable 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48145) ## Unit Tests -| **Mac/Linux** | **Windows** | **Coverage** | -|---|---|---| -| [![Build Status](https://travis-ci.com/Vitens/phreeqpython.svg?branch=master)](https://travis-ci.com/Vitens/phreeqpython) | [![Build status](https://ci.appveyor.com/api/projects/status/lr1jwspxdkgo85bv?svg=true)](https://ci.appveyor.com/project/abelheinsbroek/phreeqpython) | [![codecov](https://codecov.io/gh/Vitens/phreeqpython/branch/master/graph/badge.svg)](https://codecov.io/gh/Vitens/phreeqpython) | +| **Mac/Linux** and **Windows** | **Coverage** | +|---|---| +| [![Python package](https://github.com/DocMT/phreeqpython/actions/workflows/python-package.yml/badge.svg)](https://github.com/DocMT/phreeqpython/actions/workflows/python-package.yml)| [![codecov](https://codecov.io/gh/Vitens/phreeqpython/branch/master/graph/badge.svg)](https://codecov.io/gh/Vitens/phreeqpython) | ## Acknowledgements diff --git a/appveyor.yml b/appveyor.yml index 5b984c1..11438cc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,14 +1,15 @@ build: false environment: - matrix: - - PYTHON: "C:\\Python36-x64" - PYTHON_VERSION: "3.9.1" - PYTHON_ARCH: "64" + matrix: + - PYTHON: "C:\\Python38-x64" init: - - "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%" + - "ECHO %PYTHON%" install: + - "%PYTHON%/python.exe -m pip install --upgrade pip" + - "%PYTHON%/python.exe -m pip install pytest" + - "%PYTHON%/python.exe -m pip install numpy" - "%PYTHON%/python.exe -m pip install scipy" - "%PYTHON%/python.exe -m pip install periodictable" - "%PYTHON%/python.exe -m pip install nose" diff --git a/phreeqpython/viphreeqc.py b/phreeqpython/viphreeqc.py index ac913ac..6ae5499 100644 --- a/phreeqpython/viphreeqc.py +++ b/phreeqpython/viphreeqc.py @@ -15,7 +15,7 @@ def bytes(str_, encoding): #pylint: disable-msg=W0613 """Compatibilty function for Python 3. """ return str_ - range = xrange #pylint: disable-msg=C0103 + range = xrange #pylint: disable-msg=C0103 # noqa: F821 #pylint: enable-msg=W0622 @@ -44,6 +44,8 @@ def __init__(self, dll_path=None): dll_name = './lib/viphreeqc.so' elif sys.platform == 'darwin': dll_name = './lib/viphreeqc.dylib' + elif 'emscripten' in sys.platform: + dll_name = './lib/viphreeqcwasm.so' else: msg = 'Platform %s is not supported.' % sys.platform raise NotImplementedError(msg) diff --git a/setup.py b/setup.py index 80fbe6b..6f15bdb 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages import os import sys import zipfile @@ -11,8 +11,8 @@ author='Abel Heinsbroek', author_email='abel.heinsbroek@vitens.nl', license='Apache Licence 2.0', - packages=['phreeqpython'], + packages=['phreeqpython', 'phreeqpython.lib', 'phreeqpython.database'], include_package_data=True, zip_safe=False, - install_requires=['periodictable'] + install_requires=['periodictable','numpy','scipy'] ) diff --git a/tests/test_phreeqpython.py b/tests/test_phreeqpython.py index ae116c7..ddf864c 100644 --- a/tests/test_phreeqpython.py +++ b/tests/test_phreeqpython.py @@ -1,4 +1,4 @@ -from phreeqpython import PhreeqPython, Solution +from phreeqpython import PhreeqPython, Solution, utility from pathlib import Path import pytest @@ -39,7 +39,7 @@ def test01_basiscs(self): assert round(sol.species_activities['Ca+2'], 5) == 0.00054 # test add_solution_simple as milligrams - sol2 = self.pp.add_solution_simple({'Ca': 40.078, 'Na': 22.99, 'MgSO4': 120.37}, units='mg') + sol2 = self.pp.add_solution_simple({'Ca': 40.078, 'Na': 22.99, 'MgSO4': utility.convert_units('MgSO4', 1, 'mmol', 'mg')}, units='mg') # test conversion from mg to mmol assert round(sol2.total("Ca", 'mmol'), 4) == 1 # test amount in mg @@ -57,7 +57,7 @@ def test02_solution_functions(self): assert round(sol.total('Cl'), 2) == 3.5 assert round(sol.total('Mg'), 2) == 1 # change solution in mgs (add and subtract) - sol.change({'Na': 11.495, 'MgCl2': -95.211}, 'mg') + sol.change({'Na': 11.495, 'MgCl2': -utility.convert_units('MgCl2', 1, 'mmol', 'mg')}, 'mg') assert round(sol.total('Cl'), 2) == 1.5 assert round(sol.total('Mg'), 2) == 0 diff --git a/tests/test_utility.py b/tests/test_utility.py index 75008ee..5f31db0 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -12,7 +12,7 @@ def test_convert_units(self): ) == 39997.0 assert round( convert_units('NaOH', 1, from_units='mol', to_units='ug'), 0 - ) == 39997110.0 + ) == 39996769.0 assert round( convert_units('NaOH', 1, from_units='mmol', to_units='mol'), 4