Merge ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:line-length-library into charm-k8s-ingress:master

Proposed by Tom Haddon
Status: Merged
Approved by: Jon Seager
Approved revision: ec6db29bf8ec86ded0e1224838a9f96839ee1471
Merged at revision: 2beb4a6e66ac2dc2842f5c6e627afdea18d9b8f2
Proposed branch: ~mthaddon/charm-k8s-ingress/+git/charm-k8s-ingress:line-length-library
Merge into: charm-k8s-ingress:master
Diff against target: 195 lines (+51/-19)
5 files modified
.flake8 (+1/-1)
lib/charms/nginx_ingress_integrator/v0/ingress.py (+26/-8)
src/charm.py (+11/-3)
tests/unit/test_charm.py (+11/-5)
tox.ini (+2/-2)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-is (community) continuous-integration Needs Fixing
ingress-charmers Pending
Review via email: mp+401861@code.launchpad.net

Commit message

Switch line length to 99 to match charmcraft defaults to make library imports less noisy for other projects

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-is (prod-jenkaas-is) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-is (prod-jenkaas-is) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2beb4a6e66ac2dc2842f5c6e627afdea18d9b8f2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.flake8 b/.flake8
2index 41512a8..8ef84fc 100644
3--- a/.flake8
4+++ b/.flake8
5@@ -1,5 +1,5 @@
6 [flake8]
7-max-line-length = 120
8+max-line-length = 99
9 select: E,W,F,C,N
10 exclude:
11 venv
12diff --git a/lib/charms/nginx_ingress_integrator/v0/ingress.py b/lib/charms/nginx_ingress_integrator/v0/ingress.py
13index 066b257..688a77c 100644
14--- a/lib/charms/nginx_ingress_integrator/v0/ingress.py
15+++ b/lib/charms/nginx_ingress_integrator/v0/ingress.py
16@@ -19,7 +19,8 @@ Import `IngressRequires` in your charm, with two required options:
17 - session-cookie-max-age
18 - tls-secret-name
19
20-See [the config section](https://charmhub.io/nginx-ingress-integrator/configure) for descriptions of each, along with the required type.
21+See [the config section](https://charmhub.io/nginx-ingress-integrator/configure) for descriptions
22+of each, along with the required type.
23
24 As an example, add the following to `src/charm.py`:
25 ```
26@@ -55,7 +56,7 @@ LIBAPI = 0
27
28 # Increment this PATCH version before using `charmcraft publish-lib` or reset
29 # to 0 if you are raising the major API version
30-LIBPATCH = 4
31+LIBPATCH = 5
32
33 logger = logging.getLogger(__name__)
34
35@@ -104,17 +105,24 @@ class IngressRequires(Object):
36 """Check our config dict for errors."""
37 blocked_message = "Error in ingress relation, check `juju debug-log`"
38 unknown = [
39- x for x in self.config_dict if x not in REQUIRED_INGRESS_RELATION_FIELDS | OPTIONAL_INGRESS_RELATION_FIELDS
40+ x
41+ for x in self.config_dict
42+ if x not in REQUIRED_INGRESS_RELATION_FIELDS | OPTIONAL_INGRESS_RELATION_FIELDS
43 ]
44 if unknown:
45- logger.error("Ingress relation error, unknown key(s) in config dictionary found: %s", ", ".join(unknown))
46+ logger.error(
47+ "Ingress relation error, unknown key(s) in config dictionary found: %s",
48+ ", ".join(unknown),
49+ )
50 self.model.unit.status = BlockedStatus(blocked_message)
51 return True
52 if not update_only:
53 missing = [x for x in REQUIRED_INGRESS_RELATION_FIELDS if x not in self.config_dict]
54 if missing:
55 logger.error(
56- "Ingress relation error, missing required key(s) in config dictionary: %s", ", ".join(missing))
57+ "Ingress relation error, missing required key(s) in config dictionary: %s",
58+ ", ".join(missing),
59+ )
60 self.model.unit.status = BlockedStatus(blocked_message)
61 return True
62 return False
63@@ -168,12 +176,22 @@ class IngressProvides(Object):
64 }
65
66 missing_fields = sorted(
67- [field for field in REQUIRED_INGRESS_RELATION_FIELDS if ingress_data.get(field) is None]
68+ [
69+ field
70+ for field in REQUIRED_INGRESS_RELATION_FIELDS
71+ if ingress_data.get(field) is None
72+ ]
73 )
74
75 if missing_fields:
76- logger.error("Missing required data fields for ingress relation: {}".format(", ".join(missing_fields)))
77- self.model.unit.status = BlockedStatus("Missing fields for ingress: {}".format(", ".join(missing_fields)))
78+ logger.error(
79+ "Missing required data fields for ingress relation: {}".format(
80+ ", ".join(missing_fields)
81+ )
82+ )
83+ self.model.unit.status = BlockedStatus(
84+ "Missing fields for ingress: {}".format(", ".join(missing_fields))
85+ )
86
87 # Create an event that our charm can use to decide it's okay to
88 # configure the ingress.
89diff --git a/src/charm.py b/src/charm.py
90index ff69cea..954ab6e 100755
91--- a/src/charm.py
92+++ b/src/charm.py
93@@ -35,7 +35,11 @@ def _fix_lp_1892255():
94 """Workaround for lp:1892255."""
95 # Remove os.environ.update when lp:1892255 is FIX_RELEASED.
96 os.environ.update(
97- dict(e.split("=") for e in Path("/proc/1/environ").read_text().split("\x00") if "KUBERNETES_SERVICE" in e)
98+ dict(
99+ e.split("=")
100+ for e in Path("/proc/1/environ").read_text().split("\x00")
101+ if "KUBERNETES_SERVICE" in e
102+ )
103 )
104
105
106@@ -226,7 +230,9 @@ class NginxIngressCharm(CharmBase):
107 annotations["nginx.ingress.kubernetes.io/affinity"] = "cookie"
108 annotations["nginx.ingress.kubernetes.io/affinity-mode"] = "balanced"
109 annotations["nginx.ingress.kubernetes.io/session-cookie-change-on-failure"] = "true"
110- annotations["nginx.ingress.kubernetes.io/session-cookie-max-age"] = self._session_cookie_max_age
111+ annotations[
112+ "nginx.ingress.kubernetes.io/session-cookie-max-age"
113+ ] = self._session_cookie_max_age
114 annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "{}_AFFINITY".format(
115 self._service_name.upper()
116 )
117@@ -258,7 +264,9 @@ class NginxIngressCharm(CharmBase):
118 self.k8s_auth()
119 api = _core_v1_api()
120 services = api.list_namespaced_service(namespace=self._namespace)
121- return [x.spec.cluster_ip for x in services.items if x.metadata.name == self._k8s_service_name]
122+ return [
123+ x.spec.cluster_ip for x in services.items if x.metadata.name == self._k8s_service_name
124+ ]
125
126 def _define_service(self):
127 """Create or update a service in kubernetes."""
128diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
129index 8c1a286..58bb45a 100644
130--- a/tests/unit/test_charm.py
131+++ b/tests/unit/test_charm.py
132@@ -43,7 +43,9 @@ class TestCharm(unittest.TestCase):
133 self.assertEqual(_define_ingress.call_count, 1)
134 self.assertEqual(_define_service.call_count, 1)
135 # Confirm status is as expected.
136- self.assertEqual(self.harness.charm.unit.status, ActiveStatus('Ingress with service IP(s): 10.0.1.12'))
137+ self.assertEqual(
138+ self.harness.charm.unit.status, ActiveStatus('Ingress with service IP(s): 10.0.1.12')
139+ )
140 # And now test with leader is False.
141 _define_ingress.reset_mock()
142 _define_service.reset_mock()
143@@ -245,8 +247,8 @@ class TestCharm(unittest.TestCase):
144 with self.assertLogs(level="ERROR") as logger:
145 self.harness.update_relation_data(relation_id, 'gunicorn', relations_data)
146 msg = (
147- "ERROR:charms.nginx_ingress_integrator.v0.ingress:Missing required data fields for "
148- "ingress relation: service-hostname, service-port"
149+ "ERROR:charms.nginx_ingress_integrator.v0.ingress:Missing required data fields "
150+ "for ingress relation: service-hostname, service-port"
151 )
152 self.assertEqual(sorted(logger.output), [msg])
153 # Confirm blocked status.
154@@ -270,7 +272,9 @@ class TestCharm(unittest.TestCase):
155 def test_get_k8s_ingress(self):
156 """Test getting our definition of a k8s ingress."""
157 self.harness.disable_hooks()
158- self.harness.update_config({"service-hostname": "foo.internal", "service-name": "gunicorn", "service-port": 80})
159+ self.harness.update_config(
160+ {"service-hostname": "foo.internal", "service-name": "gunicorn", "service-port": 80}
161+ )
162 expected = kubernetes.client.NetworkingV1beta1Ingress(
163 api_version="networking.k8s.io/v1beta1",
164 kind="Ingress",
165@@ -357,7 +361,9 @@ class TestCharm(unittest.TestCase):
166 "nginx.ingress.kubernetes.io/affinity": "cookie",
167 "nginx.ingress.kubernetes.io/affinity-mode": "balanced",
168 "nginx.ingress.kubernetes.io/proxy-body-size": "20m",
169- "nginx.ingress.kubernetes.io/proxy-next-upstream": "error timeout http_502 http_503",
170+ "nginx.ingress.kubernetes.io/proxy-next-upstream": (
171+ "error timeout http_502 http_503"
172+ ),
173 "nginx.ingress.kubernetes.io/rewrite-target": "/",
174 "nginx.ingress.kubernetes.io/session-cookie-change-on-failure": "true",
175 "nginx.ingress.kubernetes.io/session-cookie-max-age": "3600",
176diff --git a/tox.ini b/tox.ini
177index 7a39457..fcbf8f0 100644
178--- a/tox.ini
179+++ b/tox.ini
180@@ -29,7 +29,7 @@ deps = -r{toxinidir}/tests/functional/requirements.txt
181 -r{toxinidir}/requirements.txt
182
183 [testenv:black]
184-commands = black --skip-string-normalization --line-length=120 src/ tests/ lib/
185+commands = black --skip-string-normalization --line-length=99 src/ tests/ lib/
186 deps = black
187
188 [testenv:lint]
189@@ -45,5 +45,5 @@ exclude =
190 .tox,
191 # Ignore E231, W503 because using black creates errors with this
192 ignore = E231, W503
193-max-line-length = 120
194+max-line-length = 99
195 max-complexity = 10

Subscribers

People subscribed via source and target branches

to all changes: