← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas-kpi:rework-project-setup into ~maas-committers/maas-kpi/+git/maas-kpi:master

 

Alberto Donato has proposed merging ~ack/maas-kpi:rework-project-setup into ~maas-committers/maas-kpi/+git/maas-kpi:master.

Commit message:
rework setup to use tox, move to pyproject.toml



Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~ack/maas-kpi/+git/maas-kpi/+merge/441776
-- 
Your team MAAS Committers is requested to review the proposed merge of ~ack/maas-kpi:rework-project-setup into ~maas-committers/maas-kpi/+git/maas-kpi:master.
diff --git a/Makefile b/Makefile
index 824b67f..fb1f794 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ INFLUXDB_DBNAME ?= maas
 SWIFT_KEY ?= swift.key
 export DATASOURCE ?= maas-influxdb.cloud.kpi.internal
 
-VIRTUALENV := .ve
+VIRTUALENV := .tox/apps
 GENERATED := generated
 
 define DASHBOARDS
@@ -16,31 +16,31 @@ define DASHBOARDS
 	team.json
 endef
 
-.DEFAULT_GOAL := setup
+.DEFAULT_GOAL := dashboards
 
-setup: clean py-dep
-.PHONY: setup
+deps:
+	sudo apt-get -y install gcc libpython3-dev libffi-dev tox
+.PHONY: deps
 
-clean: py-clean
+clean:
 	rm -rf $(GENERATED)
+	rm -rf .tox *.egg-info
 .PHONY: clean
 
-format: py-format
+format lint:
+	tox run -e $@
 .PHONY: format
 
-lint: py-lint
-.PHONY: lint
-
-check: py-check
-.PHONY: check
-
 $(GENERATED):
 	mkdir $(GENERATED)
 
+$(VIRTUALENV):
+	tox run -e apps
+
 dashboards: $(addprefix $(GENERATED)/, $(DASHBOARDS))
 .PHONY: dashboards
 
-$(GENERATED)/%.json : grafana/%.dashboard.py | $(GENERATED)
+$(GENERATED)/%.json : grafana/%.dashboard.py | $(GENERATED) $(VIRTUALENV)
 	$(VIRTUALENV)/bin/generate-dashboard -o $@ $<
 
 # snap metrics are different - they need a store macaroon, not LP credentials
@@ -56,7 +56,6 @@ $(GENERATED)/bugs.metrics: | $(GENERATED) $(VIRTUALENV)
 metrics: $(GENERATED)/bugs.metrics $(GENERATED)/dailystats.metrics
 .PHONY: metrics
 
-
 # The push target needs the PUSH_GATEWAY variable to be defined.
 push: $(GENERATED)/bugs.metrics $(GENERATED)/dailystats.metrics | $(VIRTUALENV)
 	for metric in $^ ; do \
@@ -64,52 +63,3 @@ push: $(GENERATED)/bugs.metrics $(GENERATED)/dailystats.metrics | $(VIRTUALENV)
 		$(VIRTUALENV)/bin/push-metrics --db $(INFLUXDB_DBNAME) --credentials $(INFLUXDB_CREDENTIALS) $(INFLUXDB_HOST) $$metric ; \
 	done
 .PHONY: push
