Skip to content

Commit

Permalink
CI/CD (#59)
Browse files Browse the repository at this point in the history
* cicd

* try to speed up tests

* cancel previous runs on push

* lower tol for windows

* change name for pypi

* metadata update

* readme updates
  • Loading branch information
tjlane authored Oct 31, 2024
1 parent c8014de commit bc84ac0
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 19 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: deploy

on:
workflow_run:
branches:
- master
workflows:
- "tests"
- "mypy"
- "ruff"
types:
- completed

jobs:
deploy:
name: deploy-to-pypi
runs-on: ubuntu-latest
# only run if previous workflows were a success
# AND the commit starts with v (meaning it's a tag)
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_commit.message, 'v') }}

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: install
run: |
git tag
pip install -U pip
pip install -U build twine
python -m build
twine check dist/*
ls -lh dist
- name: build and publish
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_KEY }}

- uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
7 changes: 6 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ruff

on: [push]
on: [pull_request]

jobs:
build:
Expand All @@ -10,6 +10,11 @@ jobs:
python-version: ["3.11"]

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v4

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mypy

on: [push]
on: [pull_request]

jobs:
build:
Expand All @@ -10,6 +10,11 @@ jobs:
python-version: ["3.11"]

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v4

Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
name: tests

on: [push]
on:
pull_request:
schedule:
- cron: "0 12 * * 1" # monday at noon GMT

jobs:
build:
runs-on: ubuntu-latest
name: ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
python-version:
- '3.11'
platform:
- ubuntu-latest
- macos-latest
- windows-latest

steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v4
with:
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ Map Enhancement Tools for Ephemeral Occupancy Refinement

Finally: a word of caution. Expect changes in the coming weeks as we stress test the code. You might want to consider this before publishing any results with `meteor` until we exit `beta`.

In that vein, for now please install the current master branch as per the following instructions. We'll have a sane
first stable version soon, which will be deployed straight to `PyPI` and `conda-forge`. Stay posted.

First, we recommend you make a new environment. For conda users,
First, meteor needs a `python3.11` environment. We're working hard to extend this to as many versions as possible. To be sure things work, we recommend [installing conda](https://docs.anaconda.com/miniconda/) and creating a fresh environment,
```
conda create --name meteor python==3.11 --yes
conda activate meteor
```

Then install from github,
Then install `meteor` using pip
```
pip install git+https://github.com/alisiafadini/meteor
pip install meteor-maps
```

Once installed, you will have two command-line scripts. Ask for more info using `-h`:
```
meteor.diffmap -h
meteor.phaseboost -h
```
which compute denoised difference maps using the constant-phase approximation _vs._ iterative phase retrieval, respectively.
these scripts compute denoised difference maps using the constant-phase approximation _vs._ iterative phase retrieval, respectively.


## philosophy: better science through automation
Expand Down
20 changes: 15 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ requires = ["setuptools >= 61.0", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "meteor"
name = "meteor-maps"
description = "denoise crystallographic difference maps"
dynamic = ["version"]
authors = [
{ name = "Alisia Fadini", email = "[email protected]" },
{ name = "Thomas Lane", email = "thomas.lane@desy.de" }
{ name = "Thomas Lane", email = "thomas.joseph.lane@gmail.com" }
]
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"numpy >= 1.26",
"scipy >= 1.14.0",
Expand All @@ -24,15 +29,23 @@ dependencies = [
tests = [
"pytest",
"pytest-cov",
"pytest-xdist",
]

[project.scripts]
"meteor.diffmap" = "meteor.scripts.compute_difference_map:main"
"meteor.phaseboost" = "meteor.scripts.compute_iterative_tv_map:main"

[project.urls]
Homepage = "https://github.com/rs-station/meteor"
Issues = "https://github.com/rs-station/meteor/issues"

[tool.setuptools_scm]
version_file = "meteor/_version.py"

[tool.pytest.ini_options]
addopts = "-n 4 --cov=meteor --cov-report=xml"

[tool.mypy]
disallow_untyped_calls = true
disallow_untyped_defs = true
Expand Down Expand Up @@ -101,6 +114,3 @@ exclude = [

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.pytest.ini_options]
addopts = "--cov=meteor --cov-report=xml"
5 changes: 5 additions & 0 deletions test/functional/test_compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import pytest
import reciprocalspaceship as rs

from meteor import settings
from meteor.rsmap import Map
from meteor.scripts import compute_difference_map
from meteor.scripts.common import WeightMode
from meteor.tv import TvDenoiseResult
from meteor.utils import filter_common_indices

# faster tests
settings.MAP_SAMPLING = 1
settings.TV_MAX_NUM_ITER = 10


@pytest.mark.parametrize("kweight_mode", list(WeightMode))
@pytest.mark.parametrize("tv_weight_mode", list(WeightMode))
Expand Down
5 changes: 5 additions & 0 deletions test/functional/test_compute_iterative_tv_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import numpy as np
import reciprocalspaceship as rs

from meteor import settings
from meteor.rsmap import Map
from meteor.scripts import compute_iterative_tv_map
from meteor.scripts.common import read_combined_metadata
from meteor.utils import filter_common_indices

# faster tests
settings.MAP_SAMPLING = 1
settings.TV_MAX_NUM_ITER = 10


def test_script_produces_consistent_results(
testing_pdb_file: Path,
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_rsmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def test_ccp4_map_round_trip(
assert_phases_allclose(
random_difference_map.phases.to_numpy(),
output_coefficients.phases.to_numpy(),
atol=0.01,
)


Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ def test_scale_maps_uncertainty_weighting() -> None:
weight_using_uncertainties=True,
)

np.testing.assert_allclose(scaled["F"][(0, 0, 2)], 0.5)
np.testing.assert_allclose(scaled["SIGF"][(0, 0, 2)], 250000.0)
np.testing.assert_allclose(scaled["F"][(0, 0, 2)], 0.5, atol=1e-4)
np.testing.assert_allclose(scaled["SIGF"][(0, 0, 2)], 250000.0, rtol=1e-4)

0 comments on commit bc84ac0

Please sign in to comment.