Skip to content

Commit

Permalink
Merge pull request #2 from maykinmedia/fix/#706-fixing-tox-tests
Browse files Browse the repository at this point in the history
Fix/#706 fixing tox tests
  • Loading branch information
alextreme authored Nov 24, 2023
2 parents c6b649e + 8c6e32b commit 1fe4136
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 217 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Tests and PyPI publishing

on:
push:
branches:
- master
tags:
- "*"
pull_request:
workflow_dispatch:

jobs:
tests:
name: Run tests Python ${{ matrix.python }}, Django ${{ matrix.django }})
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
django: ["3.2", "4.1", "4.2"]
exclude:
- python: "3.11"
django: "3.2"

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: pip install tox tox-gh-actions

- name: Run tests
run: tox
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.django }}

- name: Publish coverage report
uses: codecov/codecov-action@v3

publish:
name: Publish package to PyPI
runs-on: ubuntu-latest
needs:
- tests

if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Build sdist and wheel
run: |
pip install pip setuptools wheel --upgrade
python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Linting and code quality

on:
push:
branches:
- master
tags:
paths:
- '**.py'
- .github/workflows/code_quality.yml
pull_request:
paths:
- '**.py'
- .github/workflows/code_quality.yml
workflow_dispatch:

jobs:
linting:
name: Code-quality checks
runs-on: ubuntu-latest
strategy:
matrix:
toxenv:
- isort
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: pip install tox
- run: tox
env:
TOXENV: ${{ matrix.toxenv }}
53 changes: 0 additions & 53 deletions .github/workflows/release.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ cover/
htmlcov/
coverage.xml
.tox/
junit.xml
1 change: 0 additions & 1 deletion django_celery_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import absolute_import, unicode_literals

import re

from collections import namedtuple

__version__ = '1.1.2'
Expand Down
18 changes: 6 additions & 12 deletions django_celery_monitor/admin.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
"""Result Task Admin interface."""
from __future__ import absolute_import, unicode_literals

from __future__ import absolute_import, unicode_literals

# from celery.task.control import broadcast, revoke, rate_limit
from celery import Celery, current_app, states
from celery.utils.text import abbrtask
from django.contrib import admin
from django.contrib.admin import helpers
from django.contrib.admin.views import main as main_views
from django.shortcuts import render
from django.template import RequestContext
from django.utils.encoding import force_text
from django.utils.encoding import force_str as force_text
from django.utils.html import escape
from django.utils.translation import ugettext_lazy as _

from celery import current_app
from celery import states
# from celery.task.control import broadcast, revoke, rate_limit
from celery import Celery
from celery.utils.text import abbrtask
from django.utils.translation import gettext_lazy as _

from .models import TaskState, WorkerState
from .humanize import naturaldate
from .models import TaskState, WorkerState
from .utils import action, display_field, fixedwidth, make_aware


TASK_STATE_COLORS = {states.SUCCESS: 'green',
states.FAILURE: 'red',
states.REVOKED: 'magenta',
Expand Down
2 changes: 1 addition & 1 deletion django_celery_monitor/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, unicode_literals

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

__all__ = ['CeleryMonitorConfig']

Expand Down
2 changes: 1 addition & 1 deletion django_celery_monitor/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from celery.utils.log import get_logger
from celery.utils.time import maybe_iso8601

from .utils import fromtimestamp, correct_awareness
from .utils import correct_awareness, fromtimestamp

WORKER_UPDATE_FREQ = 60 # limit worker timestamp write freq.
SUCCESS_STATES = frozenset([states.SUCCESS])
Expand Down
17 changes: 9 additions & 8 deletions django_celery_monitor/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@

from datetime import datetime

from django.utils.translation import ungettext, ugettext as _
from django.utils.timezone import now
from django.utils.translation import gettext as _
from django.utils.translation import ngettext


def pluralize_year(n):
"""Return a string with the number of yeargs ago."""
return ungettext(_('{num} year ago'), _('{num} years ago'), n)
return ngettext(_('{num} year ago'), _('{num} years ago'), n)


def pluralize_month(n):
"""Return a string with the number of months ago."""
return ungettext(_('{num} month ago'), _('{num} months ago'), n)
return ngettext(_('{num} month ago'), _('{num} months ago'), n)


def pluralize_week(n):
"""Return a string with the number of weeks ago."""
return ungettext(_('{num} week ago'), _('{num} weeks ago'), n)
return ngettext(_('{num} week ago'), _('{num} weeks ago'), n)


def pluralize_day(n):
"""Return a string with the number of days ago."""
return ungettext(_('{num} day ago'), _('{num} days ago'), n)
return ngettext(_('{num} day ago'), _('{num} days ago'), n)


OLDER_CHUNKS = (
Expand Down Expand Up @@ -57,19 +58,19 @@ def naturaldate(date, include_seconds=False):
if days == 0:
if hours == 0:
if minutes > 0:
return ungettext(
return ngettext(
_('{minutes} minute ago'),
_('{minutes} minutes ago'), minutes
).format(minutes=minutes)
else:
if include_seconds and seconds:
return ungettext(
return ngettext(
_('{seconds} second ago'),
_('{seconds} seconds ago'), seconds
).format(seconds=seconds)
return _('just now')
else:
return ungettext(
return ngettext(
_('{hours} hour ago'), _('{hours} hours ago'), hours
).format(hours=hours)

Expand Down
27 changes: 2 additions & 25 deletions django_celery_monitor/managers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The model managers."""
from __future__ import absolute_import, unicode_literals

from datetime import timedelta

from celery import states
Expand All @@ -14,31 +15,7 @@ class ExtendedQuerySet(models.QuerySet):
"""A custom model queryset that implements a few helpful methods."""

def select_for_update_or_create(self, defaults=None, **kwargs):
"""Extend update_or_create with select_for_update.
Look up an object with the given kwargs, updating one with defaults
if it exists, otherwise create a new one.
Return a tuple (object, created), where created is a boolean
specifying whether an object was created.
This is a backport from Django 1.11
(https://code.djangoproject.com/ticket/26804) to support
select_for_update when getting the object.
"""
defaults = defaults or {}
lookup, params = self._extract_model_params(defaults, **kwargs)
self._for_write = True
with transaction.atomic(using=self.db):
try:
obj = self.select_for_update().get(**lookup)
except self.model.DoesNotExist:
obj, created = self._create_object_from_params(lookup, params)
if created:
return obj, created
for k, v in defaults.items():
setattr(obj, k, v() if callable(v) else v)
obj.save(using=self.db)
return obj, False
return self.update_or_create(defaults, **kwargs)


class WorkerStateQuerySet(ExtendedQuerySet):
Expand Down
4 changes: 2 additions & 2 deletions django_celery_monitor/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from __future__ import absolute_import, unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
Loading

0 comments on commit 1fe4136

Please sign in to comment.