Skip to content

Commit

Permalink
Merge pull request #6 from edx/cpappas/quality-fixes
Browse files Browse the repository at this point in the history
quality fixes including installation of six, docstring stuff, and pii…
  • Loading branch information
christopappas authored Mar 6, 2019
2 parents 712bcf6 + 1d54e26 commit 7996061
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .annotation_safe_list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a Code Annotations automatically-generated Django model safelist file.
# These models must be annotated as follows in order to be counted in the coverage report.
# See https://code-annotations.readthedocs.io/en/latest/safelist.html for more information.
#
# fake_app_1.FakeModelName:
# ".. no_pii:": "This model has no PII"
# fake_app_2.FakeModel2:
# ".. choice_annotation:": foo, bar, baz
23 changes: 23 additions & 0 deletions .pii_annotations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
source_path: ./
report_path: pii_report
safelist_path: .annotation_safe_list.yml

# Local models are all fully annotated, but non-local models are not annotated
# because this repo does not contain an IDA/Django project (which, according to
# our own PII annotating policy, doesn't require non-local annotations). 75%
# coverage represents all local models, and is the current theoretical maximum
# coverage.
# TODO: PLAT-2422
coverage_target: 0

annotations:
".. no_pii:":
"pii_group":
- ".. pii:":
- ".. pii_types:":
choices: [id, name, username, email_address, other]
- ".. pii_retirement:":
choices: [retained, local_api, consumer_api, third_party]
extensions:
python:
- py
6 changes: 3 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Change Log
.. There should always be an "Unreleased" section for changes pending release.
Unreleased
~~~~~~~~~~
[0.1.2] - 2019-03-06
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

*
* Quality fixes

[0.1.1] - 2019-03-06
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ test: clean ## run tests in the current virtualenv
diff_cover: test ## find diff lines that need test coverage
diff-cover coverage.xml

test-all: quality pii_check ## run tests on every supported Python/Django combination
# Removed pii_check from test-all, because there are no concrete models present in package
test-all: quality ## run tests on every supported Python/Django combination
tox

validate: quality pii_check test ## run tests and quality checks
# Removed pii_check from validate, because there are no concrete models present in package
validate: quality test ## run tests and quality checks

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
Expand Down
2 changes: 1 addition & 1 deletion edx_rbac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.1.1'
__version__ = '0.1.2'

default_app_config = 'edx_rbac.apps.EdxRbacConfig' # pylint: disable=invalid-name
27 changes: 20 additions & 7 deletions edx_rbac/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
from django.contrib.auth.models import User
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.fields import FieldDoesNotExist
from django.utils.encoding import python_2_unicode_compatible
from model_utils.models import TimeStampedModel
from django.db.models.fields import FieldDoesNotExist
from six import with_metaclass


class UserRoleAssignmentCreator(ModelBase):
"""
The model extending UserRoleAssignment should get a foreign key to a model that is a subclass of UserRole.
"""

def __new__(cls, name, bases, attrs):
model = super(UserRoleAssignmentCreator, cls).__new__(cls, name, bases, attrs)
def __new__(mcs, name, bases, attrs):
"""
Override to dynamically create foreign key for objects begotten from abstract class.
"""
model = super(UserRoleAssignmentCreator, mcs).__new__(mcs, name, bases, attrs)
for b in bases:
if b.__name__ == 'UserRoleAssignment' and model.__name__ != b.__name__:
try:
Expand All @@ -40,11 +44,16 @@ def __new__(cls, name, bases, attrs):
@python_2_unicode_compatible
class UserRole(TimeStampedModel):
"""
Model defining a role a user can have
Model defining a role a user can have.
"""

name = models.CharField(unique=True, max_length=255, db_index=True)

class Meta:
"""
Meta class for UserRole.
"""

abstract = True

def __str__(self):
Expand All @@ -55,15 +64,19 @@ def __str__(self):


