Skip to content

Commit

Permalink
First version for CI, similar to pymeasure.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Jul 12, 2023
1 parent 1734a92 commit eae0d44
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 10 deletions.
23 changes: 23 additions & 0 deletions .github/pytest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"problemMatcher": [
{
"owner": "pytest-warnings",
"severity": "warning",
"pattern": [
{
"regexp": "^=+ warnings summary =+$"
},
{
"regexp": "^(?<path>.+?):(?<line>\\d+)$",
"file": 1,
"line": 2
},
{
"regexp": "^ (?<message>.+)$",
"message": 1,
"loop": true
}
]
}
]
}
38 changes: 38 additions & 0 deletions .github/sphinx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"problemMatcher": [
{
"owner": "sphinx-docstring",
"pattern": [
{
"regexp": "^(?<path>.+?):(?<message>.*? (?<severity>WARNING|ERROR): .+)$",
"file": 1,
"severity": 3,
"message": 2
}
]
},
{
"owner": "sphinx-doctest",
"pattern": [
{
"regexp": "^File \\\"(?<path>.+?)\\\", line (?<line>\\d+|\\?), (?<msg>.*$)",
"file": 1,
"line": 2,
"message": 3
}
]
},
{
"owner": "sphinx-extension",
"pattern": [
{
"regexp": "^(?<severity>WARNING|ERROR): (?<code>\\S+): (?<message>.+)(?<dummy_file_entry>)$",
"severity": 1,
"code": 2,
"message": 3,
"file": 4
}
]
}
]
}
105 changes: 105 additions & 0 deletions .github/workflows/pyleco_CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: PyLECO CI
on:
push:
branches:
- main
pull_request:

jobs:
docs_lint:
name: Docs and Linting
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache conda
uses: actions/cache@v3
env:
CACHE_NUMBER: 0 # Increase to reset the cache
with:
path: ~/conda_pkgs_dir
key: py3.10-ubuntu-latest-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
- name: Install pyleco requirements
uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
environment-file: environment.yml
activate-environment: pyleco
auto-update-conda: true
use-only-tar-bz2: true # for caching to work properly
- name: Conda info & list
run: |
conda info
conda list
- name: Set up flake8 annotations
uses: rbialon/flake8-annotations@v1
- name: Lint with flake8
run: |
# Be sure to check for Python syntax errors or undefined names
flake8 . --count --extend-select=E9,F63,F7,F82 --show-source --statistics
- uses: ammaraskar/sphinx-problem-matcher@master
- name: Generate docs
if: always() # run even if the previous step failed
working-directory: ./docs
run: |
echo "::add-matcher::.github/sphinx.json"
make html SPHINXOPTS="-W --keep-going"
- name: Run doctests
if: always() # run even if the previous step failed
working-directory: ./docs
run: |
echo "::add-matcher::.github/sphinx.json"
make doctest SPHINXOPTS="-W --keep-going"
test:
name: Python ${{ matrix.python-version }}, ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache conda
uses: actions/cache@v3
env:
CACHE_NUMBER: 0 # Increase to reset the cache
with:
path: ~/conda_pkgs_dir
key: py${{ matrix.python-version }}-${{ matrix.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
- name: Install pyleco requirements
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
environment-file: environment.yml
activate-environment: pyleco
auto-update-conda: true
use-only-tar-bz2: true # for caching to work properly
- name: Install Pyleco
# If the pytest problem matcher stops working because of bad paths, do an editable install
run: pip install .[tests]
- name: Pyleco version
run: python -c "import pyleco;print(pyleco.__version__)"
- name: Conda info & list
run: |
conda info
conda list
- name: Run pytest with xvfb
if: runner.os == 'Linux'
run: |
echo "::add-matcher::.github/pytest.json"
xvfb-run -a pytest
- name: Run pytest
if: runner.os != 'Linux'
run: |
echo "::add-matcher::.github/pytest.json"
pytest
3 changes: 3 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
######
PyLeco
######
16 changes: 10 additions & 6 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ name: pyleco
channels:
- conda-forge
dependencies:
- pyzmq=25.0.0
- pyzmq=25.1.0
- pip # don't pin, to gain newest conda compatibility fixes
- pip:
- jsonrpc2-pyclient==2.2.12
- openrpc==6.3.17
- uuid7==0.1.0
# Development dependencies below
- pytest=7.2.0
- pytest-runner=6.0.0
- flake8=6.0.0
- setuptools_scm # don't pin, to get newest features
- sphinx=6.1.3
- sphinx_rtd_theme=1.0.0
# - pip # don't pin, to gain newest conda compatibility fixes
# - pip:
# - xxx
# - sphinx=6.1.3
# - sphinx_rtd_theme=1.0.0
51 changes: 51 additions & 0 deletions pyleco/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# This file is part of the PyLECO package.
#
# Copyright (c) 2023-2023 PyLECO Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

import warnings

# Maximally flexible approach to obtain version numbers, based on this approach:
# https://github.com/pypa/setuptools_scm/issues/143#issuecomment-672878863
# Sadly, this does not work with editable installs, which bake in version info on installation.
# see also https://github.com/pyusb/pyusb/pull/307#issuecomment-650797688
try:
# If a user has setuptools_scm installed, assume they want the most up to date version string.
# Alternatively, we could use a dummy dev module that is never packaged whose presence signals
# that we are in an editable install/repo, see https://github.com/pycalphad/pycalphad/pull/341
import setuptools_scm
__version__ = setuptools_scm.get_version(root='..', relative_to=__file__)
del setuptools_scm
except (ImportError, LookupError):
# Setuptools_scm was not found, or it could not find a version, so use installation metadata.
from importlib.metadata import version, PackageNotFoundError
try:
__version__ = version("pyleco")
# Alternatively, if the current approach is too slow, we could add
# 'write_to = "pyleco/_version.py"' in pyproject.toml and use the generated file here:
# from ._version import version as __version__
except PackageNotFoundError:
warnings.warn('Could not find pyleco version, it does not seem to be installed. '
'Either install it (editable or full) or install setuptools_scm')
__version__ = '0.0.0'
finally:
del version, PackageNotFoundError
14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ classifiers = [

requires-python = ">=3.10"
dependencies = [
"pyzmq",
"openrpc",
"jsonrpc2-pyclient",
"uuid7",
"pyzmq" >= 22.3.0,
"openrpc" >= 6.3.17,
"jsonrpc2-pyclient" >= 2.2.12,
"uuid7" >= 0.1.0,
]

[project.optional-dependencies]
Expand All @@ -39,3 +39,9 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
# write_to = "pyleco/_version.py"

[tool.black]
line-length = 100

[tool.isort]
profile = "black"
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
exclude = .git,__pycache__,docs/conf.py,build,dist
max-line-length = 100
max-complexity = 15
per-file-ignores =
__init__.py:F401

0 comments on commit eae0d44

Please sign in to comment.