Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build/*
zulip_term.egg-info
zulip-terminal-tracebacks.log
zulip-terminal-API-requests.log
zt_venv/*

.vscode/*
.DS_Store
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ pudb = "==2017.1.4"
snakeviz = "==0.4.2"
gitlint = "==0.10.0"
isort = "==4.3.21"
autopep8 = "~=1.5.4"
autoflake = "~=1.3.1"
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,18 @@ $ pipenv run pip3 install -r requirements.txt
$ pip3 install -e '.[dev]'
```

#### make/pip

This is the newest and simplest approach, if you have `make` installed:

1. `make` (sets up an installed virtual environment in `zt_venv` in the current directory)
2. `source zt_venv/bin/activate` (activates the venv; this assumes a bash-like shell)

### Development tasks

Once you have a development environment set up, you might find the following useful, depending upon your type of environment:

| Task | Pip | Pipenv |
| Task | Make & Pip | Pipenv |
|-|-|-|
| Run normally | `zulip-term` | `pipenv run zulip-term` |
| Run in debug mode | `zulip-term -d` | `pipenv run zulip-term -d` |
Expand All @@ -277,8 +284,12 @@ Once you have a development environment set up, you might find the following use
| Run all tests | `pytest` | `pipenv run pytest` |
| Build test coverage report | `pytest --cov-report html:cov_html --cov=./` | `pipenv run pytest --cov-report html:cov_html --cov=./` |

If using make with pip, running `make` will ensure the development environment is up to date with the specified dependencies, useful after fetching from git and rebasing.

NOTE: The linters and pytest are run in CI (travis) when you submit a pull request (PR), and we expect them to pass before code is merged. Running them locally can speed your development time, but if you have troubles understanding why the linters or pytest are failing, please do push your code to a branch/PR and we can discuss the problems in the PR or on chat.zulip.org.

If using make with pip, there are corresponding make targets for running linting and testing if you wish to use them (`make lint` & `make test`), and before pushing a pull-request (PR) ready for merging you may find it useful to ensure that `make check` runs successfully (which runs both).

NOTE: The lint script runs a number of separate linters to simplify the development workflow, but each individual linter can be run separately if you find this useful.

#### GitLint (optional)
Expand Down
49 changes: 49 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.PHONY: install-devel check lint test check-clean-tree fix force-fix venv

# NOTE: ZT_VENV and BASEPYTHON are advanced undocumented features
# Customize your venv name by running make as "ZT_VENV=my_venv_name make <command>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that the ZT_VENV=... would not only be required for the first time but every time it is run.

Additionally, perhaps rename <command> to <zt-command>?

Also, should we rather include this in the README so that it is easier to find?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had specifically left these notes in the makefile for now as they seemed more 'advanced', and may be scope for further extension - they work, but for now it's easier to just have one environment with a standard name.

I'm not sure we gain from zt-command - what matters is running the different makefile 'targets', which are more just specific to those in the makefile.


BASEPYTHON?=python3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only restriction this poses is being able to choose the exact python version during venv creation. This isn't a limitation on its own, but if we are going for an "advanced" setup option, we should consider this being customizable.

ZT_VENV?=zt_venv

VENV_ACTIVATE=. $(ZT_VENV)/bin/activate
PYTHON=${ZT_VENV}/bin/$(BASEPYTHON)

SOURCES = zulipterminal tests setup.py

# Default target at top
install-devel: venv

### LINT/TEST FILES ###

check: lint test

lint: venv
@tools/lint-all

test: venv
@pytest

### FIX FILES ###

check-clean-tree:
@git diff --exit-code --quiet || (echo 'Tree is not clean - commit changes in git first' && false)

fix: check-clean-tree
@make force-fix

force-fix: venv
@echo "=== Auto-fixing files ==="
isort --recursive $(SOURCES)
autopep8 --recursive --in-place $(SOURCES)
autoflake --recursive --in-place $(SOURCES)

### VENV SETUP ###
# Short name for file dependency
venv: $(ZT_VENV)/bin/activate

# If setup.py is updated or activate script doesn't exist, update virtual env
Copy link
Member

@preetmishra preetmishra Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps include the fact that the makefile will continue to make a new venv even if a custom venv exists (without the ZT_VENV=... command).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean if you don't use a custom environment name for all make invocations, it will build the standard one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems to build the standard one without that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, since the custom one is a bit awkward to run and manage, perhaps we should only promote the standard one.

$(ZT_VENV)/bin/activate: setup.py
@echo "=== Installing development environment ==="
test -d $(ZT_VENV) || $(BASEPYTHON) -m venv $(ZT_VENV)
$(PYTHON) -m pip install -U pip && $(PYTHON) -m pip install -e .[dev] && touch $(ZT_VENV)/bin/activate
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ beautifulsoup4>=4.9.0
lxml>=4.5.2
python-dateutil>=2.8.1
tzlocal>=2.1
autopep8~=1.5.4
autoflake~=1.3.1

zipp==1.0.0 # To support Python 3.5
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ def long_description():
linting_deps = [
'isort==4.3.21',
'mypy==0.782',
'flake8==3.7.9',
'flake8-quotes==3.0.0',
'flake8-continuation==1.0.5',
'flake8~=3.8.3',
'flake8-quotes~=3.2.0',
'flake8-continuation~=1.0.5',
]

dev_helper_deps = [
'pudb==2017.1.4',
'snakeviz==0.4.2',
'gitlint>=0.10',
'autopep8~=1.5.4',
'autoflake~=1.3.1',
]

setup(
Expand Down
14 changes: 7 additions & 7 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ def test_set_narrow_not_already_set(self, model, initial_narrow, narrow,
}
}, {0, 1}),
([['stream', 'FOO'],
['topic', 'BOO']], {
['topic', 'BOO']], {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that make fix made formatting changes in files which were already passing the linting tests is concerning. Do we have a plan to enforce make fix promptly?

Otherwise, it could potentially accumulate a bunch of unrelated changes in PRs which build on a master commit that didn't run make fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the difference is that autopep8 fixes many pep8 rules as specified, but also some additional ones as here: https://pypi.org/project/autopep8/#features

We could add this to CI without --in-place and with --diff, as a linter. Also autoflake. Ideally this would be part of flake8, so we wouldn't need another checker :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. :/ Nonetheless, we should perhaps enforce this with our CI for consistency.

'topic_msg_ids': {
1: {
'BOO': {0, 1}
}
}
}, {0, 1}),
([['stream', 'FOO'], # Covers one empty-set case
['topic', 'BOOBOO']], {
['topic', 'BOOBOO']], {
'topic_msg_ids': {
1: {
'BOO': {0, 1}
Expand Down Expand Up @@ -859,11 +859,11 @@ def test__handle_message_event(self, mocker, user_profile, response,
@pytest.mark.parametrize(['topic_name', 'topic_order_initial',
'topic_order_final'], [
('TOPIC3', ['TOPIC2', 'TOPIC3', 'TOPIC1'],
['TOPIC3', 'TOPIC2', 'TOPIC1']),
['TOPIC3', 'TOPIC2', 'TOPIC1']),
('TOPIC1', ['TOPIC1', 'TOPIC2', 'TOPIC3'],
['TOPIC1', 'TOPIC2', 'TOPIC3']),
['TOPIC1', 'TOPIC2', 'TOPIC3']),
('TOPIC4', ['TOPIC1', 'TOPIC2', 'TOPIC3'],
['TOPIC4', 'TOPIC1', 'TOPIC2', 'TOPIC3']),
['TOPIC4', 'TOPIC1', 'TOPIC2', 'TOPIC3']),
('TOPIC1', [], ['TOPIC1'])
], ids=['reorder_topic3', 'topic1_discussion_continues', 'new_topic4',
'first_topic_1'])
Expand Down Expand Up @@ -1321,7 +1321,7 @@ def test_update_star_status(self, mocker, model, event_op,
assert model.index['messages'][changed_id]['flags'] == flags_after
(model._update_rendered_view.
assert_has_calls([mocker.call(changed_id)
for changed_id in changed_ids]))
for changed_id in changed_ids]))

for unchanged_id in (set(indexed_ids) - set(event_message_ids)):
assert (model.index['messages'][unchanged_id]['flags']
Expand Down Expand Up @@ -1533,7 +1533,7 @@ def test__handle_subscription_event_mute_streams(self, model, mocker,
model.controller.update_screen.assert_called_once_with()

@pytest.mark.parametrize(['event', 'expected_pinned_streams',
'expected_unpinned_streams'], [
'expected_unpinned_streams'], [
(
{
'property': 'pin_to_top',
Expand Down
1 change: 1 addition & 0 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ class PanelSearchBox(urwid.Edit):
"""
Search Box to search panel views in real-time.
"""

def __init__(self, panel_view: Any, search_command: str,
update_function: Callable[..., None]) -> None:
self.panel_view = panel_view
Expand Down
1 change: 0 additions & 1 deletion zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,3 @@ def handle_link(self, *_: Any) -> None:
"""
Classifies and handles link.
"""
pass
1 change: 1 addition & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class StreamsViewDivider(urwid.Divider):
"""
A custom urwid.Divider to visually separate pinned and unpinned streams.
"""

def __init__(self) -> None:
# FIXME: Necessary since the divider is treated as a StreamButton.
# NOTE: This is specifically for stream search to work correctly.
Expand Down