Skip to content

Commit 4e01692

Browse files
committed
update style/syntax (mostly line length)
- renamed disabled files instead of commenting them out (and added header)
1 parent 8b68a55 commit 4e01692

35 files changed

+1924
-1141
lines changed

cc_licenses/settings/base.py

+33-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1212
# SETTINGS_DIR is where this settings file is
1313
SETTINGS_DIR = os.path.dirname(os.path.abspath(__file__))
14-
# PROJECT_DIR is the directory under root that contains the settings directory, urls.py, and other global stuff.
14+
# PROJECT_DIR is the directory under root that contains the settings directory,
15+
# urls.py, and other global stuff.
1516
PROJECT_DIR = os.path.dirname(SETTINGS_DIR)
1617
# ROOT_DIR is the top directory under source control
1718
ROOT_DIR = os.path.dirname(PROJECT_DIR)
@@ -92,7 +93,9 @@
9293
LOGGING = {
9394
"version": 1,
9495
"disable_existing_loggers": False,
95-
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
96+
"filters": {
97+
"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}
98+
},
9699
"formatters": {
97100
"basic": {
98101
"format": "%(asctime)s %(name)-20s %(levelname)-8s %(message)s",
@@ -202,22 +205,33 @@
202205
# https://docs.djangoproject.com/en/1.9/topics/auth/passwords/#password-validation
203206
AUTH_PASSWORD_VALIDATORS = [
204207
{
205-
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
208+
"NAME": (
209+
"django.contrib.auth."
210+
"password_validation.UserAttributeSimilarityValidator"
211+
),
206212
},
207213
{
208-
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
214+
"NAME": (
215+
"django.contrib.auth.password_validation.MinimumLengthValidator"
216+
),
209217
},
210218
{
211-
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
219+
"NAME": (
220+
"django.contrib.auth."
221+
"password_validation.CommonPasswordValidator"
222+
),
212223
},
213224
{
214-
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
225+
"NAME": (
226+
"django.contrib.auth."
227+
"password_validation.NumericPasswordValidator"
228+
),
215229
},
216230
]
217231

218232
# Make things more secure by default. Run "python manage.py check --deploy"
219-
# for even more suggestions that you might want to add to the settings, depending
220-
# on how the site uses SSL.
233+
# for even more suggestions that you might want to add to the settings,
234+
# depending on how the site uses SSL.
221235
SECURE_CONTENT_TYPE_NOSNIFF = True
222236
SECURE_BROWSER_XSS_FILTER = True
223237
CSRF_COOKIE_HTTPONLY = True
@@ -244,17 +258,20 @@
244258
# Percent translated that languages should be at or above
245259
TRANSLATION_THRESHOLD = 80
246260

247-
# Location of the translation data's repo. Look in env for TRANSLATION_REPOSITORY_DIRECTORY.
261+
# Location of the translation data's repo. Look in env for
262+
# TRANSLATION_REPOSITORY_DIRECTORY.
248263
# Default is next to this one.
249264
TRANSLATION_REPOSITORY_DIRECTORY = os.getenv(
250-
"TRANSLATION_REPOSITORY_DIRECTORY", os.path.join(ROOT_DIR, "..", "cc-licenses-data")
265+
"TRANSLATION_REPOSITORY_DIRECTORY",
266+
os.path.join(ROOT_DIR, "..", "cc-licenses-data"),
251267
)
252268

253269
# django-distill settings
254270
DISTILL_DIR = f"{TRANSLATION_REPOSITORY_DIRECTORY}/build/"
255271

256272
# Django translations are in the translation repo directory, under "locale".
257-
# License translations are in the translation repo directory, under "translations".
273+
# License translations are in the translation repo directory, under
274+
# "translations".
258275
LOCALE_PATHS = (
259276
os.path.join(TRANSLATION_REPOSITORY_DIRECTORY, "locale"),
260277
os.path.join(TRANSLATION_REPOSITORY_DIRECTORY, "legalcode"),
@@ -266,8 +283,11 @@
266283
"API_TOKEN": os.getenv("TRANSIFEX_API_TOKEN", "missing"),
267284
}
268285

269-
# The git branch where the official, approved, used in production translations are.
286+
# The git branch where the official, approved, used in production translations
287+
# are.
270288
OFFICIAL_GIT_BRANCH = "develop"
271289

272290
# Path to private keyfile to use when pushing up to data repo
273-
TRANSLATION_REPOSITORY_DEPLOY_KEY = os.getenv("TRANSLATION_REPOSITORY_DEPLOY_KEY", "")
291+
TRANSLATION_REPOSITORY_DEPLOY_KEY = os.getenv(
292+
"TRANSLATION_REPOSITORY_DEPLOY_KEY", ""
293+
)

cc_licenses/settings/deploy.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848

4949
# Simplified static file serving.
5050
# https://warehouse.python.org/project/whitenoise/
51-
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
51+
STATICFILES_STORAGE = (
52+
"whitenoise.storage.CompressedManifestStaticFilesStorage"
53+
)
5254

5355
else:
5456
SECRET_KEY = os.environ["SECRET_KEY"]
@@ -81,7 +83,9 @@
8183
EMAIL_SUBJECT_PREFIX = os.getenv(
8284
"EMAIL_SUBJECT_PREFIX", "[CC-Licenses %s] " % ENVIRONMENT.title()
8385
)
84-
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "noreply@%(DOMAIN)s" % os.environ)
86+
DEFAULT_FROM_EMAIL = os.getenv(
87+
"DEFAULT_FROM_EMAIL", "noreply@%(DOMAIN)s" % os.environ
88+
)
8589
SERVER_EMAIL = DEFAULT_FROM_EMAIL
8690

8791
CSRF_COOKIE_SECURE = True
@@ -99,7 +103,9 @@
99103
if backend["BACKEND"] == "django.template.backends.django.DjangoTemplates":
100104
default_loaders = ["django.template.loaders.filesystem.Loader"]
101105
if backend.get("APP_DIRS", False):
102-
default_loaders.append("django.template.loaders.app_directories.Loader")
106+
default_loaders.append(
107+
"django.template.loaders.app_directories.Loader"
108+
)
103109
# Django gets annoyed if you both set APP_DIRS True and specify your own loaders
104110
backend["APP_DIRS"] = False
105111
loaders = backend["OPTIONS"].get("loaders", default_loaders)

cc_licenses/wsgi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
if "DATABASE_URL" in os.environ:
1717
# Dokku or similar
18-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cc_licenses.settings.deploy")
18+
os.environ.setdefault(
19+
"DJANGO_SETTINGS_MODULE", "cc_licenses.settings.deploy"
20+
)
1921
else:
2022
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cc_licenses.settings")
2123

docs/conf.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
# html_logo = None
139139

140140
# The name of an image file (relative to this directory) to use as a favicon of
141-
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
142-
# pixels large.
141+
# the docs. This file should be a Windows icon file (.ico) being 16x16 or
142+
# 32x32 pixels large.
143143
# html_favicon = None
144144

145145
# Add any paths that contain custom static files (such as style sheets) here,
@@ -261,7 +261,9 @@
261261

262262
# One entry per manual page. List of tuples
263263
# (source start file, name, description, authors, manual section).
264-
man_pages = [(master_doc, "cc_licenses", "Cc_Licenses Documentation", [author], 1)]
264+
man_pages = [
265+
(master_doc, "cc_licenses", "Cc_Licenses Documentation", [author], 1)
266+
]
265267

266268
# If true, show URL addresses after external links.
267269
# man_show_urls = False

i18n/__init__.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88

99
logger = logging.getLogger(__name__)
1010

11-
CSV_HEADERS = ["lang", "num_messages", "num_trans", "num_fuzzy", "percent_trans"]
11+
CSV_HEADERS = [
12+
"lang",
13+
"num_messages",
14+
"num_trans",
15+
"num_fuzzy",
16+
"percent_trans",
17+
]
1218
DEFAULT_INPUT_DIR = settings.LOCALE_PATHS[0]
1319
DEFAULT_CSV_FILE = os.path.join(DEFAULT_INPUT_DIR, "transstats.csv")
1420
# If something has no language listed, that generally means it's English.
@@ -21,9 +27,10 @@
2127
# The language codes here are CC language codes, which sometimes differ from
2228
# Django language codes.
2329
DEFAULT_JURISDICTION_LANGUAGES = {
24-
# Map jurisdiction code to language code. IMPORTANT: Some of the jurisdiction codes
25-
# look like language codes, but they're not necessarily related. E.g. "ar" is the
26-
# language code for Arabic, but the jurisdiction code for Argentina.
30+
# Map jurisdiction code to language code. IMPORTANT: Some of the
31+
# jurisdiction codes look like language codes, but they're not necessarily
32+
# related. E.g. "ar" is the language code for Arabic, but the jurisdiction
33+
# code for Argentina.
2734
# See the "JURISDICTION_NAMES", just below this.
2835
"am": "hy", # Armenian - not in jurisdictions.rdf
2936
"ar": "es",
@@ -52,7 +59,7 @@
5259
# YES https://creativecommons.org/licenses/by/3.0/ch/legalcode.de
5360
"ch": "de", # ch=Switzerland, default in jurisdictions.rdf=de
5461
"cl": "es",
55-
"cn": "zh-Hans", # "cn" is China Mainland, language is simplified Chinese = zh-Hans
62+
"cn": "zh-Hans", # "cn" is China Mainland, language is simplified Chinese
5663
"co": "es",
5764
"cr": "es",
5865
"cz": "cs",
@@ -64,7 +71,8 @@
6471
# For "es", jurisdictions.rdf says "es-es".
6572
# Deed https://creativecommons.org/licenses/by/3.0/es/ is valid
6673
# NOT https://creativecommons.org/licenses/by/3.0/es/legalcode
67-
# License https://creativecommons.org/licenses/by/3.0/es/legalcode.es is valid
74+
# License https://creativecommons.org/licenses/by/3.0/es/legalcode.es is
75+
# valid
6876
# NOT https://creativecommons.org/licenses/by/3.0/es/legalcode.es-es
6977
# BUT the filename is by-nc-nd_3.0_es_es ????
7078
"es": "es",

i18n/management/commands/transstats.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def gen_statistics(input_dir, output_file):
6060
"num_messages": len(pofile),
6161
"num_trans": translated,
6262
"num_fuzzy": fuzzies,
63-
"percent_trans": int((float(translated) / len(pofile)) * 100),
63+
"percent_trans": int(
64+
(float(translated) / len(pofile)) * 100
65+
),
6466
}
6567
)
6668

@@ -73,7 +75,8 @@ def add_arguments(self, parser):
7375
"-i",
7476
"--input_dir",
7577
dest="input_dir",
76-
help="Directory to search for .po files to generate statistics on.",
78+
help="Directory to search for .po files to generate statistics"
79+
" on.",
7780
default=DEFAULT_INPUT_DIR,
7881
)
7982
parser.add_argument(

i18n/tests/test_utils.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
from django.test import TestCase, override_settings
88

99
# First-party/Local
10-
from i18n.utils import get_translation_object, save_content_as_pofile_and_mofile
10+
from i18n.utils import (
11+
get_translation_object,
12+
save_content_as_pofile_and_mofile,
13+
)
1114

1215
TEST_POFILE = os.path.join(
13-
os.path.dirname(__file__), "locales", "es_test_4.0", "LC_MESSAGES", "test-4.0.po"
16+
os.path.dirname(__file__),
17+
"locales",
18+
"es_test_4.0",
19+
"LC_MESSAGES",
20+
"test-4.0.po",
1421
)
1522

1623

@@ -26,7 +33,9 @@ def test_get_translation_object(self):
2633
django_language_code="code", domain="cnn.com"
2734
)
2835
mock_djt.assert_called_with(
29-
domain="cnn.com", language="code", localedirs=["/foo/bar/translations"]
36+
domain="cnn.com",
37+
language="code",
38+
localedirs=["/foo/bar/translations"],
3039
)
3140
mock_trans.assert_called_with("code")
3241
self.assertEqual(translation_object, result)
@@ -39,7 +48,9 @@ def test_save_content_as_pofile_and_mofile(self):
3948
with mock.patch("i18n.utils.polib") as mock_polib:
4049
return_value = save_content_as_pofile_and_mofile(path, content)
4150
self.assertEqual(("/foo/bar.po", "/foo/bar.mo"), return_value)
42-
mock_polib.pofile.assert_called_with(pofile=content.decode(), encoding="utf-8")
51+
mock_polib.pofile.assert_called_with(
52+
pofile=content.decode(), encoding="utf-8"
53+
)
4354
pofile = mock_polib.pofile.return_value
4455
pofile.save.assert_called_with(path)
4556
pofile.save_as_mofile.assert_called_with("/foo/bar.mo")

