Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating pre-commit and running pylint/pyright #343

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ jobs:
- name: Formatting + Lint
shell: bash
run: |
poetry run ruff check . --fix --exit-zero
poetry run ruff check .
poetry run ruff format --check .

# - name: Run pyright
# run: poetry run pyright
- name: Run pyright
run: poetry run pyright

# - name: Thorough check with pylint
# run: poetry run pylint awpy
- name: Thorough check with pylint
run: poetry run pylint awpy

- name: Test
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install awpy
run: |
poetry install --no-interaction

- name: Publish to PyPI
run: |
poetry publish --build --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} -vvv
poetry publish --build --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} -vvv
24 changes: 13 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
exclude: docs/
repos:
# - repo: https://github.com/JanEricNitschke/pymend
# rev: "v1.0.10"
# hooks:
# - id: pymend
# language: python
# args: ["--write", "--check"]
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
language: python
Expand All @@ -25,20 +31,16 @@ repos:
language: python
- id: check-builtin-literals
language: python
- repo: 'https://github.com/charliermarsh/ruff-pre-commit'
rev: v0.0.291
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
rev: v0.5.6
hooks:
- id: ruff
args:
- '--fix'
- '--exit-non-zero-on-fix'
- repo: 'https://github.com/psf/black'
rev: 23.9.1
hooks:
- id: black
language: python
- "--fix"
- "--exit-non-zero-on-fix"
- id: ruff-format
- repo: https://github.com/crate-ci/typos
rev: v1.16.13
rev: v1.23.6
hooks:
- id: typos
args: []
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ build:
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install

sphinx:
configuration: docs/conf.py
configuration: docs/conf.py
29 changes: 15 additions & 14 deletions awpy/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Command-line interface for Awpy."""

from pathlib import Path
from typing import Literal, Optional
from typing import Literal

import click
import requests
Expand All @@ -23,9 +23,7 @@ def awpy() -> None:
)
@click.argument("resource_type", type=click.Choice(["map", "nav", "usd"]))
@click.argument("resource_name", required=False)
def get(
resource_type: Literal["map", "nav", "usd"], resource_name: Optional[str]
) -> None:
def get(resource_type: Literal["map", "nav", "usd"], resource_name: str | None) -> None:
"""Get a resource given its type and name."""
if not AWPY_DATA_DIR.exists():
AWPY_DATA_DIR.mkdir(parents=True, exist_ok=True)
Expand All @@ -47,7 +45,7 @@ def get(
block_size = 1024
with (
tqdm(total=total_size, unit="B", unit_scale=True) as progress_bar,
open(usd_file_path, "wb") as file,
usd_file_path.open("wb") as file,
):
for data in response.iter_content(block_size):
progress_bar.update(len(data))
Expand All @@ -65,7 +63,7 @@ def get(
block_size = 1024
with (
tqdm(total=total_size, unit="B", unit_scale=True) as progress_bar,
open(usd_file_path, "wb") as file,
usd_file_path.open("wb") as file,
):
for data in response.iter_content(block_size):
progress_bar.update(len(data))
Expand All @@ -80,8 +78,12 @@ def get(


@awpy.command(help="Parse a Counter-Strike 2 demo file.")
@click.argument("demo", type=click.Path(exists=True))
@click.option("--outpath", type=click.Path(), help="Path to save the compressed demo.")
@click.argument("demo_path", type=click.Path(exists=True, path_type=Path))
@click.option(
"--outpath",
type=click.Path(path_type=Path),
help="Path to save the compressed demo.",
)
@click.option("--verbose", is_flag=True, default=False, help="Enable verbose mode.")
@click.option("--noticks", is_flag=True, default=False, help="Disable tick parsing.")
@click.option(
Expand All @@ -97,17 +99,16 @@ def get(
"--other-props", multiple=True, help="List of other properties to include."
)
def parse(
demo: Path,
demo_path: Path,
*,
outpath: Optional[Path] = None,
outpath: Path | None = None,
verbose: bool = False,
noticks: bool = False,
norounds: bool = True,
player_props: Optional[tuple[str]] = None,
other_props: Optional[tuple[str]] = None,
player_props: tuple[str] | None = None,
other_props: tuple[str] | None = None,
) -> None:
"""Parse a file given its path."""
demo_path = Path(demo) # Pathify
"""Parse a file given its path.""" # Pathify
demo = Demo(
path=demo_path,
verbose=verbose,
Expand Down
29 changes: 13 additions & 16 deletions awpy/converters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Converters for index-based fields."""

