Skip to content

Commit

Permalink
Merge pull request ColtonProvias#65 from deryckh/4_0_8_deryck_take_3
Browse files Browse the repository at this point in the history
Make it possible to get at __version__ within code.
  • Loading branch information
Anderycks authored Apr 7, 2017
2 parents e7b8e23 + 4366cbf commit d11b300
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ target/
pyvenv.cfg
pip-selfcheck.json

# Editors
*.swp
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
requirements = ['SQLAlchemy', 'inflection']

if sys.version_info[0] != 3 or sys.version_info[1] < 4:
requirements.append('enum34')
requirements.append('enum34')

# XXX: deryck (2016 April 6) __version__ is defined twice.
# __version__ is defined here and in sqlalchemy_jsonapi.__version__
# but we can't import it since __init__ imports literally everything.
# The constants and serializer files depend on enum34 which has to be
# conditionally installed. Once we stop supporting Python 2.7,
# this version string can also be imported as sqlalchemy_jsonapi.__version__.
__version__ = '4.0.9'

setup(name='SQLAlchemy-JSONAPI',
version='4.0.9',
version=__version__,
url='http://github.com/coltonprovias/sqlalchemy-jsonapi',
license='MIT',
author='Colton J. Provias',
Expand Down
1 change: 1 addition & 0 deletions sqlalchemy_jsonapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ALL_PERMISSIONS, INTERACTIVE_PERMISSIONS, JSONAPI, AttributeActions,
Permissions, RelationshipActions, attr_descriptor, permission_test,
relationship_descriptor)
from ._version import __version__ # NOQA

try:
from .flaskext import FlaskJSONAPI
Expand Down
1 change: 1 addition & 0 deletions sqlalchemy_jsonapi/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '4.0.9'
5 changes: 4 additions & 1 deletion sqlalchemy_jsonapi/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
from uuid import uuid4

# Relative import here is to avoid circular import in setup.py.
from ._version import __version__


class BaseError(Exception):
@property
Expand Down Expand Up @@ -160,7 +163,7 @@ def user_error(status_code, title, detail, pointer):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
return json.dumps(response), status_code
9 changes: 7 additions & 2 deletions sqlalchemy_jsonapi/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
Colton J. Provias
MIT License
"""
from enum import Enum

try:
from enum import Enum
except ImportError:
from enum34 import Enum

from inflection import dasherize, tableize, underscore
from sqlalchemy.exc import IntegrityError
Expand All @@ -16,6 +20,7 @@
RelationshipNotFoundError, ResourceNotFoundError,
ResourceTypeNotFoundError, ToManyExpectedError,
ValidationError)
from ._version import __version__


class AttributeActions(Enum):
Expand Down Expand Up @@ -139,7 +144,7 @@ def __init__(self):
self.status_code = 200
self.data = {
'jsonapi': {'version': '1.0'},
'meta': {'sqlalchemy_jsonapi_version': '4.0.9'}
'meta': {'sqlalchemy_jsonapi_version': __version__}
}


Expand Down
3 changes: 2 additions & 1 deletion sqlalchemy_jsonapi/unittests/test_errors_user_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

from sqlalchemy_jsonapi import errors
from sqlalchemy_jsonapi import __version__


class TestUserError(unittest.TestCase):
Expand All @@ -30,7 +31,7 @@ def test_user_error(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
expected = json.dumps(data), status_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class DeleteResource(testcases.SqlalchemyJsonapiTestCase):
Expand All @@ -22,7 +23,7 @@ def test_delete_resource_successs_response(self):

expected = {
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'jsonapi': {
'version': '1.0'
Expand Down
25 changes: 13 additions & 12 deletions sqlalchemy_jsonapi/unittests/test_serializer_get_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class GetCollection(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_get_collection_response_with_no_query_args(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': []
}
Expand Down Expand Up @@ -141,7 +142,7 @@ def test_get_collection_response_with_single_include_model(self):
}
}],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'jsonapi': {
'version': '1.0'
Expand Down Expand Up @@ -217,7 +218,7 @@ def test_get_collection_asc_sorted_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': []
}
Expand Down Expand Up @@ -291,7 +292,7 @@ def test_get_collection_desc_sorted_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': []
}
Expand Down Expand Up @@ -360,7 +361,7 @@ def test_get_collection_access_denied(self):
'data': [],
'included': [],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'jsonapi': {
'version': '1.0'
Expand Down Expand Up @@ -435,7 +436,7 @@ def test_get_collection_paginated_response_by_page(self):
}],
'included': [],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'jsonapi': {
'version': '1.0'
Expand Down Expand Up @@ -475,7 +476,7 @@ def test_get_collection_with_single_field(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -558,7 +559,7 @@ def test_get_collection_when_including_model_and_its_attribute(self):
}
}],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'data': [{
'id': 1,
Expand Down Expand Up @@ -636,7 +637,7 @@ def test_get_collection_given_an_included_model_that_is_null(self):
}
}],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': []
}
Expand Down Expand Up @@ -748,7 +749,7 @@ def test_get_collection_with_multiple_included_models(self):
}
}],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -781,7 +782,7 @@ def test_get_collection_given_pagination_with_offset(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': [],
'data': [{
Expand Down Expand Up @@ -913,7 +914,7 @@ def test_get_collection_when_pagnation_is_out_of_range(self):
'data': [],
'included': [],
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'jsonapi': {
'version': '1.0'
Expand Down
7 changes: 4 additions & 3 deletions sqlalchemy_jsonapi/unittests/test_serializer_get_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class GetRelated(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -67,7 +68,7 @@ def test_get_related_of_to_one(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_get_related_of_to_many(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -195,7 +196,7 @@ def test_get_related_when_related_object_is_null(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class GetRelationship(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -41,7 +42,7 @@ def test_get_relationship_on_to_many(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}

Expand Down Expand Up @@ -73,7 +74,7 @@ def test_get_relationship_on_to_one(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class GPatchRelationship(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_patch_relationship_on_to_one_set_to_resource_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -102,7 +103,7 @@ def test_patch_relationship_on_to_one_set_resource_to_null_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -167,7 +168,7 @@ def test_patch_relationship_on_to_many_set_resources_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -234,7 +235,7 @@ def test_patch_relationship_on_to_many_set_to_empty_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class PatchResource(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -103,7 +104,7 @@ def test_patch_resource_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models
from sqlalchemy_jsonapi import __version__


class PostCollection(testcases.SqlalchemyJsonapiTestCase):
Expand Down Expand Up @@ -88,7 +89,7 @@ def test_add_resource_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}

Expand Down Expand Up @@ -190,7 +191,7 @@ def test_add_resource_with_many_to_one_relationship_response(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
}
}
actual = response.data
Expand Down Expand Up @@ -567,7 +568,7 @@ def test_add_resource_with_a_null_relationship(self):
'version': '1.0'
},
'meta': {
'sqlalchemy_jsonapi_version': '4.0.9'
'sqlalchemy_jsonapi_version': __version__
},
'included': []
}
Expand Down
Loading

0 comments on commit d11b300

Please sign in to comment.