X Tutup
Skip to content

Commit 6bdca1e

Browse files
committed
Merge pull request python-telegram-bot#294 from python-telegram-bot/yapf
yapf formatter, pre-commit hooks and new travis tests
2 parents 56b1d4f + fd7b571 commit 6bdca1e

File tree

133 files changed

+627
-1156
lines changed

Some content is hidden

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

133 files changed

+627
-1156
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- repo: git://github.com/pre-commit/mirrors-yapf
2+
sha: 'v0.7.1'
3+
hooks:
4+
- id: yapf
5+
args: ['-i']
6+
7+
- repo: git://github.com/pre-commit/pre-commit-hooks
8+
sha: 'v0.5.0'
9+
hooks:
10+
- id: flake8
11+
args: ['telegram']
12+
13+
- repo: git://github.com/pre-commit/mirrors-pylint
14+
sha: 'v1.5.5'
15+
hooks:
16+
- id: pylint
17+
args: ['--errors-only', '--disable=no-name-in-module,import-error', 'telegram']

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ install:
1313
- pip install -r requirements-dev.txt
1414
script:
1515
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/
16+
- 'if [ $TRAVIS_PYTHON_VERSION != 2.6 ] && [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then yapf -r telegram; fi'
1617
- flake8 telegram
17-
- 'if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then pylint -E telegram --disable=no-name-in-module,import-error; fi'
18+
- 'if [ $TRAVIS_PYTHON_VERSION != 2.6 ]; then pylint -E telegram --disable=no-name-in-module,import-error; fi'
1819
after_success:
1920
coveralls

CONTRIBUTING.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Setting things up
2222

2323
``$ pip install -r requirements.txt -r requirements-dev.txt``
2424

25+
26+
5. Install pre-commit hooks:
27+
28+
``$ pre-commit install``
29+
2530
Finding something to do
2631
-----------------------
2732

@@ -68,18 +73,20 @@ Here's how to make a one-off code change.
6873

6974
- Add yourself to the AUTHORS.rst_ file in an alphabetical fashion.
7075

71-
- Before making a commit ensure that all automated tests, pep8 & lint validations still pass:
76+
- Before making a commit ensure that all automated tests still pass:
7277

7378
``$ make test``
7479

75-
``$ make pep8``
80+
- To actually make the commit (this will trigger tests for yapf, lint and pep8 automatically):
7681

77-
``$ make lint``
82+
``$ git add your-file-changed.py``
7883

79-
- To actually make the commit and push it to your GitHub fork, run:
84+
- yapf may change code formatting, make sure to re-add them to your commit.
8085

8186
``$ git commit -a -m "your-commit-message-here"``
8287

88+
- Finally, push it to your GitHub fork, run:
89+
8390
``$ git push origin your-branch-name``
8491

8592
4. **When your feature is ready to merge, create a pull request.**

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.DEFAULT_GOAL := help
2-
.PHONY: clean pep8 lint test install
2+
.PHONY: clean pep257 pep8 yapf lint test install
33

44
PYLINT := pylint
55
NOSETESTS := nosetests
66
PEP257 := pep257
77
PEP8 := flake8
8+
YAPF := yapf
89
PIP := pip
910

1011
clean:
@@ -19,7 +20,10 @@ pep257:
1920
$(PEP257) telegram
2021

2122
pep8:
22-
$(PEP8) telegram
23+
$(PEP8) telegram
24+
25+
yapf:
26+
$(YAPF) -r telegram
2327

2428
lint:
2529
$(PYLINT) -E telegram --disable=no-name-in-module,import-error
@@ -28,19 +32,21 @@ test:
2832
$(NOSETESTS) -v
2933

3034
install:
31-
$(PIP) install -r requirements.txt
35+
$(PIP) install -r requirements.txt -r requirements-dev.txt
3236

3337
help:
3438
@echo "Available targets:"
3539
@echo "- clean Clean up the source directory"
3640
@echo "- pep257 Check docstring style with pep257"
3741
@echo "- pep8 Check style with flake8"
3842
@echo "- lint Check style with pylint"
43+
@echo "- yapf Check style with yapf"
3944
@echo "- test Run tests"
4045
@echo
4146
@echo "Available variables:"
4247
@echo "- PYLINT default: $(PYLINT)"
4348
@echo "- NOSETESTS default: $(NOSETESTS)"
4449
@echo "- PEP257 default: $(PEP257)"
4550
@echo "- PEP8 default: $(PEP8)"
51+
@echo "- YAPF default: $(YAPF)"
4652
@echo "- PIP default: $(PIP)"

requirements-dev.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ nose
33
pep257
44
pylint
55
unittest2
6-
flaky
6+
flaky
7+
yapf
8+
pre-commit
9+
pre-commit-hooks

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ upload-dir = docs/build/html
1111

