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

Add version to package #384

Merged
merged 2 commits into from
Nov 19, 2023
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
workflows: ["unit test"]
branches:
- main
- activitypub
types:
- completed

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN --mount=type=cache,sharing=locked,target=/var/cache/apt apt-get update \

COPY . /neodb

RUN echo neodb-`cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/version
RUN echo `cd /neodb && git rev-parse --short HEAD`-`cd /neodb/neodb-takahe && git rev-parse --short HEAD`-`date -u +%Y%m%d%H%M%S` > /neodb/build_version
RUN rm -rf /neodb/.git /neodb/neodb-takahe/.git

RUN mv /neodb/neodb-takahe /takahe
Expand Down
1 change: 1 addition & 0 deletions boofilsic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.9.0"
12 changes: 10 additions & 2 deletions boofilsic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import environ

NEODB_VERSION = "0.8"
from boofilsic import __version__

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

try:
with open(os.path.join(BASE_DIR, "build_version")) as f:
NEODB_VERSION = __version__ + "-" + f.read().strip()
except:
NEODB_VERSION = __version__ + "-dev"


# Parse configuration from:
# - environment variables
# - .env file in project root directory
# - /etc/neodb.conf
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
environ.Env.read_env("/etc/neodb.conf")
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))

Expand Down
17 changes: 11 additions & 6 deletions catalog/sites/igdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,34 @@

import requests
from django.conf import settings
from django.core.cache import cache
from igdb.wrapper import IGDBWrapper

from catalog.common import *
from catalog.models import *

_logger = logging.getLogger(__name__)
_cache_key = "igdb_access_token"


def _igdb_access_token():
if not settings.IGDB_CLIENT_SECRET:
return "<missing>"
try:
token = requests.post(
f"https://id.twitch.tv/oauth2/token?client_id={settings.IGDB_CLIENT_ID}&client_secret={settings.IGDB_CLIENT_SECRET}&grant_type=client_credentials"
).json()["access_token"]
token = cache.get(_cache_key)
if not token:
j = requests.post(
f"https://id.twitch.tv/oauth2/token?client_id={settings.IGDB_CLIENT_ID}&client_secret={settings.IGDB_CLIENT_SECRET}&grant_type=client_credentials"
).json()
token = j["access_token"]
ttl = j["expires_in"] - 60
cache.set(_cache_key, token, ttl)
except Exception:
_logger.error("unable to obtain IGDB token")
token = "<invalid>"
return token


_wrapper = IGDBWrapper(settings.IGDB_CLIENT_ID, _igdb_access_token())


def search_igdb_by_3p_url(steam_url):
r = IGDB.api_query("websites", f'fields *, game.*; where url = "{steam_url}";')
if not r:
Expand Down Expand Up @@ -63,6 +67,7 @@ def api_query(cls, p, q):
if get_mock_mode():
r = BasicDownloader(key).download().json()
else:
_wrapper = IGDBWrapper(settings.IGDB_CLIENT_ID, _igdb_access_token())
r = json.loads(_wrapper.api_request(p, q)) # type: ignore
if settings.DOWNLOADER_SAVEDIR:
with open(
Expand Down
3 changes: 0 additions & 3 deletions common/management/commands/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from django.core.management.base import BaseCommand
from loguru import logger

from catalog.jobs import * # noqa
from common.models import BaseJob, JobManager
from mastodon.jobs import * # noqa
from users.jobs import * # noqa

# @JobManager.register
# class DummyJob(BaseJob):
Expand Down
10 changes: 10 additions & 0 deletions common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ def run(cls, job_id):
def get_scheduled_job_ids(cls):
registry = ScheduledJobRegistry(queue=django_rq.get_queue("cron"))
return registry.get_job_ids()

@classmethod
def schedule_all(cls):
# TODO rewrite lazy import in a better way
from catalog.jobs import DiscoverGenerator, PodcastUpdater
from mastodon.jobs import MastodonSiteCheck
from users.jobs import MastodonUserSync

cls.cancel()
cls.schedule()
2 changes: 2 additions & 0 deletions common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from loguru import logger

from catalog.search.models import Indexer
from common.models import JobManager
from takahe.models import Config as TakaheConfig
from takahe.models import Domain as TakaheDomain
from takahe.models import Follow as TakaheFollow
Expand Down Expand Up @@ -151,5 +152,6 @@ def run(self):
Indexer.init()

# Register cron jobs if not yet
JobManager.schedule_all()

logger.info("Finished post-migration setup.")
4 changes: 2 additions & 2 deletions misc/bin/neodb-hello
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
echo '\033[0;35m====== Welcome to NeoDB ======\033[0m'
cat /neodb/version
echo '\033[0;35m====== NeoDB ======\033[0m'
echo Version: `neodb-version`
echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN}
[[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON, showing environment variables:
[[ -z "${NEODB_DEBUG}" ]] || env
Expand Down
9 changes: 3 additions & 6 deletions misc/bin/neodb-init
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/bin/sh
echo '\033[0;35m====== Welcome to NeoDB ======\033[0m'
cat /neodb/version
echo '\033[0;35m====== NeoDB ======\033[0m'
echo Version: `neodb-version`
echo Your configuration is for ${NEODB_SITE_NAME} on ${NEODB_SITE_DOMAIN}
[[ -z "${NEODB_DEBUG}" ]] || echo DEBUG is ON, show environment:
[[ -z "${NEODB_DEBUG}" ]] || env
echo

echo NeoDB initializing...

takahe-manage migrate || exit $?
neodb-manage migrate || exit $?
neodb-manage cron --schedule || exit $?

echo NeoDB initialization complete.
2 changes: 2 additions & 0 deletions misc/bin/neodb-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "from django.conf import settings; print(settings.NEODB_VERSION+(' debug:on' if settings.DEBUG else ''))" | neodb-manage shell