Skip to content

Commit

Permalink
Merge pull request #11 from chrisburr/dev
Browse files Browse the repository at this point in the history
Add type hints and mypy CI
  • Loading branch information
chrisburr authored Feb 22, 2023
2 parents 5e6a0ba + 439d60e commit bc2a42a
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 139 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
run: |
. "${CONDA}/bin/activate" test-env
pytest
- name: Run mypy
run: |
. "${CONDA}/bin/activate" test-env
mypy
- name: Run pylint
run: |
. "${CONDA}/bin/activate" test-env
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -euo pipefail

PYTHON_VERSION=$1

conda create --quiet -c conda-forge -c free -n test-env \
conda create --quiet -c conda-forge -n test-env \
python="$PYTHON_VERSION" \
"pytest>=4.6" pylint pytest-cov pycodestyle \
setuptools setuptools_scm wheel
setuptools setuptools_scm wheel mypy
source "${CONDA}/bin/activate" test-env
pip install ".[testing]"
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ build-backend = "setuptools.build_meta"
[tool.black]
line-length = 120
target-version = ['py39']

[tool.mypy]
strict = true
files = 'src/diraccfg'

[tool.pylint."messages control"]
disable = ["unsubscriptable-object"]
11 changes: 7 additions & 4 deletions src/diraccfg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import annotations

import argparse
import json
import os
import sys
from typing import NoReturn

from .cfg import CFG
from .versions import parseVersion


def parseArgs():
def parseArgs() -> NoReturn:
parser = argparse.ArgumentParser(description="Parser for DIRAC cfg files")
subparsers = parser.add_subparsers(help="Actions to run with the ")

Expand All @@ -27,15 +30,15 @@ def parseArgs():
sys.exit(0)


def dumpAsJson(cfgFilename):
def dumpAsJson(cfgFilename: str) -> None:
if not os.path.isfile(cfgFilename):
sys.stderr.write(f"ERROR: {cfgFilename} does not exist\n")
sys.exit(1)
res = CFG().loadFromFile(cfgFilename)
print(json.dumps(res.getAsDict()))


def sortVersions(allow_pre_releases=False):
def sortVersions(allow_pre_releases: bool = False) -> None:
try:
objs = json.loads(sys.stdin.read())
except getattr(json, "JSONDecodeError", ValueError):
Expand All @@ -56,7 +59,7 @@ def sortVersions(allow_pre_releases=False):
continue
parsedVersions[obj] = (major, minor, patch, pre)

print(json.dumps(sorted(parsedVersions, key=parsedVersions.get, reverse=True)))
print(json.dumps(sorted(parsedVersions, key=parsedVersions.__getitem__, reverse=True)))


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit bc2a42a

Please sign in to comment.