1212
[flake8]
1313
max-line-length = 99
14+
15+
[yapf]
16+
based_on_style = google
17+
column_limit = 99

telegram/__init__.py

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
19-
2019
"""A library that provides a Python interface to the Telegram Bot API"""
2120

2221
from sys import version_info
@@ -81,70 +80,24 @@
8180
from .update import Update
8281
from .bot import Bot
8382

84-
8583
__author__ = 'devs@python-telegram-bot.org'
8684
__version__ = '4.0.3'
87-
__all__ = ['Audio',
88-
'Bot',
89-
'Chat',
90-
'ChatAction',
91-
'ChosenInlineResult',
92-
'CallbackQuery',
93-
'Contact',
94-
'Document',
95-
'Emoji',
96-
'File',
97-
'ForceReply',
98-
'InlineKeyboardButton',
99-
'InlineKeyboardMarkup',
100-
'InlineQuery',
101-
'InlineQueryResult',
102-
'InlineQueryResult',
103-
'InlineQueryResultArticle',
104-
'InlineQueryResultAudio',
105-
'InlineQueryResultCachedAudio',
106-
'InlineQueryResultCachedDocument',
107-
'InlineQueryResultCachedGif',
108-
'InlineQueryResultCachedMpeg4Gif',
109-
'InlineQueryResultCachedPhoto',
110-
'InlineQueryResultCachedSticker',
111-
'InlineQueryResultCachedVideo',
112-
'InlineQueryResultCachedVoice',
113-
'InlineQueryResultContact',
114-
'InlineQueryResultDocument',
115-
'InlineQueryResultGif',
116-
'InlineQueryResultLocation',
117-
'InlineQueryResultMpeg4Gif',
118-
'InlineQueryResultPhoto',
119-
'InlineQueryResultVenue',
120-
'InlineQueryResultVideo',
121-
'InlineQueryResultVoice',
122-
'InputContactMessageContent',
123-
'InputFile',
124-
'InputLocationMessageContent',
125-
'InputMessageContent',
126-
'InputTextMessageContent',
127-
'InputVenueMessageContent',
128-
'KeyboardButton',
129-
'Location',
130-
'Message',
131-
'MessageEntity',
132-
'NullHandler',
133-
'ParseMode',
134-
'PhotoSize',
135-
'ReplyKeyboardHide',
136-
'ReplyKeyboardMarkup',
137-
'ReplyMarkup',
138-
'Sticker',
139-
'TelegramError',
140-
'TelegramObject',
141-
'Update',
142-
'User',
143-
'UserProfilePhotos',
144-
'Venue',
145-
'Video',
146-
'Voice']
147-
85+
__all__ = ['Audio', 'Bot', 'Chat', 'ChatAction', 'ChosenInlineResult', 'CallbackQuery', 'Contact',
86+
'Document', 'Emoji', 'File', 'ForceReply', 'InlineKeyboardButton',
87+
'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult', 'InlineQueryResult',
88+
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio',
89+
'InlineQueryResultCachedDocument', 'InlineQueryResultCachedGif',
90+
'InlineQueryResultCachedMpeg4Gif', 'InlineQueryResultCachedPhoto',
91+
'InlineQueryResultCachedSticker', 'InlineQueryResultCachedVideo',
92+
'InlineQueryResultCachedVoice', 'InlineQueryResultContact', 'InlineQueryResultDocument',
93+
'InlineQueryResultGif', 'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif',
94+
'InlineQueryResultPhoto', 'InlineQueryResultVenue', 'InlineQueryResultVideo',
95+
'InlineQueryResultVoice', 'InputContactMessageContent', 'InputFile',
96+
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
97+
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
98+
'NullHandler', 'ParseMode', 'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
99+
'ReplyMarkup', 'Sticker', 'TelegramError', 'TelegramObject', 'Update', 'User',
100+
'UserProfilePhotos', 'Venue', 'Video', 'Voice']
148101

149102
if version_info < (2, 7):
150103
from warnings import warn

telegram/audio.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
19-
2019
"""This module contains a object that represents a Telegram Audio."""
2120

2221
from telegram import TelegramObject
@@ -45,10 +44,7 @@ class Audio(TelegramObject):
4544
file_size (Optional[int]):
4645
"""
4746

48-
def __init__(self,
49-
file_id,
50-
duration,
51-
**kwargs):
47+
def __init__(self, file_id, duration, **kwargs):
5248
# Required
5349
self.file_id = str(file_id)
5450
self.duration = int(duration)

telegram/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
19-
2019
"""Base class for Telegram Objects."""
2120

2221
import json

0 commit comments

Comments
 (0)
X Tutup