@python_2_unicode_compatible
class UserRoleAssignment(TimeStampedModel):
class UserRoleAssignment(with_metaclass(UserRoleAssignmentCreator, TimeStampedModel)):
"""
Model for mapping users and their roles
Model for mapping users and their roles.
"""
__metaclass__ = UserRoleAssignmentCreator

user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE)
role_class = None

class Meta:
"""
Meta class for UserRoleAssignment.
"""

abstract = True

def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings')
sys.path.append(PWD)
try:
from django.core.management import execute_from_command_line # pylint: disable=wrong-import-position
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # pylint: disable=unused-import, wrong-import-position
import django # pylint: disable=unused-import
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

Django>=1.8,<2.0 # Web application framework
django-model-utils # Provides TimeStampedModel abstract base class
six
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
django-model-utils==3.1.2
django==1.11.20
pytz==2018.9 # via django
six==1.12.0
14 changes: 8 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
argparse==1.4.0
astroid==1.5.3
atomicwrites==1.3.0
attrs==18.2.0
attrs==19.1.0
backports.functools-lru-cache==1.5
caniusepython3==7.0.0
certifi==2018.11.29
chardet==3.0.4
click-log==0.1.8
click==7.0
code-annotations==0.2.4
code-annotations==0.3
codecov==2.0.15
configparser==3.7.3
contextlib2==0.5.5 # via importlib-metadata
Expand All @@ -28,15 +28,15 @@ edx-lint==1.1.1
enum34==1.1.6
filelock==3.0.10
funcsigs==1.0.2
futures==3.2.0
futures==3.1.1
idna==2.8
importlib-metadata==0.8 # via path.py
inflect==2.1.0 # via jinja2-pluralize
isort==4.3.9
isort==4.3.12
jinja2-pluralize==0.3.0 # via diff-cover
jinja2==2.10 # via diff-cover, jinja2-pluralize
jinja2==2.10
lazy-object-proxy==1.3.1
markupsafe==1.1.1 # via jinja2
markupsafe==1.1.1
mccabe==0.6.1
more-itertools==5.0.0
packaging==19.0
Expand All @@ -58,6 +58,7 @@ pyparsing==2.3.1
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.0
python-slugify==3.0.0
pytz==2018.9
pyyaml==3.13
requests==2.21.0
Expand All @@ -66,6 +67,7 @@ singledispatch==3.4.0.3
six==1.12.0
snowballstemmer==1.2.1
stevedore==1.30.1
text-unidecode==1.2
toml==0.10.0
tox-battery==0.5.1
tox==3.7.0
Expand Down
10 changes: 6 additions & 4 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#
alabaster==0.7.12 # via sphinx
atomicwrites==1.3.0
attrs==18.2.0
attrs==19.1.0
babel==2.6.0 # via sphinx
bleach==3.1.0 # via readme-renderer
certifi==2018.11.29 # via requests
chardet==3.0.4 # via doc8, requests
click==7.0
code-annotations==0.2.4
code-annotations==0.3
coverage==4.5.2
django-model-utils==3.1.2
django==1.11.20
Expand All @@ -22,8 +22,8 @@ edx-sphinx-theme==1.4.0
funcsigs==1.0.2
idna==2.8 # via requests
imagesize==1.1.0 # via sphinx
jinja2==2.10 # via sphinx
markupsafe==1.1.1 # via jinja2
jinja2==2.10
markupsafe==1.1.1
more-itertools==5.0.0
packaging==19.0 # via sphinx
pathlib2==2.3.3
Expand All @@ -35,6 +35,7 @@ pyparsing==2.3.1 # via packaging
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.0
python-slugify==3.0.0
pytz==2018.9
pyyaml==3.13
readme-renderer==24.0
Expand All @@ -46,6 +47,7 @@ snowballstemmer==1.2.1 # via sphinx
sphinx==1.8.4
sphinxcontrib-websupport==1.1.0 # via sphinx
stevedore==1.30.1
text-unidecode==1.2
typing==3.6.6 # via sphinx
urllib3==1.24.1 # via requests
webencodings==0.5.1 # via bleach
1 change: 1 addition & 0 deletions requirements/quality.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edx-lint # edX pylint rules and plugins
isort # to standardize order of imports
pycodestyle # PEP 8 compliance validation
pydocstyle # PEP 257 compliance validation
futures==3.1.1 # 3.2.0 breaks in py36, and shouldn't be required for py3 anyway. Pinning.
14 changes: 9 additions & 5 deletions requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
argparse==1.4.0 # via caniusepython3
astroid==1.5.3 # via edx-lint, pylint, pylint-celery
atomicwrites==1.3.0
attrs==18.2.0
backports.functools-lru-cache==1.5 # via astroid, caniusepython3, pylint
attrs==19.1.0
backports.functools-lru-cache==1.5 # via astroid, caniusepython3, isort, pylint
caniusepython3==7.0.0
certifi==2018.11.29 # via requests
chardet==3.0.4 # via requests
click-log==0.1.8 # via edx-lint
click==7.0
code-annotations==0.2.4
code-annotations==0.3
configparser==3.7.3 # via pydocstyle, pylint
coverage==4.5.2
distlib==0.2.8 # via caniusepython3
Expand All @@ -23,10 +23,12 @@ django==1.11.20
edx-lint==1.1.1
enum34==1.1.6 # via astroid
funcsigs==1.0.2
futures==3.2.0 # via caniusepython3, isort
futures==3.1.1
idna==2.8 # via requests
isort==4.3.9
isort==4.3.12
jinja2==2.10
lazy-object-proxy==1.3.1 # via astroid
markupsafe==1.1.1
mccabe==0.6.1 # via pylint
more-itertools==5.0.0
packaging==19.0 # via caniusepython3
Expand All @@ -44,6 +46,7 @@ pyparsing==2.3.1 # via packaging
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.0
python-slugify==3.0.0
pytz==2018.9
pyyaml==3.13
requests==2.21.0 # via caniusepython3
Expand All @@ -52,5 +55,6 @@ singledispatch==3.4.0.3 # via astroid, pylint
six==1.12.0
snowballstemmer==1.2.1 # via pydocstyle
stevedore==1.30.1
text-unidecode==1.2
urllib3==1.24.1 # via requests
wrapt==1.11.1 # via astroid
10 changes: 7 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# make upgrade
#
atomicwrites==1.3.0 # via pytest
attrs==18.2.0 # via pytest
attrs==19.1.0 # via pytest
click==7.0 # via code-annotations
code-annotations==0.2.4
code-annotations==0.3
coverage==4.5.2 # via pytest-cov
django-model-utils==3.1.2
funcsigs==1.0.2 # via pytest
jinja2==2.10 # via code-annotations
markupsafe==1.1.1 # via jinja2
more-itertools==5.0.0 # via pytest
pathlib2==2.3.3 # via pytest, pytest-django
pbr==5.1.3 # via stevedore
Expand All @@ -19,8 +21,10 @@ py==1.8.0 # via pytest
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.0 # via pytest-cov, pytest-django
python-slugify==3.0.0 # via code-annotations
pytz==2018.9
pyyaml==3.13 # via code-annotations
scandir==1.9.0 # via pathlib2
six==1.12.0 # via more-itertools, pathlib2, pytest, stevedore
six==1.12.0
stevedore==1.30.1 # via code-annotations
text-unidecode==1.2 # via python-slugify
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def is_requirement(line):
VERSION = get_version('edx_rbac', '__init__.py')

if sys.argv[-1] == 'tag':
print("Tagging the version on github:")
os.system("git tag -a %s -m 'version %s'" % (VERSION, VERSION))
os.system("git push --tags")
print(u"Tagging the version on github:")
os.system(u"git tag -a %s -m 'version %s'" % (VERSION, VERSION))
os.system(u"git push --tags")
sys.exit()

README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Expand Down

0 comments on commit 7996061

Please sign in to comment.