diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml new file mode 100644 index 0000000..528bc64 --- /dev/null +++ b/.github/workflows/flake8.yml @@ -0,0 +1,23 @@ +name: Check Code Style - FLAKE8 + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install Dependencies + run: | + # These packages are installed in the base environment but may be older + # versions. Explicitly upgrade them because they often create + # installation problems if out of date. + python -m pip install --upgrade pip setuptools numpy + + pip install flake8 + - name: Run flake8 + run: | + flake8 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..04771bb --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,39 @@ +# This workflow will upload a Python Package using flit when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries +# This workflows will upload a Python Package when a release is created. +# For more information see: +# - https://docs.pypi.org/trusted-publishers/adding-a-publisher/ +# - https://github.com/pypa/gh-action-pypi-publish + +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Build package + run: | + set -vxeuo pipefail + python -m pip install --upgrade pip + pip install wheel setuptools + python setup.py sdist bdist_wheel + + - name: Publish wheels to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: ./dist/ diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a1db53a --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,46 @@ +name: Unit Tests + +on: [push, pull_request, workflow_dispatch] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + + fail-fast: false + steps: + + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install + shell: bash -l {0} + run: | + set -vxeuo pipefail + pip install --upgrade pip setuptools wheel numpy + pip install -r requirements-dev.txt + pip install -r requirements-extras.txt + pip install -e . + pip list + + - name: Test with pytest + shell: bash -l {0} + run: | + set -vxeuo pipefail + coverage run --source=csxtools run_tests.py + coverage xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + file: ./coverage.xml + flags: unittests + diff --git a/.gitignore b/.gitignore index 488c458..b023f45 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ docs/_build/ #pycharm .idea/* +.vscode #Dolphin browser files .directory/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index db7411b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,51 +0,0 @@ -language: python -sudo: false - -matrix: - include: - - python: 3.5 - -services: - - mongodb - -addons: - apt: - sources: - - mongodb-3.2-precise - packages: - - mongodb-org-server - - mongodb-org - -env: - global: - - GH_USER=stuwilkins - - MDS_HOST=localhost - - MDS_DATABASE=test - - MDS_TIMEZONE=US/Eastern - - FS_HOST=localhost - - FS_DATABASE=test - -before_install: - - git config --global user.email "donotreply@travis.ci" - - git config --global user.name "travisci" - - git config --global credential.helper store --file=$HOME/.git-credentials - - echo "https://${GH_USER}:${GH_TOKEN}@github.com" > $HOME/.git-credentials - -install: - - export GIT_FULL_HASH=`git rev-parse HEAD` - - pip install --upgrade numpy setuptools pip - - pip install -r requirements-dev.txt - - pip install -e .[complete] - -script: - - flake8 - - coverage run --source=csxtools run_tests.py - - cd $TRAVIS_BUILD_DIR/doc && make html - -after_success: - - cd $TRAVIS_BUILD_DIR && coveralls - - cd $TRAVIS_BUILD_DIR && codecov - - | - if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then - cd $TRAVIS_BUILD_DIR/doc && make gh-pages - fi diff --git a/setup.py b/setup.py index 83e3d5b..95e5056 100644 --- a/setup.py +++ b/setup.py @@ -1,45 +1,82 @@ -from __future__ import (absolute_import, division, print_function) -import setuptools -from distutils.core import setup, Extension +from __future__ import absolute_import, division, print_function + +import sys +from distutils.core import Extension, setup +from os import path + import numpy as np +import setuptools + import versioneer -with open('requirements.txt') as f: +min_version = (3, 8) +if sys.version_info < min_version: + error = """ +bluesky-adaptive does not support Python {0}.{1}. +Python {2}.{3} and above is required. Check your Python version like so: + +python3 --version + +This may be due to an out-of-date pip. Make sure you have pip >= 9.0.1. +Upgrade pip like so: + +pip install --upgrade pip +""".format( + *(sys.version_info[:2] + min_version) + ) + sys.exit(error) + +here = path.abspath(path.dirname(__file__)) + +with open(path.join(here, "README.md"), encoding="utf-8") as readme_file: + readme = readme_file.read() + + +with open("requirements.txt") as f: requirements = f.read().split() -with open('requirements-extras.txt') as f: - extras_require = {'complete': f.read().split()} - -fastccd = Extension('fastccd', - sources=['src/fastccdmodule.c', - 'src/fastccd.c'], - extra_compile_args=['-fopenmp'], - extra_link_args=['-lgomp']) - -image = Extension('image', - sources=['src/imagemodule.c', - 'src/image.c'], - extra_compile_args=['-fopenmp'], - extra_link_args=['-lgomp']) - -phocount = Extension('phocount', - sources=['src/phocountmodule.c', - 'src/phocount.c'], - extra_compile_args=['-fopenmp'], - extra_link_args=['-lgomp']) +with open("requirements-extras.txt") as f: + extras_require = {"complete": f.read().split()} + +fastccd = Extension( + "fastccd", + sources=["src/fastccdmodule.c", "src/fastccd.c"], + extra_compile_args=["-fopenmp"], + extra_link_args=["-lgomp"], +) + +image = Extension( + "image", sources=["src/imagemodule.c", "src/image.c"], extra_compile_args=["-fopenmp"], extra_link_args=["-lgomp"] +) + +phocount = Extension( + "phocount", + sources=["src/phocountmodule.c", "src/phocount.c"], + extra_compile_args=["-fopenmp"], + extra_link_args=["-lgomp"], +) setup( - name='csxtools', + name="csxtools", version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), - author='Brookhaven National Laboratory', - packages=setuptools.find_packages(exclude=['src', 'tests']), - ext_package='csxtools.ext', + author="Brookhaven National Laboratory", + description="Python library for tools to be used at the Coherent Soft X-ray scattering (CSX) beamline at NSLS-II.", + packages=setuptools.find_packages(exclude=["src", "tests"]), + python_requires=">={}".format(".".join(str(n) for n in min_version)), + long_description=readme, + long_description_content_type='text/markdown', + ext_package="csxtools.ext", include_dirs=[np.get_include()], ext_modules=[fastccd, image, phocount], - tests_require=['pytest'], + tests_require=["pytest"], install_requires=requirements, extras_require=extras_require, - url='http://github.com/NSLS-II_CSX/csxtools', - keywords='Xray Analysis', - license='BSD' + url="https://github.com/NSLS-II-CSX/csxtools", + keywords="Xray Analysis", + license="BSD", + classifiers=[ + "Development Status :: 2 - Pre-Alpha", + "Natural Language :: English", + "Programming Language :: Python :: 3", + ], )