Skip to content

Commit e1ba1a7

Browse files
authored
Merge branch 'main' into irc-ssl
2 parents c2094f8 + ffb8a38 commit e1ba1a7

File tree

234 files changed

+11571
-8837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+11571
-8837
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13-
[*.{sh,py,pyi,js,json,yml,xml,css,md,markdown,handlebars,html}]
13+
[*.{sh,py,pyi,js,json,xml,css,md,markdown,handlebars,html}]
1414
indent_style = space
1515
indent_size = 4
1616

17-
[*.{svg,rb,pp,pl}]
17+
[*.{svg,rb,pp,pl,yaml,yml}]
1818
indent_style = space
1919
indent_size = 2
2020

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
ignore =
33
# Each of these rules are ignored for the explained reason.
44

5+
# "whitespace before ':'"
6+
# Black disagrees with this.
7+
E203,
8+
59
# "multiple spaces before operator"
610
# There are several typos here, but also several instances that are
711
# being used for alignment in dict keys/values using the `dict`

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
github: zulip
2+
patreon: zulip
3+
open_collective: zulip

.github/workflows/zulip-tests.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
static-analysis:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Setup Python 3.6
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.6
20+
21+
- name: Install dependencies
22+
run: tools/provision --force
23+
24+
- name: Running Test-Suite
25+
run: |
26+
source zulip-api-py3-venv/bin/activate
27+
tools/lint --skip=gitlint
28+
29+
test:
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os: [ubuntu-latest, windows-latest]
35+
python-version: [3.6, 3.7, 3.8, 3.9]
36+
exclude:
37+
- os: windows-latest
38+
python-version: 3.6 # cryptography install fails on Windows with python 3.6 since pip is quite old.
39+
40+
steps:
41+
- uses: actions/checkout@v2
42+
43+
- name: Setup Python ${{ matrix.python-version }}
44+
uses: actions/setup-python@v2
45+
with:
46+
python-version: ${{ matrix.python-version }}
47+
48+
- name: Install dependencies
49+
run: python tools/provision --force
50+
51+
- if: runner.os == 'Linux'
52+
name: Running Test-Suite on Linux
53+
run: |
54+
source zulip-api-py3-venv/bin/activate
55+
pytest --cov --cov-config=tools/.coveragerc --cov-report=xml
56+
57+
- if: runner.os == 'Windows'
58+
name: Running Test-Suite on Windows
59+
run: |
60+
zulip-api-py3-venv\Scripts\Activate.ps1
61+
pytest --cov --cov-config=tools\.coveragerc --cov-report=xml
62+
63+
- uses: codecov/codecov-action@v2
64+
with:
65+
files: coverage.xml

.gitlint

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is copied from the original .gitlint at zulip/zulip.
2+
# Please don't edit here; instead update the zulip/zulip copy and then resync this file.
3+
4+
[general]
5+
ignore=title-trailing-punctuation, body-min-length, body-is-missing
6+
extra-path=tools/gitlint-rules.py
7+
8+
[title-match-regex]
9+
regex=^(.+:\ )?[A-Z].+\.$
10+
11+
[title-max-length]
12+
line-length=76
13+
14+
[body-max-line-length]
15+
line-length=76

.travis.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Zulip API
22

