Skip to content

Commit

Permalink
fix: 🐛 default_app_config warnings for django>=3.2
Browse files Browse the repository at this point in the history
- move `setup.py` metadata to `setup.cfg`.
    - this means the `__version__` string is no longer available. To use the installed versions, you may use `importlib.metadata.version['django_flag_app']`

- add `pyproject.toml`.
- add `pre-commit`.
- add some useful bash scripts.
- remove release workflow(I have trust issues with Github).
- reduce package size by removing tests, documentation and other potentially unnecessary stuff.
  • Loading branch information
abhiabhi94 committed May 1, 2021
1 parent 509b3d5 commit e160921
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 140 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/release.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
- repo: https://github.com/mgedmin/check-manifest
rev: "0.46"
hooks:
- id: check-manifest
args: [--no-build-isolation]
- repo: https://github.com/PyCQA/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.7.0
hooks:
- id: rst-backticks
6 changes: 6 additions & 0 deletions .scripts/generate_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/bash
set -euxo pipefail

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u abhiabhi94 -p django-flag-app
pandoc -o CHANGELOG.rst CHANGELOG.md
rm CHANGELOG.md
18 changes: 18 additions & 0 deletions .scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/bash

set -euxo pipefail

echo "----------Releasing $(python setup.py --version) --------------"

echo -e "\n------------- Upgrading dependecies ---------------------\n"
python -m pip install -U pip
python -m pip install -U setuptools twine wheel

echo -e "\n------------- Building Package -----------------------\n"
python setup.py sdist bdist_wheel

echo -e "\n------------- Verifying Package ----------------------\n"
twine check dist/*

echo -e "\n------------- Publishing Package ----------------------\n"
twine upload dist/*
22 changes: 16 additions & 6 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
recursive-include flag *.py
recursive-include flag/static *
recursive-include flag/templates *
recursive-include docs *
global-exclude *.py[cod]
prune __pycache__
include LICENSE
include README.rst
include tox.ini manage.py
recursive-include tests *.py
include pyproject.toml
include CHANGELOG.rst
recursive-include flag/locale *
recursive-include flag/templates *
recursive-include flag/static *
prune testapp
prune tests
prune docs
prune .scripts
exclude tox.ini
exclude .pre-commit-config.yaml
exclude codecov.yml
exclude manage.py
exclude CONTRIBUTING.rst
23 changes: 14 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import sys
import os.path

# add flag to system path
sys.path.insert(0, os.path.abspath('..'))

PROJECT_ROOT = os.path.dirname(os.getcwd())


def _get_version_and_release():
with open(os.path.join(PROJECT_ROOT, 'setup.cfg'), 'r') as fp:
for line in fp:
if line.startswith('version = '):
version_line = line.strip()
break
else:
raise AssertionError('Version can not be determined')

def get_version_and_release():
import flag
__version__ = flag.__version__
# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
_, version = version_line.split(' = ')
# The full version, including alpha/beta/rc tags.
release = __version__
release = version
return version, release


Expand All @@ -33,7 +38,7 @@ def get_version_and_release():
copyright = '2020, Abhyudai'
author = 'Abhyudai'

version, release = get_version_and_release()
version, release = _get_version_and_release()

# -- General configuration ---------------------------------------------------

Expand Down
17 changes: 3 additions & 14 deletions flag/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
VERSION = (1, 1, 0)
import django


def _get_version(version):
if len(version) > 2:
str_version = "%s.%s.%s" % version[:3]
else:
str_version = "%s.%s" % version[:2]

return str_version


__version__ = _get_version(VERSION)


default_app_config = 'flag.apps.FlagConfig'
if django.VERSION < (3, 2):
default_app_config = 'flag.apps.FlagConfig'
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
60 changes: 52 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
[metadata]
name = django-flag-app
version = 1.0.1
author = Abhyudai
author_email =
description = A pluggable django application that adds the ability for users to flag(or report) your models
long_description = file: README.rst
long_description_content_type = 'text/x-rst'
url = https://github.com/abhiabhi94/django-flag-app
license = MIT
license_file = LICENSE
project_urls =
Documentation=https://django-flag-app.readthedocs.io
Source Code=https://github.com/abhiabhi94/django-flag-app
classifiers =
Environment :: Web Environment
Framework :: Django
Framework :: Django :: 2.1
Framework :: Django :: 2.2
Framework :: Django :: 3.0
Framework :: Django :: 3.1
Framework :: Django :: 3.2
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content
keywords = django flag report moderate

[options]
packages = find:
include_package_data = True
python_requires = >=3.6
install_requires = django
zip_safe = False

[options.packages.find]
exclude =
docs
test*

[flake8]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203, E231,

[isort]
Expand All @@ -12,13 +57,12 @@ known_third_party = django, rest_framework
branch = true

[tool:pytest]
DJANGO_SETTINGS_MODULE = testapp.settings
# Standard pytest options
addopts = -p
no:warnings
--reuse-db
--cov=flag
--cov-report term-missing:skip-covered
django_find_project = false
addopts = -p no:doctest
--ds=testapp.settings
--reuse-db
--cov=flag
--cov-report term-missing:skip-covered

[build_sphinx]
source-dir = docs
Expand Down
60 changes: 2 additions & 58 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,2 @@
import codecs
import os
import setuptools
import importlib

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


def get_version():
return importlib.import_module('flag').__version__


def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
# intentionally *not* adding an encoding option to open, See:
# https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
return fp.read()


setuptools.setup(
name='django-flag-app',
version=get_version(),
author='Abhyudai',
author_email='',
description='A pluggable django application that adds the ability for users to flag(or report) your models',
long_description=read('README.rst'),
url='https://github.com/abhiabhi94/django-flag-app',
project_urls={
'Documentation': 'https://django-flag-app.readthedocs.io',
'Source Code': 'https://github.com/abhiabhi94/django-flag-app',
},
packages=setuptools.find_packages(exclude=['docs', 'test*']),
include_package_data=True,
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
python_requires='>=3.6',
install_requires=['django'],
keywords='django flag report moderate',
zip_safe=False,
)
from setuptools import setup
setup()
15 changes: 15 additions & 0 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""This module aims to test the compatibility of the project with different django versions"""
import django
import pytest

import flag


class TestDefaultAppConfigDefinition:
@pytest.mark.skipif(django.VERSION < (3, 2), reason='app config is automatically defined by django')
def test_app_config_not_defined(self):
assert hasattr(flag, 'default_app_config') is False

@pytest.mark.skipif(django.VERSION >= (3, 2), reason='app config is not automatically defined by django')
def test_app_config_defined(self):
assert hasattr(flag, 'default_app_config') is True
12 changes: 0 additions & 12 deletions tests/test_version.py

This file was deleted.

0 comments on commit e160921

Please sign in to comment.