Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
* add sanitized pcsl match reports as test cases
* update dependencies
* establish auto-discovery and auto-testing of match report files in tests/mocks_data/match_reports
* update tox and github actions configs to handle multi-os test matrix
  • Loading branch information
cahna authored Dec 25, 2023
1 parent 5f31b47 commit 89883c2
Show file tree
Hide file tree
Showing 27 changed files with 1,795 additions and 722 deletions.
21 changes: 13 additions & 8 deletions .github/actions/setup-poetry-env/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@ name: "setup-poetry-env"
description: "Composite action to setup the Python and poetry environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.10"
python-version:
required: false
description: "The python version to use"
default: "3.10"
cached-venv:
required: false
description: "Whether to use a cached venv or not"
default: true

runs:
using: "composite"
steps:
- name: Set up python
- name: Set up python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
virtualenvs-in-project: ${{ inputs.cached-venv }}

- name: get repository name
- name: "Set env vars"
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
shell: bash

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
if: ${{ inputs.cached-venv }}
with:
path: .venv
key: venv-$${{ env.REPOSITORY_NAME }}-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
if: ${{ inputs.cached-venv && steps.cached-poetry-dependencies.outputs.cache-hit != 'true' }}
run: poetry install --no-interaction
shell: bash
75 changes: 50 additions & 25 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3

- name: get repository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
shell: bash
uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ env.REPOSITORY_NAME }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
- name: Init python/poetry environment
uses: ./.github/actions/setup-poetry-env

- name: Run pre-commit
Expand All @@ -34,48 +30,77 @@ jobs:

- name: Check Poetry lock file consistency
run: poetry lock --check

- name: black
run: poetry run black --check ./hitfactorpy ./tests

- name: flake8
run: poetry run flake8 ./hitfactorpy ./tests

- name: isort
run: poetry run isort --check ./hitfactorpy ./tests

typecheck:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: ~/.mypy_cache
key: mypy-cache-${{ env.REPOSITORY_NAME }}-${{ hashFiles('pyproject.toml') }}

- name: Init python/poetry environment
uses: ./.github/actions/setup-poetry-env

- run: poetry run mypy ./hitfactorpy ./tests

tox:
runs-on: ubuntu-latest
needs:
- quality
- typecheck
strategy:
matrix:
platform:
- ubuntu-latest
- macos-latest
# - windows-latest
python-version: ['3.10', '3.11']
fail-fast: false
fail-fast: true
runs-on: ${{ matrix.platform }}
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v4
- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1

- name: get repository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
shell: bash

- name: Load cached venv
uses: actions/cache@v3
with:
path: .tox
key: venv-${{ env.REPOSITORY_NAME }}-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}

- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

check-docs:
needs:
- quality
- typecheck
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/release-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish to PyPI
on:
release:
types: [published]

jobs:
pypi_release:
name: Poetry Build & Publish (PyPI)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Init python/poetry environment
uses: ./.github/actions/setup-poetry-env
with:
cached-venv: false

- run: poetry run pytest

- run: poetry config pypi-token.pypi "${{ secrets.PYPI_API_KEY }}"

- name: "TODO: Publish to PyPI"
run: echo TODO && exit 1
shell: bash
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: mypy
files: ^(hitfactorpy/|tests/)
additional_dependencies:
- "pydantic>=1.10.4"
- "pydantic>=1.10.4,<2"
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
Expand Down
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"recommendations": [
"ms-python.python",
"ms-python.black-formatter",
"ms-python.isort",
"ms-python.mypy-type-checker",
"ms-python.vscode-pylance",
"ms-python.flake8"
]
}
8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
"editor.tabSize": 4,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.testing.pytestArgs": [
"tests"
Expand Down
2 changes: 2 additions & 0 deletions hitfactorpy/parsers/match_report/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class ParsedStage:

internal_id: int
name: Optional[str] = None
number: Optional[int | str] = None
min_rounds: Optional[int] = 0
max_points: Optional[int] = 0
classifier: bool = False
classifier_number: Optional[str] = None
scoring_type: Scoring = Scoring.COMSTOCK
gun_type: Optional[str] = None


@dataclass(frozen=True)
Expand Down
9 changes: 6 additions & 3 deletions hitfactorpy/parsers/match_report/pandas/stage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from enum import Enum, unique
from enum import Enum
from io import StringIO
from typing import Any, Callable, List, Mapping

Expand All @@ -13,7 +13,6 @@
_logger = logging.getLogger(__name__)


@unique
class StageColumnName(str, Enum):
"""Known competitor column names. May also include dataframe references and custom columns added to the dataframe after parsing."""

Expand All @@ -24,6 +23,7 @@ class StageColumnName(str, Enum):
CLASSIFIER_NUM = "Classifier_No"
STAGE_NAME = "Stage_name"
SCORING = "ScoringType"
GUN_TYPE = "Guntype"


CSV_CONVERTERS: Mapping[str, Callable[[str], Any]] = {
Expand Down Expand Up @@ -54,20 +54,23 @@ def parse_stages(stage_csv_text: str) -> List[ParsedStage]:
ParsedStage(
internal_id=internal_id,
name=stage_name,
number=internal_id,
scoring_type=scoring,
min_rounds=min_rounds,
max_points=max_points,
classifier=classifier,
classifier_number=classifier_number,
gun_type=gun_type,
)
for internal_id, stage_name, scoring, min_rounds, max_points, classifier, classifier_number in zip(
for internal_id, stage_name, scoring, min_rounds, max_points, classifier, classifier_number, gun_type in zip(
df.index,
df[StageColumnName.STAGE_NAME],
df[StageColumnName.SCORING],
df[StageColumnName.MIN_ROUNDS],
df[StageColumnName.MAX_POINTS],
df[StageColumnName.CLASSIFIER],
df[StageColumnName.CLASSIFIER_NUM],
df[StageColumnName.GUN_TYPE],
)
]
# TODO: how to handle this edge case?
Expand Down
7 changes: 6 additions & 1 deletion hitfactorpy/parsers/match_report/strict/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@unique
class StageColumn(int, Enum):
ID = 0
GUN_TYPE = 1
MIN_ROUNDS = 2
MAX_POINTS = 3
CLASSIFIER = 4
Expand Down Expand Up @@ -53,16 +54,20 @@ def parse_match_report_stage_lines(
stages: List[ParsedStage] = []
for line in stage_lines:
row = parse_csv_row(line)
stage_number_text = row[StageColumn.ID].strip()
stage_number = int(re.sub(r"[^0-9]", "", stage_number_text))
stage = ParsedStage(
internal_id=int(re.sub(r"[^0-9]", "", row[StageColumn.ID].strip())),
internal_id=stage_number,
name=row[StageColumn.STAGE_NAME].strip(),
number=stage_number,
min_rounds=parse_int_value(row[StageColumn.MIN_ROUNDS]),
max_points=parse_int_value(row[StageColumn.MAX_POINTS]),
classifier=row[StageColumn.CLASSIFIER].strip().lower() == "yes",
classifier_number=row[StageColumn.CLASSIFIER_NUM].strip(),
scoring_type=parse_scoring(row[StageColumn.SCORING])
if len(row) > StageColumn.SCORING
else Scoring.COMSTOCK,
gun_type=row[StageColumn.GUN_TYPE].strip(),
)
stages.append(stage)
return stages
Loading

0 comments on commit 89883c2

Please sign in to comment.