Skip to content

Commit

Permalink
Added coverage actions
Browse files Browse the repository at this point in the history
Improved README and pyproject.toml
  • Loading branch information
JosePizarro3 committed Jun 10, 2024
1 parent 1a9d4dd commit 9ea306a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 34 deletions.
78 changes: 50 additions & 28 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,62 @@
name: install-and-test
on: [push]

# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# `contents` is for permission to the contents of the repository.
# `pull-requests` is for permission to pull request
permissions:
contents: write
checks: write
pull-requests: write

jobs:
install-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
pip install --upgrade pip
pip install '.[dev]'
- name: mypy
run: |
python -m mypy --ignore-missing-imports --follow-imports=silent --no-strict-optional src/pyssmf tests
- name: Test with pytest
run: |
python -m pytest -sv tests
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
pip install uv
pip install --upgrade pip --system
uv pip install '.[dev]' --system
- name: mypy
run: |
python -m mypy --ignore-missing-imports --follow-imports=silent --no-strict-optional src/pyssmf tests
- name: Build coverage file
run: |
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=src tests | tee pytest-coverage.txt
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
- name: Submit to coveralls
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coveralls --service=github
build-and-install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Build the package
run: |
pip install --upgrade pip
pip install build
python -m build --sdist
- name: Install the package
run: |
pip install dist/*.tar.gz
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Build the package
run: |
pip install uv
uv pip install --upgrade pip --system
uv pip install build --system
python -m build --sdist
- name: Install the package
run: |
uv pip install dist/*.tar.gz
ruff-linting:
runs-on: ubuntu-latest
steps:
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,51 @@ python3.9 -m venv .pyenv
source .pyenv/bin/activate
```

We recommend using `uv` for pip installing all packages:
```sh
pip install uv
```

Make sure to have pip upgraded to its latest version:
```sh
pip install --upgrade pip
uv pip install --upgrade pip
```

Now, install the dependencies in editable mode (this is done by adding the flag `-e` and it is useful when debugging the code):
```sh
pip install -e '.[dev]'
uv pip install -e '.[dev]'
```

The `[dev]` option will allow to install the optional-dependencies specified in the configuration `pyproject.toml` file.

### Run the tests

You can run local tests using the `pytest` package:

```sh
python -m pytest -sv tests
```

where the `-s` and `-v` options toggle the output verbosity.

Our CI/CD pipeline produces a more comprehensive test report using `coverage` and `coveralls` packages. We suggest you to generate your own coverage reports locally by doing:

```sh
uv pip install coverage coveralls
python -m pytest --cov=src tests
```

### Run linting and auto-formatting

We use [Ruff](https://docs.astral.sh/ruff/) for auto-formatting our Python modules. This package is included as part of the `[dev]` dependencies of the project, and can be run in the terminal:

```sh
ruff check .
ruff format . --check
```

Ruff auto-formatting is also a part of the GitHub workflow actions. Make sure that before you make a Pull Request, `ruff format . --check` runs in your local without any errors otherwise the workflow action will fail.

### Using VSCode for debugging

I recommend to use VSCode as your visual editor for debugging. The project comes with a `settings.json` file which already takes care of formatting everytime you save changes in a file (using [Ruff](https://docs.astral.sh/ruff/)).
Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ build-backend = "setuptools.build_meta"

[project]
name = 'pySSMF'
version = '0.1.0'
description = 'A Python package to solve the Slave-Spin Mean-Field equations for tight-binding models in strongly correlated systems'
authors = [
{ name = "Jose M. Pizarro", email = "[email protected]" }
]
license = { text = "Apache-2.0" }
maintainers = [
{ name = "Jose M. Pizarro", email = "[email protected]" }
]
dynamic = ["version"]
license = { file = "LICENSE" }
requires-python = ">=3.9"
readme = "README.md"
dependencies = [
Expand All @@ -29,11 +32,12 @@ dependencies = [
[project.optional-dependencies]
dev = [
'mypy==1.5.1',
'pytest==3.10.0',
'pytest',
'pytest-timeout',
'pytest-cov',
'ruff',
"structlog==22.3.0",
"lxml_html_clean>=0.1.0",
"PyQt5==5.15.10",
]

[tool.ruff]
Expand Down

0 comments on commit 9ea306a

Please sign in to comment.