Skip to content
Draft
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
33 changes: 12 additions & 21 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -35,13 +35,10 @@ jobs:
mongosh --version

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
run: uv sync --all-extras --dev

- name: Test with tox
run: poetry run tox -e ${{ matrix.toxenv }}
run: uv run tox -e ${{ matrix.toxenv }}

lint:
runs-on: ubuntu-latest
Expand All @@ -50,23 +47,19 @@ jobs:
python-version: ['3.10']
toxenv: [black, isort, lint]


steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
run: uv sync --all-extras --dev

- name: Tests with tox
run: poetry run tox -e ${{ matrix.toxenv }}
run: uv run tox -e ${{ matrix.toxenv }}

test-generate-docs:
runs-on: ubuntu-latest
Expand All @@ -77,17 +70,15 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-get install pandoc
python -m pip install --upgrade pip
pip install poetry
poetry install
uv sync --all-extras --dev

- name: Tests doc generation
run: poetry run sphinx-build -b html docs/ docs/_build
run: uv run sphinx-build -b html docs/ docs/_build
4,736 changes: 0 additions & 4,736 deletions poetry.lock

This file was deleted.

135 changes: 75 additions & 60 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,87 +1,102 @@
[tool.poetry]

[project]
authors = [{ name = "Mila-IDT" }]
requires-python = "<4.0,>=3.10"
dependencies = [
"fabric<4.0.0,>=3.0.0",
"prometheus-api-client<1.0.0,>=0.5.2",
"pydantic<2.0.0,>=1.10.4",
"pydantic-mongo<2.0.0,>=1.0.1",
"pymongo<5.0.0,>=4.3.3",
"numpy<2.0.0,>=1.24.0",
"ldap3<3.0.0,>=2.9.1",
"python-hostlist<2.0.0,>=1.23.0",
"tqdm<5.0.0,>=4.64.1",
"flatten-dict<1.0.0,>=0.4.2",
"simple-parsing<1.0.0,>=0.1.0",
"sphinx<7.0.0,>=6.2.1",
"myst-parser<3.0.0,>=2.0.0",
"sphinx-rtd-theme<2.0.0,>=1.2.2",
"nbsphinx<1.0.0,>=0.9.3",
"opentelemetry-api<2.0.0,>=1.23.0",
"opentelemetry-sdk<2.0.0,>=1.23.0",
"requests-mock<2.0.0,>=1.11.0",
"gifnoc==0.4.1",
"watchdog<5.0.0,>=4.0.0",
"python-dateutil<3.0.0.0,>=2.9.0.post0",
"pandas>=2.2.3",
"starbear[server]>=0.2.8",
"plotnine>=0.14.5",
"griptape[all]>=0.20.0",
]
name = "sarc"
version = "0.1.0"
description = "Surveillance et analyse des ressources de calcul"
authors = ["Mila-IDT"]
readme = "README.md"
packages = [{include = 'sarc'}]

[tool.poetry.dependencies]
python = "^3.9"
fabric = "^3.0.0"
prometheus-api-client = "^0.5.2"
pydantic = "^1.10.4"
pydantic-mongo = "^1.0.1"
pymongo = "^4.3.3"
numpy = "^1.24.0"
ldap3 = "^2.9.1"
python-hostlist = "^1.23.0"
tqdm = "^4.64.1"
flatten-dict = "^0.4.2"
simple-parsing = "^0.1.0"
sphinx = "^6.2.1"
myst-parser = "^2.0.0"
sphinx-rtd-theme = "^1.2.2"
nbsphinx = "^0.9.3"
opentelemetry-api = "^1.23.0"
opentelemetry-sdk = "^1.23.0"
requests-mock = "^1.11.0"
pandas = "< 2.1.0"
gifnoc = "^0.2.3"
watchdog = "^4.0.0"
python-dateutil = "^2.9.0.post0"

[tool.poetry.group.dev.dependencies]
black = ">= 22.12.0"
pylint = ">= 2.15.10"
isort = ">= 5.11.4"
mypy = ">= 0.991"
pytest = ">= 7.2.1"
pytest-cov = ">= 4.0.0"
pytest-regressions = ">= 2.4.2"
tox = ">= 4.4.5"
pytest-freezegun = ">= 0.4.2"
fabric = {extras = ["testing"], version = "^3.0.0"}
pytest-timeout = "^2.1.0"
pytest-custom-exit-code = ">= 0.3.0"
coverage = "^7.2.7"
pytest-xdist = "^3.3.1"
jupyter = "^1.0.0"
tabulate = "^0.9.0"