-
-deb-dep:
-	sudo apt-get -y install gcc python3-venv libpython3-dev libffi-dev
-
-# Python targets
-
-PY_FILES := setup.py maaskpi grafana
-
-py-dep: py-dep-app
-	$(VIRTUALENV)/bin/pip install -e .[dev]
-.PHONY: py-dep
-
-py-dep-app: $(VIRTUALENV)
-	$(VIRTUALENV)/bin/pip install -r requirements.txt -e .
-.PHONY: py-dep-app
-
-$(VIRTUALENV)/.dev-bin:
-	$(MAKE) py-dep
-	touch $@
-
-py-clean:
-	rm -rf $(VIRTUALENV) maaskpi.egg-info
-.PHONY: py-clean
-
-py-format: $(VIRTUALENV)/.dev-bin
-	@$(VIRTUALENV)/bin/isort --profile black $(PY_FILES)
-	@$(VIRTUALENV)/bin/black $(PY_FILES)
-.PHONY: py-format
-
-py-lint: $(VIRTUALENV)/.dev-bin
-	@$(VIRTUALENV)/bin/isort --profile black --check-only --diff $(PY_FILES)
-	@$(VIRTUALENV)/bin/black -q --check $(PY_FILES)
-	@$(VIRTUALENV)/bin/flake8 $(PY_FILES)
-.PHONY: py-lint
-
-py-freeze: VENV := .freeze_ve
-py-freeze: PIP := $(VENV)/bin/pip
-py-freeze:
-	rm -rf $(VENV)
-	python3 -m venv $(VENV)
-	$(PIP) install .
-	$(PIP) freeze | grep -E -v '^(pkg-resources|maaskpi)' > requirements.txt
-	rm -rf $(VENV)
-.PHONY: py-freeze
-
-
-$(VIRTUALENV):
-	python3 -m venv $@
-	$(VIRTUALENV)/bin/pip install wheel
diff --git a/README.md b/README.md
index f8f9490..20663da 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@ imported into a Grafana instance.
 
 ## Setup
 
-To set things up, you need to have `make` and `python3-venv` installed.
-Next, run `make` which will set up the Python venv in `.ve`.
+To set things up, you need to have `make` installed.  Next, run `make deps`
+which will install dependencies.
 
 
 ## Prometheus metrics
@@ -24,14 +24,12 @@ run `make push`.
 
 ### Adding new metrics
 
-If you need to add new metrics, you can either add it to an existing
-collector, or create a completely new one. You can look in `setup.cfg`
-to see which ones are already there. Any script that starts with
-`maaskip-` is a collector.
+If you need to add new metrics, you can either add it to an existing collector,
+or create a completely new one. You can look in `pyproject.toml` to see which
+ones are already there. Any script that starts with `maaskip-` is a collector.
 
-If you need to create a new one, create a new class based on the
-`Collector` class and add an entry in `setup.cfg` pointing to its
-`run()` method.
+If you need to create a new one, create a new class based on the `Collector`
+class and add an entry in `pyproject.toml` pointing to its `run()` method.
 
 You also need to edit the `metrics` target in `Makefile` to include the
 new metrics file.
diff --git a/grafana/machine-listing-spike.dashboard.py b/grafana/machine-listing-spike.dashboard.py
index 9b331a6..655e854 100644
--- a/grafana/machine-listing-spike.dashboard.py
+++ b/grafana/machine-listing-spike.dashboard.py
@@ -4,10 +4,10 @@
 from textwrap import dedent
 from typing import NamedTuple
 
