Skip to content

Commit

Permalink
This commit has had black (https://github.com/psf/black), the autof…
Browse files Browse the repository at this point in the history
…ormatter, run on the `wagtailflags` package and `setup.py`

It also adds `black --check` to the `tox` `lint` environment and adds a section in `CONTRIBUTING.md` about code style and tools.
  • Loading branch information
cwdavies committed Mar 30, 2020
1 parent 78ed1f9 commit 5b1458b
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 327 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ tests that validate implemented features and the presence or lack of defects.
Additionally, the code should follow any stylistic and architectural guidelines
prescribed by the project. In the absence of such guidelines, mimic the styles
and patterns in the existing code-base.


## Style

This project uses [`black`](https://github.com/psf/black) to format code,
[`isort`](https://github.com/timothycrosley/isort) to format imports,
and [`flake8`](https://gitlab.com/pycqa/flake8).

You can format code and imports by calling:

```
black wagtailflags
isort --recursive wagtailflags
```

And you can check for style, import order, and other linting by using:

```
tox -e lint
```
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tool.black]
line-length = 79
target-version = ['py36', 'py38']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs
| \.git
| \.tox
| \*.egg-info
| _build
| build
| dist
| migrations
| site
| \*.json
| \*.csv
)/
)
'''

[build-system]
requires = ["setuptools", "wheel"]
58 changes: 24 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
from setuptools import find_packages, setup

install_requires = ["wagtail>=2.3,<2.9", "django-flags>=4.2,<5.0"]

long_description = open('README.md', 'r').read()

install_requires = [
'wagtail>=2.3,<2.9',
'django-flags>=4.2,<5.0'
]

testing_extras = [
'coverage>=3.7.0',
]
testing_extras = ["coverage>=3.7.0"]

setup(
name='wagtail-flags',
url='https://github.com/cfpb/wagtail-flags',
author='CFPB',
author_email='tech@cfpb.gov',
description='Feature flags for Wagtail sites',
long_description=long_description,
long_description_content_type='text/markdown',
license='CC0',
version='4.2.0',
name="wagtail-flags",
url="https://github.com/cfpb/wagtail-flags",
author="CFPB",
author_email="tech@cfpb.gov",
description="Feature flags for Wagtail sites",
long_description=open("README.md", "r").read(),
long_description_content_type="text/markdown",
license="CC0",
version="4.2.0",
include_package_data=True,
packages=find_packages(),
install_requires=install_requires,
extras_require={
'testing': testing_extras,
},
extras_require={"testing": testing_extras},
classifiers=[
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Wagtail',
'Framework :: Wagtail :: 2',
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
'License :: Public Domain',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
]
"Framework :: Django",
"Framework :: Django :: 1.11",
"Framework :: Django :: 2.0",
"Framework :: Django :: 2.1",
"Framework :: Django :: 2.2",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"License :: Public Domain",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
],
)
13 changes: 9 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ deps=
[testenv:lint]
basepython=python3.6
deps=
flake8>=2.2.0
isort>=4.2.15
black
flake8
isort
commands=
black --check wagtailflags setup.py
flake8 .
isort --check-only --diff --recursive wagtailflags

[flake8]
ignore=E731,W503,W504
exclude=
.git,
.tox,
__pycache__

__pycache__,
node_modules,
*/migrations/*.py,
.eggs/*,

[isort]
combine_as_imports=1
Expand Down
2 changes: 1 addition & 1 deletion wagtailflags/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'wagtailflags.apps.WagtailFlagsAppConfig'
default_app_config = "wagtailflags.apps.WagtailFlagsAppConfig"
4 changes: 2 additions & 2 deletions wagtailflags/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class WagtailFlagsAppConfig(AppConfig):
name = 'wagtailflags'
verbose_name = 'Wagtail Flags'
name = "wagtailflags"
verbose_name = "Wagtail Flags"

def ready(self):
# Import custom conditions to ensure that they get registered.
Expand Down
19 changes: 10 additions & 9 deletions wagtailflags/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
from flags.conditions import RequiredForCondition, register


@register('site')
@register("site")
def site_condition(site_str, request=None, **kwargs):
""" Does the requests's Wagtail Site match the given site?
site_str should be 'hostname:port', or 'hostname [default]'. """
if request is None:
raise RequiredForCondition("request is required for condition "
"'site'")
raise RequiredForCondition(
"request is required for condition " "'site'"
)

Site = apps.get_model('wagtailcore.Site')
Site = apps.get_model("wagtailcore.Site")

if '[default]' in site_str:
if "[default]" in site_str:
# Wagtail Sites on the default port have [default] at the end of
# their str() form.
site_str = site_str.replace(' [default]', ':80')
elif ':' not in site_str:
site_str = site_str.replace(" [default]", ":80")
elif ":" not in site_str:
# Add a default port if one isn't given
site_str += ':80'
site_str += ":80"

hostname, port = site_str.split(':')
hostname, port = site_str.split(":")
try:
conditional_site = Site.objects.get(hostname=hostname, port=port)
except ObjectDoesNotExist:
Expand Down
42 changes: 16 additions & 26 deletions wagtailflags/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@


class NewFlagForm(forms.ModelForm):
name = forms.CharField(
label='Name',
required=True
)
name = forms.CharField(label="Name", required=True)

def clean_name(self):
name = self.cleaned_data['name']
name = self.cleaned_data["name"]
if name in get_flags():
raise forms.ValidationError(
"Flag named {} already exists".format(name)
Expand All @@ -21,46 +18,39 @@ def clean_name(self):

def save(self, commit=True):
obj = super(NewFlagForm, self).save(commit=False)
obj.condition = 'boolean'
obj.value = 'False'
obj.condition = "boolean"
obj.value = "False"
obj.required = False
obj.save()
return obj

class Meta:
model = FlagState
fields = ('name', )
fields = ("name",)


class FlagStateForm(forms.ModelForm):
name = forms.CharField(
label='Flag',
required=True,
disabled=True,
widget=forms.HiddenInput(),
)
condition = forms.ChoiceField(
label='Condition',
required=True
)
value = forms.CharField(
label='Expected value',
required=True
label="Flag", required=True, disabled=True, widget=forms.HiddenInput(),
)
condition = forms.ChoiceField(label="Condition", required=True)
value = forms.CharField(label="Expected value", required=True)
required = forms.BooleanField(
label='Required',
label="Required",
required=False,
help_text=('All conditions marked "required" must be met to enable '
'the flag'),
help_text=(
'All conditions marked "required" must be met to enable '
"the flag"
),
)

def __init__(self, *args, **kwargs):
super(FlagStateForm, self).__init__(*args, **kwargs)

self.fields['condition'].choices = [
(c, c) for c in sorted(get_conditions()) if c != 'boolean'
self.fields["condition"].choices = [
(c, c) for c in sorted(get_conditions()) if c != "boolean"
]

class Meta:
model = FlagState
fields = ('name', 'condition', 'value', 'required')
fields = ("name", "condition", "value", "required")
18 changes: 6 additions & 12 deletions wagtailflags/templatetags/wagtailflags_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@

@register.filter
def enablable(flag):
return (
not any(
c.required for c in flag.conditions if c.condition == 'boolean'
)
and not bool_enabled(flag)
)
return not any(
c.required for c in flag.conditions if c.condition == "boolean"
) and not bool_enabled(flag)


@register.filter
def disablable(flag):
return (
not any(
c.required for c in flag.conditions if c.condition == 'boolean'
)
and bool_enabled(flag)
)
return not any(
c.required for c in flag.conditions if c.condition == "boolean"
) and bool_enabled(flag)
Loading

0 comments on commit 5b1458b

Please sign in to comment.