Skip to content

Commit

Permalink
fix: πŸ› version number according to PEP440
Browse files Browse the repository at this point in the history
- add: βž• docs build to tox.
  • Loading branch information
abhiabhi94 committed Mar 11, 2021
1 parent c6f7090 commit 709e6a0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 26 deletions.
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

23 changes: 9 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
# 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 os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import importlib

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


def get_version():
with open(os.path.join(BASE_DIR, 'VERSION')) as version_file:
version = version_file.read().strip()
return version
def get_version_and_release():
__version__ = importlib.import_module('flag').__version__
# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
return version, release


# -- Project information -----------------------------------------------------
Expand All @@ -29,11 +28,7 @@ def get_version():
copyright = '2020, Abhyudai'
author = 'Abhyudai'

# The short X.Y version
version = get_version()
# The full version, including alpha/beta/rc tags
release = get_version()

version, release = get_version_and_release()

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

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


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'
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ known_third_party = django, rest_framework
DJANGO_SETTINGS_MODULE = testapp.settings
# Standard pytest options
addopts = -p no:warnings --reuse-db
[build_sphinx]
source-dir = docs
build-dir = docs/_build
all_files = 1

[upload_sphinx]
upload-dir = docs/_build/html
23 changes: 12 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import codecs
import os
import setuptools

import importlib

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


def get_description():
with open(os.path.join(BASE_DIR, 'README.rst')) as fh:
description = fh.read().strip()
return description
def get_version(rel_path):
return importlib.import_module('flag').__version__


def get_version():
with open(os.path.join(BASE_DIR, 'VERSION')) as version_file:
version = version_file.read().strip()
return 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(),
version=get_version('flag/__init__.py'),
author='Abhyudai',
author_email='',
description='A pluggable django application that adds the ability for users to flag(or report) your models',
long_description=get_description(),
long_description=read('README.rst'),
url='https://github.com/abhiabhi94/django-flag-app',
project_urls={
'Documentation': 'https://django-flag-app.readthedocs.io',
Expand Down
12 changes: 12 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from flag import _get_version


class TestVersion:
@pytest.mark.parametrize(('version', 'result'), (
((1, 2, 3), ('1.2.3')), # with patch
((1, 2), ('1.2')), # without patch
))
def test_get_version(self, version, result):
assert _get_version((version)) == result
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ DJANGO =
3.1: dj31
main: djmain

[testenv:docs]
deps =
sphinx
sphinx_rtd_theme
commands =
python setup.py build_sphinx

[testenv]
deps =
flake8
Expand Down

0 comments on commit 709e6a0

Please sign in to comment.