+from grafanalib import formatunits as UNITS
 from grafanalib.core import (
     INDIVIDUAL,
     NULL_AS_ZERO,
-    SECONDS_FORMAT,
     SORT_DESC,
     Annotations,
     Dashboard,
@@ -19,7 +19,6 @@ from grafanalib.core import (
     YAxes,
     YAxis,
 )
-from grafanalib import formatunits as UNITS
 
 from maaskpi.grafana import Graph, InfluxDBTarget, Tag, TagField, get_datasource
 
@@ -158,7 +157,7 @@ def create_rows():
 
 def create_annotations():
     query = dedent(
-        f"""\
+        """\
         SELECT "duration", "revision", "dataset"
         FROM maas_ci_perf..testcase
         WHERE "dataset" =~ /^$dataset/
diff --git a/maaskpi/grafana.py b/maaskpi/grafana.py
index ea98731..5659492 100644
--- a/maaskpi/grafana.py
+++ b/maaskpi/grafana.py
@@ -20,7 +20,6 @@ TIME_SERIES_TARGET_FORMAT = "time_series"
 
 @attr.s
 class InfluxDBTarget(object):
-
     select = attr.ib(default=None)
     format = attr.ib(default=TIME_SERIES_TARGET_FORMAT)
     measurement = attr.ib(default="")
@@ -52,7 +51,6 @@ class InfluxDBTarget(object):
 
 @attr.s
 class Select(object):
-
     items = attr.ib(default=attr.Factory(list))
 
     def to_json_data(self):
@@ -64,7 +62,6 @@ class Select(object):
 
 @attr.s
 class Field(object):
-
     name = attr.ib(default="")
 
     def to_json_data(self):
@@ -73,7 +70,6 @@ class Field(object):
 
 @attr.s
 class TagField(object):
-
     name = attr.ib(default="")
 
     def to_json_data(self):
@@ -82,7 +78,6 @@ class TagField(object):
 
 @attr.s
 class Tag(object):
-
     key = attr.ib()
     operator = attr.ib()
     value = attr.ib()
@@ -97,7 +92,6 @@ class Tag(object):
 
 @attr.s
 class Time(object):
-
     interval = attr.ib(default="$__interval")
 
     def to_json_data(self):
@@ -116,7 +110,6 @@ class Sum(object):
 
 @attr.s
 class Alias(object):
-
     name = attr.ib()
 
     def to_json_data(self):
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..b413de7
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,37 @@
+[build-system]
+build-backend = "setuptools.build_meta"
+requires = [
+  "setuptools",
+]
+
+[project]
+name = "maaskpi"
+version = "1.0"
+description = "Collect MAAS project KPIs"
+readme = "README.md"
+dependencies = [
+  "attr",
+  "grafanalib",
+  "influxdb",
+  "launchpadlib",
+  "prometheus-client",
+  "pymacaroons",
+  "python-keystoneclient",
+  "python-swiftclient",
+  "requests",
+]
+[project.scripts]
+maaskpi-bugs = "maaskpi.bugs:run"
+maaskpi-dailystats = "maaskpi.dailystats:run"
+maaskpi-snap = "maaskpi.snap:run"
+prometheus-export = "maaskpi.prometheus:prometheus_export"
+push-metrics = "maaskpi.influxdb:push_metrics"
+
+[tool.setuptools.packages.find]
+include = ["maaskpi*"]
+
+[tool.isort]
+profile = "black"
+
+[tool.flake8]
+ignore = ["E203", "E266", "E501", "W503"]
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index 6732010..0000000
--- a/setup.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
-[metadata]
-name = maaskpi
-version = 1.0
-description = Collect MAAS project KPIs
-long_description = file: README.md
-
-[options]
-zip_safe = true
-packages = find:
-install_requires =
-    attr
-    grafanalib
-    influxdb
-    launchpadlib
-    pymacaroons
-    python-keystoneclient
-    python-swiftclient
-    prometheus-client
-    requests
-
-[options.extras_require]
-dev =
-    black
-    flake8
-    isort>=5.0.0
-
-[options.entry_points]
-console_scripts =
-    maaskpi-bugs = maaskpi.bugs:run
-    maaskpi-snap = maaskpi.snap:run
-    maaskpi-dailystats = maaskpi.dailystats:run
-    push-metrics = maaskpi.influxdb:push_metrics
-    prometheus-export = maaskpi.prometheus:prometheus_export
-
-[flake8]
-ignore = E203, E266, E501, W503
diff --git a/setup.py b/setup.py
deleted file mode 100644
index 6068493..0000000
--- a/setup.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from setuptools import setup
-
-setup()
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..4d98fad
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,41 @@
+[tox]
+requires =
+    tox>=4.2
+no_package = true
+
+[testenv:format]
+deps =
+    {[deps]lint}
+commands =
+    isort {[files]lint}
+    black -q {[files]lint}
+    - pyproject-fmt pyproject.toml
+    - tox-ini-fmt tox.ini
+
+[testenv:lint]
+deps =
+    {[deps]lint}
+commands =
+    isort --check-only --diff {[files]lint}
+    black --check {[files]lint}
+    flake8 {[files]lint}
+    pyproject-fmt --check pyproject.toml
+
+[testenv:apps]
+deps =
+    -e .
+    -r requirements.txt
+
+[files]
+lint =
+    grafana \
+    maaskpi
+
+[deps]
+lint =
+    black
+    flake8
+    flake8-pyproject
+    isort
+    pyproject-fmt
+    tox-ini-fmt

Follow ups