i18n/tests/tests.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def test_rtl_context_stuff(self):
6868
# )
6969
# # Alphabetized
7070
# self.assertEqual(
71-
# [{"code": "en", "name": "English"}, {"code": "fr", "name": "français"}],
71+
# [
72+
# {"code": "en", "name": "English"},
73+
# {"code": "fr", "name": "français"},
74+
# ],
7275
# result,
7376
# )
7477

@@ -89,7 +92,9 @@ def test_ugettext_for_locale(self):
8992
#
9093
# with self.subTest("Uses cached result"):
9194
# CACHED_TRANS_STATS["unused filename"] = "ding dong"
92-
# self.assertEqual("ding dong", get_all_trans_stats("unused filename"))
95+
# self.assertEqual(
96+
# "ding dong", get_all_trans_stats("unused filename")
97+
# )
9398
# CACHED_TRANS_STATS.clear()
9499
#
95100
# with self.subTest("Nonexistent file raises exception"):
@@ -154,6 +159,10 @@ def test_locale_to_lower_upper(self):
154159

155160
def test_get_language_for_jurisdiction(self):
156161
# 'be' default is "fr"
157-
self.assertEqual("fr", get_default_language_for_jurisdiction("be", "ar"))
162+
self.assertEqual(
163+
"fr", get_default_language_for_jurisdiction("be", "ar")
164+
)
158165
# There is none for "xx" so we return the default instead
159-
self.assertEqual("ar", get_default_language_for_jurisdiction("xx", "ar"))
166+
self.assertEqual(
167+
"ar", get_default_language_for_jurisdiction("xx", "ar")
168+
)

