Repository: zulip/zulip-terminal
Pull request #1179 (2022-03-27 00:47:51)

Upgrade dependencies (install, dev, linting, dev_helper)
<!-- Please see https://github.com/zulip/zulip-terminal#contributor-guidelines ! -->

**What does this PR do?**  <!-- Overall description goes here -->

This bumps the versions of many of the project's dependencies.

Most of the install dependencies provide extra features or bugfixes, with the addition that the zulip package now incorporates some code that was previously defined locally so that can be refactored out. The only downside of the latter is that this is less explicit in our code, hence the minor additional comments.

Other than bumping linting dependencies generally, the upgraded `mypy` will allow for improving our use of `TypedDict`, among other possibilities. Additional typing dependencies should help; we could consider one for `beautifulsoup4`, but this requires further analysis so I've left it at this time.

<!-- If fixing a filed bug or new feature, add 'Fixes #<issue>' or 'Partial fix for #<issue>' -->

<!-- Add a link to a discussion on chat.zulip.org, if relevant -->

**Tested?** <!-- Fine to leave some of these unchecked if this is a draft/work-in-progress -->
- [x] Manually
- [x] Existing tests (adapted, if necessary)
- [ ] New tests added (for any new behavior)
- [ ] Passed linting & tests (each commit)
<!-- Code must pass CI (GitHub Actions) before merging - look for the green tick! -->

There should not be any significant feature changes in the dependencies, so I expect tests to pass fine.

**Notes & Questions** <!-- if any; add/delete/fill-in as appropriate -->

The change to gitlint may require an uninstall and reinstall. I've not made an update to the documentation regarding this (at least yet) as existing developers tend to be involved on chat.zulip.org, where I'll raise this point.

Potential follow-up:
- investigate adding the type package for `beautifulsoup4`
- investigate extra changes possible via the mypy upgrade (eg. in `TypedDict` with `total=False`)
- update gruvbox theme to use pygments gruvbox theme directly, rather than an approximation

zulipbot: Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

<!-- areaLabelAddition -->


Patch:
diff --git a/setup.py b/setup.py
index e59c171..ccaa598 100644
--- a/setup.py
+++ b/setup.py
@@ -42,15 +42,17 @@ testing_deps = [
 ]
 
 linting_deps = [
-    "isort~=5.7.0",
-    "flake8~=3.9.0",
+    "isort~=5.10.1",
+    "flake8~=4.0.1",
     "flake8-quotes~=3.2.0",
     "flake8-continuation~=1.0.5",
     "black>=22.1.0",
 ]
 
 typing_deps = [
-    "mypy==0.910",
+    "lxml-stubs",
+    "mypy==0.942",
+    "types-pygments",
     "types-python-dateutil",
     "types-tzlocal",
     "types-pytz",
@@ -58,11 +60,11 @@ typing_deps = [
 ]
 
 dev_helper_deps = [
-    "pudb==2017.1.4",
-    "snakeviz==0.4.2",
-    "gitlint>=0.10",
-    "autopep8~=1.5.4",
-    "autoflake~=1.3.1",
+    "pudb==2022.1.1",
+    "snakeviz>=2.1.1",
+    "gitlint>=0.17",
+    "autopep8~=1.6.0",
+    "autoflake~=1.4.0",
 ]
 
 setup(
@@ -115,14 +117,14 @@ setup(
     tests_require=testing_deps,
     install_requires=[
         "urwid~=2.1.2",
-        "zulip>=0.7.0",
+        "zulip>=0.8.2",
         "urwid_readline>=0.13",
-        "beautifulsoup4>=4.9.0",
-        "lxml>=4.6.2",
-        "pygments>=2.8.1",
+        "beautifulsoup4>=4.10.0",
+        "lxml>=4.7.1",
+        "pygments>=2.11.2",
         "typing_extensions>=3.7",
-        "python-dateutil>=2.8.1",
-        "pytz>=2021.1",
+        "python-dateutil>=2.8.2",
+        "pytz>=2022.1",
         "tzlocal>=2.1",
         "pyperclip>=1.8.1",
     ],
diff --git a/zulipterminal/api_types.py b/zulipterminal/api_types.py
index db6b8d9..17dc1a1 100644
--- a/zulipterminal/api_types.py
+++ b/zulipterminal/api_types.py
@@ -2,20 +2,14 @@ from typing import Any, Dict, List, Optional, Union
 
 from typing_extensions import Literal, TypedDict
 
+# These are documented in the zulip package (python-zulip-api repo)
+from zulip import EditPropagateMode  # one/all/later
+from zulip import EmojiType  # [unicode/realm/zulip_extra + _emoji]
+from zulip import MessageFlag  # superset of below, may only be changed indirectly
+from zulip import ModifiableMessageFlag  # directly modifiable read/starred/collapsed
 
-RESOLVED_TOPIC_PREFIX = "✔ "
 
-EditPropagateMode = Literal["change_one", "change_all", "change_later"]
-EmojiType = Literal["realm_emoji", "unicode_emoji", "zulip_extra_emoji"]
-# Limited flags which could be present in update_message_flag events.
-ModifiableMessageFlag = Literal["read", "starred", "collapsed"]
-MessageFlag = Literal[
-    ModifiableMessageFlag,
-    "mentioned",
-    "wildcard_mentioned",
-    "has_alert_word",
-    "historical",
-]
+RESOLVED_TOPIC_PREFIX = "✔ "
 
 
 class PrivateComposition(TypedDict):
diff --git a/zulipterminal/config/ui_mappings.py b/zulipterminal/config/ui_mappings.py
index 6d8de48..6d05256 100644
--- a/zulipterminal/config/ui_mappings.py
+++ b/zulipterminal/config/ui_mappings.py
@@ -40,3 +40,10 @@ ROLE_BY_ID: Dict[Optional[int], Dict[str, str]] = {
     400: {"bool": "", "name": "Member"},
     600: {"bool": "is_guest", "name": "Guest"},
 }
+
+STREAM_POST_POLICY = {
+    1: "Any user can post",
+    2: "Only organization administrators can send to this stream",
+    3: "Only organization administrators, moderators and full members can send to this stream",
+    4: "Only organization administrators and moderators can send to this stream",
+}
diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py
index 838000c..1fce22a 100644
--- a/zulipterminal/ui_tools/views.py
+++ b/zulipterminal/ui_tools/views.py
@@ -28,6 +28,7 @@ from zulipterminal.config.ui_mappings import (
     EDIT_MODE_CAPTIONS,
     ROLE_BY_ID,
     STATE_ICON,
+    STREAM_POST_POLICY,
 )
 from zulipterminal.config.ui_sizes import LEFT_WIDTH
 from zulipterminal.helper import (
@@ -1329,6 +1330,14 @@ class StreamInfoView(PopUpView):
             )
         ]
 
+        if "stream_post_policy" in stream:
+            stream_policy = STREAM_POST_POLICY[stream["stream_post_policy"]]
+        else:
+            if stream.get("is_announcement_only"):
+                stream_policy = STREAM_POST_POLICY[2]
+            else:
+                stream_policy = STREAM_POST_POLICY[1]
+
         total_members = len(stream["subscribers"])
         type_of_stream = "Private" if stream["invite_only"] else "Public"
         availability_of_history = (
@@ -1376,6 +1385,7 @@ class StreamInfoView(PopUpView):
                         f"Press {email_keys} to copy Stream email address",
                     ),
                     ("History of Stream", f"{availability_of_history}"),
+                    ("Posting Policy", f"{stream_policy}"),
                 ],
             ),
             ("Stream settings", []),


Test patch:
diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py
index a89d3c8..02c7687 100644
--- a/tests/ui_tools/test_popups.py
+++ b/tests/ui_tools/test_popups.py
@@ -1185,45 +1185,68 @@ class TestStreamInfoView:
         ],
         [
             case(
-                {"date_created": None},
+                {"date_created": None, "is_announcement_only": True},
                 "74 [Organization default]",
                 None,
-                15,
-                id="ZFL=None_no_date_created__no_retention_days",
+                17,
+                id="ZFL=None_no_date_created__no_retention_days__admins_only",
             ),
             case(
-                {"date_created": None},
+                {"date_created": None, "is_announcement_only": False},
                 "74 [Organization default]",
+                None,
+                16,
+                id="ZFL=None_no_date_created__no_retention_days__anyone_can_type",
+            ),
+            case(
+                {"date_created": None, "stream_post_policy": 1},
+                "74 [Organization default]",
+                16,
                 16,
-                15,
                 id="ZFL<30_no_date_created__ZFL<17_no_retention_days",
             ),
             case(
-                {"date_created": None, "message_retention_days": 200},
+                {
+                    "date_created": None,
+                    "message_retention_days": 200,
+                    "stream_post_policy": 2,
+                },
                 "200",
                 17,
-                15,
+                17,
                 id="ZFL<30_no_date_created__ZFL=17_custom_finite_retention_days",
             ),
             case(
-                {"date_created": None, "message_retention_days": None},
+                {
+                    "date_created": None,
+                    "message_retention_days": None,
+                    "stream_post_policy": 3,
+                },
                 "Indefinite [Organization default]",
                 29,
-                15,
+                18,
                 id="ZFL<30_no_date_created__ZFL>17_default_indefinite_retention_days",
             ),
             case(
-                {"date_created": 1472091253, "message_retention_days": 31},
+                {
+                    "date_created": 1472091253,
+                    "message_retention_days": 31,
+                    "stream_post_policy": 4,
+                },
                 "31",
                 30,
-                16,
+                18,
                 id="ZFL=30_with_date_created__ZFL>17_custom_finite_retention_days",
             ),
             case(
-                {"date_created": 1472047124, "message_retention_days": None},
+                {
+                    "date_created": 1472047124,
+                    "message_retention_days": None,
+                    "stream_post_policy": 2,
+                },
                 "72 [Organization default]",
                 40,
-                16,
+                18,
                 id="ZFL>30_with_date_created__ZFL>17_default_finite_retention_days",
             ),
             case(
@@ -1231,10 +1254,11 @@ class TestStreamInfoView:
                     "date_created": 1472046489,
                     "stream_weekly_traffic": None,
                     "message_retention_days": 60,
+                    "stream_post_policy": 1,
                 },
                 "60",
                 50,
-                16,
+                17,
                 id="ZFL>30_new_stream_with_date_created__ZFL>17_finite_retention_days",
             ),
         ],