Repository: bandframework/surmise (language: python)

Issue:
PR for installation-related changes



Discussion / hints:

Fix patch:
diff --git a/.flake8 b/.flake8
index 1160b420..c1406bf8 100644
--- a/.flake8
+++ b/.flake8
@@ -6,6 +6,7 @@ exclude =
         .git,
         # Largely autogenerated
         docs/conf.py
-	examples/
-	tests/
-	setup.py
\ No newline at end of file
+	    examples/
+	    tests/
+	    setup.py
+	    surmise/_version.py
diff --git a/.github/config/.wordlist.txt b/.github/config/.wordlist.txt
index 520ca626..f417021d 100644
--- a/.github/config/.wordlist.txt
+++ b/.github/config/.wordlist.txt
@@ -82,3 +82,7 @@ www
 zNqg
 lbl
 mosesyhc
+PyPI
+microsoft
+visualstudio
+whl
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 0b334aa9..9695f903 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -16,6 +16,8 @@ jobs:
 
     steps:
       - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
       - name: Build wheels
         uses: pypa/cibuildwheel@v2.16.0
 
@@ -28,6 +30,8 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
       - name: Build sdist
         run: pipx run build --sdist
       - uses: actions/upload-artifact@v3
@@ -52,3 +56,4 @@ jobs:
         uses: pypa/gh-action-pypi-publish@release/v1
         with:
           password: ${{ secrets.PYPI_ACCESS_TOKEN }}
+
diff --git a/.gitignore b/.gitignore
index c6d4b9c5..b50b7f90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,6 @@ CaseStudy/
 .eggs/
 examples/develop-example/
 .coverage
+/surmise/_version.py
+/wheelhouse/
+/dist/
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 519e2da9..2e321db8 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -4,6 +4,15 @@ Release Notes
 
 Below are the notes from all surmise releases.
 
+Release 0.2.1
+-------------
+
+:Date: September 26, 2023
+
+* Updates README to improve installation and testing procedures.
+* Updates Github action to build and upload .whl distribution files to PyPI.
+* Fixes testing procedure to ensure shell script searches under `sys.path` for `pytest`.
+
 Release 0.2.0
 -------------
 
diff --git a/README.rst b/README.rst
index 14132677..3a0e3892 100644
--- a/README.rst
+++ b/README.rst
@@ -37,22 +37,38 @@ From the command line, use the following command to install surmise::
 
  pip install surmise
 
-Alternatively, the source code can be downloaded to the local folder, and the
-package can be installed from the .tar file.
+The list of available .whl files can be found under `PyPI-wheel`_.  If a wheel file
+for your preferred platform is not listed, surmise has to be built from source,
+which requires extra dependencies::
+
+ git clone https://github.com/bandframework/surmise/
+ cd surmise
+ pip install -r requirements.txt
+
+.. note::
+
+    Direct installation of surmise requires Cython to build C executable.
+    On Windows platform Cython is supported by Microsoft build tools, for which installation
+    is outside pip.  See `Microsoft build tools`_ for details.
 
 Testing
 ~~~~~~~
 
-The test suite requires the pytest_ and pytest-cov_ packages to be installed
-and can be run from the ``tests/`` directory of the source distribution by running::
+The test suite requires the pytest_ and pytest-cov_ packages to be installed.  The packages
+can be installed via::
+
+ pip install pytest pytest-cov
+
+The test suite can then be run from within the ``tests/`` directory of the source distribution by running::
 
+ cd tests
  ./run-tests.sh
 
 Further options are available for testing. To see a complete list of options, run::
 
  ./run-tests.sh -h
 
-Coverage reports are produced under the relevant directory only if all tests are used.
+Coverage reports are produced under ``tests/cov_html`` directory only if all tests are used.
 
 Documentation
 ~~~~~~~~~~~~~
@@ -106,3 +122,5 @@ In addition, for a gentle introduction of emulation and calibration using Gaussi
 .. _Python: http://www.python.org
 .. _SciPy: http://www.scipy.org
 .. _`surmise Jupyter notebook`: https://colab.research.google.com/drive/1f4gKTCLEAGE8r-aMWOoGvY-O6zNqg1qj?usp=drive_link
+.. _PyPI-wheel: https://pypi.org/project/surmise/#files
+.. _`Microsoft build tools`: https://visualstudio.microsoft.com/downloads/?q=build+tools
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index ec02fdea..dd2a38e7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -36,3 +36,10 @@ build-backend = "setuptools.build_meta"
 
 [tool.setuptools_scm]
 write_to = "surmise/_version.py"