import pandas as pd
from typing import TYPE_CHECKING

if TYPE_CHECKING:
import pandas as pd

def map_hitgroup(series: pd.Series) -> pd.Series:

def map_hitgroup(series: "pd.Series[int]") -> "pd.Series[str]":
"""Map hitgroups to their names.

Args:
Expand All @@ -12,7 +15,7 @@ def map_hitgroup(series: pd.Series) -> pd.Series:
Returns:
pd.Series: Series of hitgroup names.
"""
hitgroup_mapping = {
hitgroup_mapping: dict[int, str] = {
0: "generic",
1: "head",
2: "chest",
Expand All @@ -24,12 +27,10 @@ def map_hitgroup(series: pd.Series) -> pd.Series:
8: "neck",
10: "gear",
}
return series.map(
lambda x: hitgroup_mapping.get(x) # pylint: disable=unnecessary-lambda
)
return series.map(hitgroup_mapping)


def map_round_end_reasons(series: pd.Series) -> pd.Series:
def map_round_end_reasons(series: "pd.Series[int]") -> "pd.Series[str]":
"""Map round end reasons to their names.

Args:
Expand All @@ -38,7 +39,7 @@ def map_round_end_reasons(series: pd.Series) -> pd.Series:
Returns:
pd.Series: Series of round end reason names.
"""
round_end_reason_mapping = {
round_end_reason_mapping: dict[int, str] = {
0: "still_in_progress",
1: "target_bombed",
2: "vip_escaped",
Expand All @@ -61,12 +62,10 @@ def map_round_end_reasons(series: pd.Series) -> pd.Series:
19: "t_planted",
20: "cts_reached_hostage",
}
return series.map(
lambda x: round_end_reason_mapping.get(x) # pylint: disable=unnecessary-lambda
)
return series.map(round_end_reason_mapping)


def map_game_phase(series: pd.Series) -> pd.Series:
def map_game_phase(series: "pd.Series[int]") -> "pd.Series[str]":
"""Map game phases to their names.

Args:
Expand All @@ -75,7 +74,7 @@ def map_game_phase(series: pd.Series) -> pd.Series:
Returns:
pd.Series: Series of game phase names.
"""
game_phase_mapping = {
game_phase_mapping: dict[int, str] = {
0: "init",
1: "pregame",
2: "startgame",
Expand All @@ -85,6 +84,4 @@ def map_game_phase(series: pd.Series) -> pd.Series:
6: "stalemate",
7: "gameover",
}
return series.map(
lambda x: game_phase_mapping.get(x) # pylint: disable=unnecessary-lambda
)
return series.map(game_phase_mapping)
26 changes: 25 additions & 1 deletion awpy/data/map_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
"""Dictionary that holds map data for Counter-Strike 2."""

from typing import TypedDict

Number = int | float


class Selection(TypedDict):
"""Structure of selections data."""

name: str
altitude_max: Number
altitude_min: Number


class MapData(TypedDict):
"""Structure of map data."""

pos_x: Number
pos_y: Number
scale: Number
rotate: Number | None
zoom: Number | None
selections: list[Selection]


# pos_x is upper left world coordinate
MAP_DATA = {
MAP_DATA: dict[str, MapData] = {
"ar_baggage": {
"pos_x": -1316,
"pos_y": 1288,
Expand Down
Loading