i18n/utils.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
# Return list of locale names under our locale dir.
3434
# """
3535
# dir = settings.LOCALE_PATHS[0]
36-
# return [item for item in os.listdir(dir) if os.path.isdir(os.path.join(dir, item))]
36+
# return [
37+
# item for item in os.listdir(dir)
38+
# if os.path.isdir(os.path.join(dir, item))
39+
# ]
3740

3841

3942
LANGUAGE_JURISDICTION_MAPPING = {}
@@ -78,10 +81,12 @@ def get_translation_object(
7881
)
7982
# Start with a translation object for the domain for this license.
8083
license_translation_object = DjangoTranslation(
81-
language=django_language_code, domain=domain, localedirs=[license_locale_dir]
84+
language=django_language_code,
85+
domain=domain,
86+
localedirs=[license_locale_dir],
8287
)
83-
# Add a fallback to the standard Django translation for this language. This gets us the
84-
# non-legalcode parts of the pages.
88+
# Add a fallback to the standard Django translation for this language. This
89+
# gets us the non-legalcode parts of the pages.
8590
license_translation_object.add_fallback(translation(django_language_code))
8691

8792
return license_translation_object
@@ -170,7 +175,9 @@ def get_default_language_for_jurisdiction(
170175
):
171176
# Input: a jurisdiction code
172177
# Output: a CC language code
173-
return DEFAULT_JURISDICTION_LANGUAGES.get(jurisdiction_code, default_language)
178+
return DEFAULT_JURISDICTION_LANGUAGES.get(
179+
jurisdiction_code, default_language
180+
)
174181

175182

176183
def get_locale_text_orientation(locale_identifier: str) -> str:
@@ -180,7 +187,9 @@ def get_locale_text_orientation(locale_identifier: str) -> str:
180187
try:
181188
locale = Locale.parse(locale_identifier, sep="-")
182189
except UnknownLocaleError:
183-
raise ValueError("No locale found with identifier %r" % locale_identifier)
190+
raise ValueError(
191+
"No locale found with identifier %r" % locale_identifier
192+
)
184193
return "ltr" if locale.character_order == "left-to-right" else "rtl"
185194

186195

@@ -313,7 +322,8 @@ def _wrapped_ugettext(message):
313322
#
314323
# if not os.path.exists(trans_file):
315324
# raise IOError(
316-
# f"No such CSV file {trans_file}. Maybe run `python manage.py transstats`?"
325+
# f"No such CSV file {trans_file}. Maybe run"
326+
# " `python manage.py transstats`?"
317327
# )
318328
#
319329
# reader = csv.DictReader(open(trans_file, "r"), CSV_HEADERS)

licenses/bs_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def name_and_text(tag: Tag):
6565
6666
E.g. "<strong>Truck</strong> is a <strong>heavy</strong> vehicle."
6767
68-
Returns a dictionary {"name": "Truck", "text": "is a <strong>heavy</strong> vehicle."}
68+
Returns a dictionary:
69+
{"name": "Truck", "text": "is a <strong>heavy</strong> vehicle."}
6970
"""
7071
top_level_children = list(tag.children)
7172

0 commit comments

Comments
 (0)