[tool.poetry.group.examples.dependencies]
seaborn = "^0.12.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.scripts]
sarc = 'sarc.cli:main'
[tool.hatch.build.targets.wheel]
packages = ["sarc"]

[tool.pytest]
norecursedirs = "tests/common"

[tool.pylint]
ignore-paths = []
disable = [
"no-self-argument", # Pydantic validators don't have one
"too-few-public-methods", # Triggered on Pydantic models
"import-outside-toplevel", # These imports are useful to reduce loading times
"no-self-argument", # Pydantic validators don't have one
"too-few-public-methods", # Triggered on Pydantic models
"import-outside-toplevel", # These imports are useful to reduce loading times
"too-many-arguments",
"too-many-locals",
"too-many-positional-arguments",
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring",
"invalid-name",
"no-else-return", # Bad rule IMO (- OB)
"line-too-long", # Black takes care of line length.
"no-else-return", # Bad rule IMO (- OB)
"line-too-long", # Black takes care of line length.
"logging-fstring-interpolation",
"duplicate-code",
"too-many-positional-arguments",
]
extension-pkg-whitelist = "pydantic"

[tool.isort]
profile = "black"
[tool.ruff.lint]
extend-select = ["I"]

[tool.ruff.lint.isort]
combine-as-imports = true

[project.scripts]
sarc = "sarc.cli:main"

[project.optional-dependencies]
examples = [
"rich>=13.9.4",
"seaborn>=0.13.2",
]

[dependency-groups]
dev = [
"black>=22.12.0",
"pylint>=2.15.10",
"isort>=5.11.4",
"mypy>=0.991",
"pytest>=7.2.1",
"pytest-cov>=4.0.0",
"pytest-regressions>=2.4.2",
"tox>=4.4.5",
"pytest-freezegun>=0.4.2",
"fabric[testing]<4.0.0,>=3.0.0",
"pytest-timeout<3.0.0,>=2.1.0",
"pytest-custom-exit-code>=0.3.0",
"coverage<8.0.0,>=7.2.7",
"pytest-xdist<4.0.0,>=3.3.1",
"jupyter<2.0.0,>=1.0.0",
"tabulate<1.0.0,>=0.9.0",
]
examples = ["seaborn<1.0.0,>=0.12.2"]
56 changes: 5 additions & 51 deletions sarc/alerts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
from typing import Optional, Union

import gifnoc
from apischema import ValidationError, deserialize, deserializer, serialize, serializer
from dateutil import parser as dateparser
from apischema import deserialize, serialize
from gifnoc import TaggedSubclass
from gifnoc.std import time

# load custom serializing logic
from ..common import utils # noqa: F401


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -252,55 +255,6 @@ def __call__(self, write=True):
return results


@serializer
def _serialize_timedelta(td: timedelta) -> str:
"""Serialize timedelta as Xs (seconds) or Xus (microseconds)."""
seconds = int(td.total_seconds())
if td.microseconds:
return f"{seconds}{td.microseconds:06}us"
else:
return f"{seconds}s"


@deserializer
def _deserialize_timedelta(s: str) -> timedelta:
"""Deserialize a combination of days, hours, etc. as a timedelta."""
units = {
"d": "days",
"h": "hours",
"m": "minutes",
"s": "seconds",
"ms": "milliseconds",
"us": "microseconds",
}
sign = 1
if s.startswith("-"):
s = s[1:]
sign = -1
kw = {}
parts = re.split(string=s, pattern="([a-z ]+)")
if parts[-1] != "":
raise ValidationError("timedelta representation must end with a unit")
for i in range(len(parts) // 2):
n = parts[i * 2]
unit = parts[i * 2 + 1].strip()
if unit not in units:
raise ValidationError(f"'{unit}' is not a valid timedelta unit")
try:
kw[units[unit]] = float(n)
except ValueError as err:
raise ValidationError(
f"Could not convert '{n}' ({units[unit]}) to float"
) from err
return sign * timedelta(**kw)


@deserializer
def _deserialize_date(s: str) -> datetime:
"""This is mostly so that things work with Python <3.11."""
return dateparser.parse(s)


@dataclass
class HealthMonitorConfig:
# Root directory for check results
Expand Down
Empty file added sarc/app/__init__.py
Empty file.
Loading
Loading