Skip to content

Commit

Permalink
use uv (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn authored Oct 26, 2024
1 parent ca36b95 commit 148d444
Show file tree
Hide file tree
Showing 61 changed files with 1,895 additions and 585 deletions.
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

35 changes: 17 additions & 18 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

name: upload release to PyPI
runs-on: ubuntu-latest
environment: release
environment:
name: PyPI
url: https://pypi.org/p/cyeva
permissions:
id-token: write
env:
TRUSTED_PUBLISHING: always
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
- run: make build
- run: uv publish
82 changes: 0 additions & 82 deletions .github/workflows/pytest.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
coverage-perf:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- run: make bench

- name: Upload coverage reports to Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${{ secrets.CODECOV_TOKEN }}
- name: Continuous Benchmark
uses: benchmark-action/[email protected]
if: ${{ github.ref == 'refs/heads/main' }}
with:
name: cyeva Benchmark
tool: "pytest"
output-file-path: output.json
github-token: ${{ secrets.OPS_ACTIONS_CI_TOKEN }}
gh-repository: "github.com/caiyunapp/cyeva"
auto-push: true
alert-threshold: "150%"
comment-on-alert: true
fail-on-alert: false
benchmark-data-dir-path: "performance/"
alert-comment-cc-users: "@clarmy"

Test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- run: make all
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: "3.9"
python: "3.11"
# You can also specify other tool versions:
# nodejs: "16"
# rust: "1.55"
Expand All @@ -26,4 +26,4 @@ sphinx:
# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: requirements/requirements-doc.txt
- requirements: docs/requirements.txt
10 changes: 0 additions & 10 deletions MANIFEST.in

This file was deleted.

48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.PHONY: help build fmt lint sync lock upgrade all test

export PYTHONPATH := $(shell pwd)
export UV_PYTHON_PREFERENCE=only-system

help:
@echo "Available commands:"
@echo " build - Build the project using uv"
@echo " fmt - Format the code using ruff"
@echo " lint - Lint the code using ruff"
@echo " sync - Sync and compile the project using uv"
@echo " lock - Lock dependencies using uv"
@echo " upgrade - Upgrade dependencies using uv"
@echo " all - Run lock, sync, fmt, lint, and test"

build:
uv build --no-sources

fmt:
uv run ruff check --select I --fix .
uv run ruff format .

lint:
uv run ruff check --fix .
uv run ruff format --check .

sync:
uv sync --compile --frozen

lock:
uv lock

upgrade:
uv lock --upgrade

all: lock sync
make fmt
make lint
make test

test: lint
uv run pytest --cov=cyeva/ ./tests/functions ./tests/test_issues.py

bench: sync
uv run pytest --cov=cyeva/ -p no:warnings --memray --benchmark-json output.json tests/test_perf.py

freeze-doc-requirements:
cd docs;uv lock;uv export > requirements.txt
10 changes: 5 additions & 5 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Cyeva aims to make automated evaluation of the accuracy of deterministic meteoro
$ pip install cyeva
```

**Note: Since this project is currently in beta, it is not a stable version. It may undergo incompatible changes in future releases. Therefore, it's recommended to specify the version during installation, e.g., pip install cyeva==0.1.0b0.**
**Note: Since this project is currently in beta, it is not a stable version. It may undergo incompatible changes in future releases. Therefore, it's recommended to specify the version during installation, e.g., pip install cyeva==0.2.0.**

### Install from Source Code

Expand Down Expand Up @@ -58,7 +58,7 @@ print('accuracy ration within 1 degC:', temp.calc_diff_accuracy_ratio(limit=1))
print('accuracy ration within 2 degC:', temp.calc_diff_accuracy_ratio(limit=2)) # 2-degree accuracy (deviation within 2°C)
print('rss:', temp.calc_rss()) # Residual Sum of Squares
print('rmse:', temp.calc_rmse()) # Root Mean Square Error
print('mae:', temp.calc_mae()) # Mean Absolute Erro
print('mae:', temp.calc_mae()) # Mean Absolute Error
print('chi square:', temp.calc_chi_square()) # Chi Square (χ2)
```

Expand All @@ -79,7 +79,7 @@ precip = PrecipitationComparison(obs, fcst, unit='mm')

print('rss:', precip.calc_rss()) # Residual Sum of Squares
print('rmse:', precip.calc_rmse()) # Root Mean Square Error
print('mae:', precip.calc_mae()) # Mean Absolute Erro
print('mae:', precip.calc_mae()) # Mean Absolute Error
print('chi square:', precip.calc_chi_square()) # Chi Square (χ2)
print('accuracy ratio:', precip.calc_accuracy_ratio()) # Accuracy(0 level)
print('binary accuracy ratio:', precip.calc_binary_accuracy_ratio()) # Binary accuracy(Binary classes between sunny or rainy weather)
Expand Down Expand Up @@ -146,8 +146,8 @@ print('wind speed rss:', wind.calc_rss())
print('wind direction rss:', wind.calc_rss(kind='direction')) # Residual Sum of Squares(by direction)
print('wind speed rmse:', wind.calc_rmse()) # Root Mean Square Error(by speed/default)
print('wind direction rmse:', wind.calc_rmse(kind='direction')) # Root Mean Square Error(by direction)
print('wind speed mae:', wind.calc_mae()) # Mean Absolute Erro(by speed/default)
print('wind direction mae:', wind.calc_mae(kind='direction')) # Mean Absolute Erro(by direction)
print('wind speed mae:', wind.calc_mae()) # Mean Absolute Error(by speed/default)
print('wind direction mae:', wind.calc_mae(kind='direction')) # Mean Absolute Error(by direction)
print('wind speed chi square:', wind.calc_chi_square()) # Chi Square(χ2)
print('wind direction chi square:', wind.calc_chi_square(kind='direction')) # Chi Square(χ2)(by direction)
print('wind direction score:', wind.calc_dir_score()) # Direction score
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
[![Download statistic](https://pepy.tech/badge/cyeva)](https://pepy.tech/project/cyeva)
[![codecov](https://codecov.io/gh/caiyunapp/cyeva/branch/main/graph/badge.svg?token=344FXDKAYD)](https://codecov.io/gh/caiyunapp/cyeva)
[![performance](https://img.shields.io/badge/performance-benchmark-yellow)](https://caiyunapp.github.io/cyeva/performance/)
[![style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)


cyeva 是一个由彩云科技天气团队和社区贡献者共同开发的用于对气象要素确定性预报准确率进行快速评测的 Python 开源工具库。
Expand All @@ -30,7 +29,7 @@ cyeva 将致力于让气象要素确定性预报准确率的自动化评估变
$ pip install cyeva
```

**注意:由于本项目目前处于beta阶段,并非稳定版本,有可能在后续的发布版中出现不兼容性修改,因此在安装时建议指定版本号,例如 `pip install cyeva==0.1.0b0`**
**注意:由于本项目目前处于beta阶段,并非稳定版本,有可能在后续的发布版中出现不兼容性修改,因此在安装时建议指定版本号,例如 `pip install cyeva==0.2.0`**

### 通过源码安装

Expand Down
4 changes: 2 additions & 2 deletions cyeva/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .core import *
from .core import * # noqa

__version__ = "0.1.0.beta.12"
__version__ = "0.2.0"
Empty file removed cyeva/config/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions cyeva/config/directions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
This is the module to store wind directions constants.
* DIRECTION8_CENTER_ANGLE: Wind 8 cardinal directions central angles.
* DIRECTION16_CENTER_ANGLE: Wind 16 cardinal directions central angles.
* DIRECTION8_ABBR: Wind 8 cardinal directions abbreviation.
* DIRECTION16_ABBR: Wind 16 cardinal directions abbreviation.
"""

DIRECTION8_CENTER_ANGLE = {0: 0, 1: 45, 2: 90, 3: 135, 4: 180, 5: 225, 6: 270, 7: 315}
DIRECTION16_CENTER_ANGLE = {
0: 0,
1: 22.5,
2: 45,
3: 67.5,
4: 90,
5: 112.5,
6: 135,
7: 157.5,
8: 180,
9: 202.5,
10: 225,
11: 247.5,
12: 270,
13: 292.5,
14: 315,
15: 337.5,
}

DIRECTION8_ABBR = {0: "N", 1: "NE", 2: "E", 3: "SE", 4: "S", 5: "SW", 6: "W", 7: "NW"}
DIRECTION16_ABBR = {
0: "N",
1: "NNE",
2: "NE",
3: "ENE",
4: "E",
5: "ESE",
6: "SE",
7: "SSE",
8: "S",
9: "SSW",
10: "SW",
11: "WSW",
12: "W",
13: "WNW",
14: "NW",
15: "NNW",
}
Loading

0 comments on commit 148d444

Please sign in to comment.