Skip to content

Commit

Permalink
Remove version.py
Browse files Browse the repository at this point in the history
It should be more reliable to put the version in our pyproject file and
then use importlib.metadata when we want to read the package version.

We add a settings.PROMGEN_VERSION as a convenience internally for getting
the version number.
  • Loading branch information
kfdm committed Feb 13, 2024
1 parent 0e497e7 commit d0c2e2f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import django
django.setup()

from promgen.version import __version__
from django.conf import settings


# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -67,9 +67,9 @@
# built documents.
#
# The short X.Y version.
version = __version__
version = settings.PROMGEN_VERSION
# The full version, including alpha/beta/rc tags.
release = __version__
release = settings.PROMGEN_VERSION

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
5 changes: 3 additions & 2 deletions promgen/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# These sources are released under the terms of the MIT license: see LICENSE

from promgen import models, util
from promgen.version import __version__

from django.conf import settings


def settings_in_view(request):
return {
"TIMEZONE": util.setting("timezone", "UTC"),
"VERSION": __version__,
"VERSION": settings.PROMGEN_VERSION,
"DEFAULT_EXPORTERS": models.DefaultExporter.objects.order_by("job", "-port"),
}
5 changes: 3 additions & 2 deletions promgen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import importlib.metadata
import os
import pathlib

Expand All @@ -23,11 +24,11 @@

from promgen import PROMGEN_CONFIG_FILE
from promgen.plugins import apps_from_setuptools
from promgen.version import __version__

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = pathlib.Path(__file__).parent.parent
DOT_ENV = BASE_DIR / ".env"
PROMGEN_VERSION = importlib.metadata.version("promgen")

# Load our environment
env = environ.Env()
Expand Down Expand Up @@ -177,7 +178,7 @@
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration

os.environ.setdefault("SENTRY_RELEASE", __version__)
os.environ.setdefault("SENTRY_RELEASE", PROMGEN_VERSION)
# By default we want to keep sentry's default of NOT sending user
# information, but in some environments, it's useful for debugging
# purposes so lets add a flag here that we can use.
Expand Down
3 changes: 1 addition & 2 deletions promgen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
from django.conf import settings
from django.db.models import F

from promgen.version import __version__

# Wrappers around request api to ensure we always attach our user agent
# https://github.com/requests/requests/blob/master/requests/api.py


USER_AGENT = f"promgen/{__version__}"
USER_AGENT = f"promgen/{settings.PROMGEN_VERSION}"
ACCEPT_HEADER = (
"application/openmetrics-text; version=0.0.1,text/plain;version=0.0.4;q=0.5,*/*;q=0.1"
)
Expand Down
1 change: 0 additions & 1 deletion promgen/version.py

This file was deleted.

4 changes: 2 additions & 2 deletions promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
signals,
tasks,
util,
version,
)
from promgen.shortcuts import resolve_domain

from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def collect(self):
v = GaugeMetricFamily(
"promgen_build_info", "Promgen Information", labels=["version", "python"]
)
v.add_metric([version.__version__, platform.python_version()], 1)
v.add_metric([settings.PROMGEN_VERSION, platform.python_version()], 1)
yield v

try:
Expand Down

0 comments on commit d0c2e2f

Please sign in to comment.