+
+[tool.cibuildwheel]
+# Skip 32-bit builds
+# Disable building PyPy wheels on all platforms
+# Disable musllinux
+skip = ["*-win32", "*_i686", "*-musllinux*", "pp*"]
+before-build = ["git status"]
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index eea71b86..f717f6ea 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,8 @@
 numpy>=1.18.3
 scipy>=1.7
-scikit-learn>=1.2.0
\ No newline at end of file
+scikit-learn>=1.2.0
+
+-e .
+pytest==7.4.1
+pytest-cov==4.1.0
+cython==3.0.2


Test patch:
diff --git a/.github/workflows/test-publish.yml b/.github/workflows/test-publish.yml
new file mode 100644
index 00000000..9fc33b72
--- /dev/null
+++ b/.github/workflows/test-publish.yml
@@ -0,0 +1,62 @@
+# This workflow tests releases to https://testpypi.org/project/surmise/
+
+name: Test PyPI Publisher
+
+on:
+  push:
+    branches:
+      - upload-test  # create branch as needed.
+#  release:
+#    types: [ published ]
+  
+jobs:
+  build-wheels:
+    name: Build wheels on ${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-22.04, windows-2022, macos-11]  # include only one to shorten test time
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - name: Build wheels
+        uses: pypa/cibuildwheel@v2.16.0
+
+      - uses: actions/upload-artifact@v3
+        with:
+          path: ./wheelhouse/*.whl
+
+  build-sdist:
+    name: Build source distribution
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - name: Build sdist
+        run: pipx run build --sdist
+      - uses: actions/upload-artifact@v3
+        with:
+          path: dist/*.tar.gz
+
+  pypi-publish:
+    name: Upload release to Test PyPI
+    needs: [build-wheels, build-sdist]
+    runs-on: ubuntu-latest
+    environment:
+      name: pypi
+      url: https://test.pypi.org/project/surmise/
+    permissions:
+      id-token: write
+    steps:
+      - uses: actions/download-artifact@v3
+        with:
+          name: artifact
+          path: dist
+      - name: Publish distribution 📦 to Test PyPI
+        uses: pypa/gh-action-pypi-publish@release/v1
+        with:
+          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
+          repository-url: https://test.pypi.org/legacy/
diff --git a/tests/__init__.py b/tests/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 1014ac2c..126f0732 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -122,7 +122,7 @@ fi;
 # Run Tests -----------------------------------------------------------------------
 if [ "$RUN_EMU_TESTS" = true ] && [ "$RUN_CAL_TESTS" = true ]; then
   echo -e "\n************** Running: surmise Test-Suite **************\n"
-  pytest $COV_LINE_SERIAL -k 'not new'
+  python -m pytest $COV_LINE_SERIAL -k 'not new'
 else
   if [ "$RUN_EMU_TESTS" = true ]; then
     if [ -z "$TEST_INPUT" ]; then
@@ -132,7 +132,7 @@ else
         cd $DIR
         for TEST_SCRIPT in $TEST_LIST
         do
-          pytest $TEST_SCRIPT $COV_LINE_SERIAL
+          python -m pytest $TEST_SCRIPT $COV_LINE_SERIAL
         done
       done
     else
@@ -142,7 +142,7 @@ else
         cd $DIR
         for TEST_SCRIPT in $TEST_LIST
         do
-          pytest $TEST_SCRIPT $COV_LINE_SERIAL --cmdopt1=$TEST_INPUT
+          python -m pytest $TEST_SCRIPT $COV_LINE_SERIAL --cmdopt1=$TEST_INPUT
         done
       done
     fi;
@@ -155,7 +155,7 @@ else
         cd $DIR
         for TEST_SCRIPT in $TEST_LIST
         do
-          pytest $TEST_SCRIPT $COV_LINE_SERIAL
+          python -m pytest $TEST_SCRIPT $COV_LINE_SERIAL
         done
       done
     else
@@ -165,7 +165,7 @@ else
         cd $DIR
         for TEST_SCRIPT in $TEST_LIST
         do
-          pytest $TEST_SCRIPT $COV_LINE_SERIAL --cmdopt2=$TEST_INPUT
+          python -m pytest $TEST_SCRIPT $COV_LINE_SERIAL --cmdopt2=$TEST_INPUT
         done
       done
     fi;
diff --git a/tests/test_emu_cal/__init__.py b/tests/test_emu_cal/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/test_new_calibrator/__init__.py b/tests/test_new_calibrator/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/test_new_emulator/__init__.py b/tests/test_new_emulator/__init__.py
deleted file mode 100644
index e69de29b..00000000