3-
![Build status](https://travis-ci.org/zulip/python-zulip-api.svg?branch=master)
4-
[![Coverage status](https://img.shields.io/codecov/c/github/zulip/python-zulip-api/master.svg)](
3+
[![Build status](https://github.com/zulip/python-zulip-api/workflows/build/badge.svg)](
4+
https://github.com/zulip/python-zulip-api/actions?query=branch%3Amain+workflow%3Abuild)
5+
[![Coverage status](https://img.shields.io/codecov/c/github/zulip/python-zulip-api)](
56
https://codecov.io/gh/zulip/python-zulip-api)
67

78
This repository contains the source code for Zulip's PyPI packages:
@@ -21,17 +22,17 @@ This is part of the Zulip open source project; see the
2122
[contributing guide](https://zulip.readthedocs.io/en/latest/overview/contributing.html)
2223
and [commit guidelines](https://zulip.readthedocs.io/en/latest/contributing/version-control.html).
2324

24-
1. Fork and clone the Git repo:
25-
`git clone https://github.com/<your_username>/python-zulip-api.git`
26-
27-
2. Make sure you have [pip](https://pip.pypa.io/en/stable/installing/)
28-
and [virtualenv](https://virtualenv.pypa.io/en/stable/installation.html)
29-
installed.
25+
1. Fork and clone the Git repo, and set upstream to zulip/python-zulip-api:
26+
```
27+
git clone https://github.com/<your_username>/python-zulip-api.git
28+
cd python-zulip-api
29+
git remote add upstream https://github.com/zulip/python-zulip-api.git
30+
git fetch upstream
31+
```
3032

31-
3. `cd` into the repository cloned earlier:
32-
`cd python-zulip-api`
33+
2. Make sure you have [pip](https://pip.pypa.io/en/stable/installing/).
3334

34-
4. Run:
35+
3. Run:
3536
```
3637
python3 ./tools/provision
3738
```
@@ -42,14 +43,14 @@ and [commit guidelines](https://zulip.readthedocs.io/en/latest/contributing/vers
4243
python3 ./tools/provision -p <path_to_your_python_version>
4344
```
4445

45-
5. If that succeeds, it will end with printing the following command:
46+
4. If that succeeds, it will end with printing the following command:
4647
```
4748
source /.../python-zulip-api/.../activate
4849
```
4950
You can run this command to enter the virtual environment.
5051
You'll want to run this in each new shell before running commands from `python-zulip-api`.
5152

52-
6. Once you've entered the virtualenv, you should see something like this on the terminal:
53+
5. Once you've entered the virtualenv, you should see something like this on the terminal:
5354
```
5455
(zulip-api-py3-venv) user@pc ~/python-zulip-api $
5556
```
@@ -58,13 +59,14 @@ and [commit guidelines](https://zulip.readthedocs.io/en/latest/contributing/vers
5859

5960
### Running tests
6061

61-
To run the tests for
62-
63-
* *zulip*: run `./tools/test-zulip`
62+
You can run all the tests with:
6463

65-
* *zulip_bots*: run `./tools/test-lib && ./tools/test-bots`
64+
`pytest`
6665

67-
* *zulip_botserver*: run `./tools/test-botserver`
66+
or test individual packages with `pytest zulip`, `pytest zulip_bots`,
67+
or `pytest zulip_botserver` (see the [pytest
68+
documentation](https://docs.pytest.org/en/latest/how-to/usage.html)
69+
for more options).
6870

6971
To run the linter, type:
7072

mypy.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[mypy]
2+
mypy_path = $MYPY_CONFIG_FILE_DIR/stubs
3+
24
check_untyped_defs = True
35
disallow_any_generics = True
46
strict_optional = True
@@ -9,3 +11,6 @@ scripts_are_modules = True
911
show_traceback = True
1012

1113
warn_no_return = True
14+
warn_redundant_casts = True
15+
warn_unused_ignores = True
16+
warn_unreachable = True

packaged_helloworld/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a boilerplate package for a Zulip bot that can be installed from pip
2+
and launched using the `zulip-run-bots` command.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Simple Zulip bot that will respond to any query with a "beep boop".
2+
3+
The packaged_helloworld bot is a boilerplate bot that can be used as a
4+
template for more sophisticated/evolved Zulip bots that can be
5+
installed separately.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See readme.md for instructions on running this code.
2+
from typing import Any, Dict
3+
4+
import packaged_helloworld
5+
6+
from zulip_bots.lib import BotHandler
7+
8+
__version__ = packaged_helloworld.__version__
9+
10+
11+
class HelloWorldHandler:
12+
def usage(self) -> str:
13+
return """
14+
This is a boilerplate bot that responds to a user query with
15+
"beep boop", which is robot for "Hello World".
16+
17+
This bot can be used as a template for other, more
18+
sophisticated, bots that can be installed separately.
19+
"""
20+
21+
def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None:
22+
content = "beep boop" # type: str
23+
bot_handler.send_reply(message, content)
24+
25+
emoji_name = "wave" # type: str
26+
bot_handler.react(message, emoji_name)
27+
return
28+
29+
30+
handler_class = HelloWorldHandler

packaged_helloworld/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import packaged_helloworld
2+
from setuptools import find_packages, setup
3+
4+
package_info = {
5+
"name": "packaged_helloworld",
6+
"version": packaged_helloworld.__version__,
7+
"entry_points": {
8+
"zulip_bots.registry": ["packaged_helloworld=packaged_helloworld.packaged_helloworld"],
9+
},
10+
"packages": find_packages(),
11+
}
12+
13+
setup(**package_info)

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool.black]
2+
line-length = 100
3+
target-version = ["py36"]
4+
5+
[tool.isort]
6+
src_paths = ["tools", "zulip", "zulip_bots", "zulip_botserver"]
7+
profile = "black"
8+
line_length = 100

requirements.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
crayons
22
twine
3-
coverage>=4.4.1
3+
black
4+
isort
45
flake8
56
mock
67
pytest
8+
pytest-cov
79
-e ./zulip
810
-e ./zulip_bots
911
-e ./zulip_botserver
10-
-e git+https://github.com/zulip/zulint@639c0d34c23ac559ef0f7b9510cf95f73f6d0eb9#egg=zulint==1.0.0
11-
mypy==0.770
12+
-e git+https://github.com/zulip/zulint@14e3974001bf8442a6a3486125865660f1f2eb68#egg=zulint==1.0.0
13+
mypy==0.910
14+
types-python-dateutil
15+
types-pytz
16+
types-requests
17+
gitlint>=0.13.0

stubs/_zephyr.pyi

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from typing import List, Optional, Sequence, Tuple, overload
2+
3+
from typing_extensions import Literal
4+
5+
class ZUid:
6+
address: str
7+
time: float
8+
9+
class ZNotice:
10+
kind: int
11+
cls: str
12+
instance: str
13+
uid: ZUid
14+
time: int
15+
port: int
16+
auth: bool
17+
recipient: Optional[str]
18+
sender: Optional[str]
19+
opcode: Optional[str]
20+
format: str
21+
other_fields: List[str]
22+
fields: List[str]
23+
_charset: Optional[str]
24+
def __init__(
25+
self,
26+
kind: int = ...,
27+
cls: str = ...,
28+
instance: str = ...,
29+
uid: ZUid = ...,
30+
time: int = ...,
31+
port: int = ...,
32+
auth: bool = ...,
33+
recipient: Optional[str] = ...,
34+
sender: Optional[str] = ...,
35+
opcode: Optional[str] = ...,
36+
format: str = ...,
37+
other_fields: List[str] = ...,
38+
fields: List[str] = ...,
39+
_charset: Optional[str] = ...,
40+
message: str = ...,
41+
): ...
42+
def getmessage(self) -> str: ...
43+
def setmessage(self, newmsg: str) -> None: ...
44+
message = property(getmessage, setmessage)
45+
@property
46+
def charset(self) -> Optional[str]: ...
47+
def send(self) -> None: ...
48+
49+
def initialize() -> None: ...
50+
def openPort() -> int: ...
51+
def getFD() -> int: ...
52+
def setFD(fd: int) -> None: ...
53+
def sub(cls: str, instance: str, recipient: str) -> None: ...
54+
def subAll(lst: Sequence[Tuple[str, str, str]]) -> None: ...
55+
def unsub(cls: str, instance: str, recipient: str) -> None: ...
56+
def cancelSubs() -> None: ...
57+
@overload
58+
def receive(block: Literal[True]) -> ZNotice: ...
59+
@overload
60+
def receive(block: bool = ...) -> Optional[ZNotice]: ...
61+
def sender() -> str: ...
62+
def realm() -> str: ...
63+
def dump_session() -> bytes: ...
64+
def load_session(session: bytes) -> None: ...
65+
def getSubscriptions() -> List[Tuple[str, str, str]]: ...

stubs/zephyr.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Set, Tuple
2+
3+
import _zephyr
4+
from _zephyr import ZNotice as ZNotice
5+
from _zephyr import receive as receive
6+
7+
_z = _zephyr
8+
__inited: bool
9+
10+
def init() -> None: ...
11+
12+
class Subscriptions(Set[Tuple[str, str, str]]):
13+
pass

0 commit comments

Comments
 (0)