Skip to content

Commit

Permalink
Merge pull request #3893 from RasaHQ/add-flake8
Browse files Browse the repository at this point in the history
Add flake8 linting, update Makefile
  • Loading branch information
federicotdn committed Jul 4, 2019
2 parents ce43f1a + b4f9671 commit 03204cd
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 27 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ before_script:
jobs:
include:
- stage: test
name: "Black Formatting"
name: "Code Formatting"
python: 3.6
script:
- pip install black
- black --check .
- make lint
- stage: test
name: "Type Check"
python: 3.6
Expand All @@ -52,7 +51,7 @@ jobs:
name: "Test 3.5"
python: "3.5"
script:
- py.test tests --cov rasa
- make test
- <<: *run-tests
name: "Test 3.6"
python: '3.6'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Added
- debug logging now tells you which tracker store is connected
- the response of ``/model/train`` now includes a response header for the trained model filename
- ``Validator`` class to help developing by checking if the files have any errors
- project's code is now linted using flake8

Changed
-------
Expand Down
38 changes: 22 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
.PHONY: clean test lint init check-readme

TEST_PATH=./

help:
@echo " clean"
@echo " Remove python artifacts and build artifacts."
@echo " Remove Python/build artifacts."
@echo " formatter"
@echo " Apply black formatting to code."
@echo " lint"
@echo " Check style with flake8."
@echo " Lint code with flake8, and check if black formatter should be applied."
@echo " types"
@echo " Check for type errors using pytype."
@echo " test"
@echo " Run py.test"
@echo " Run pytest on tests/."
@echo " check-readme"
@echo " Check if the readme can be converted from md to rst for pypi"
@echo " init"
@echo " Install Rasa Core"

init:
pip install -r requirements.txt
@echo " Check if the README can be converted from .md to .rst for PyPI."
@echo " doctest"
@echo " Run all doctests embedded in the documentation."
@echo " livedocs"
@echo " Build the docs locally."

clean:
find . -name '*.pyc' -exec rm -f {} +
Expand All @@ -24,22 +25,27 @@ clean:
rm -rf build/
rm -rf .pytype/
rm -rf dist/
rm -rf *.egg-info
rm -rf docs/_build

formatter:
black rasa tests

lint:
black .
flake8 rasa tests
black --check rasa tests

types:
pytype --keep-going rasa

test: clean
py.test tests --verbose --color=yes $(TEST_PATH)
black --check .
py.test tests --cov rasa

doctest: clean
cd docs && make doctest

livedocs:
cd docs && make livehtml

# if this runs through we can be sure the readme is properly shown on pypi
check-readme:
# if this runs through we can be sure the readme is properly shown on pypi
python setup.py check --restructuredtext --strict
2 changes: 0 additions & 2 deletions rasa/cli/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def train_core(
args.stories, "stories", DEFAULT_DATA_PATH, none_is_valid=True
)

_train_path = train_path or tempfile.mkdtemp()

# Policies might be a list for the compare training. Do normal training
# if only list item was passed.
if not isinstance(args.config, list) or len(args.config) == 1:
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/training/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def read_from_folder(
story_steps.extend(steps)

# if exclusion percentage is not 100
if exclusion_percentage and exclusion_percentage is not 100:
if exclusion_percentage and exclusion_percentage != 100:
import random

idx = int(round(exclusion_percentage / 100.0 * len(story_steps)))
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def from_files(
"""Create an instance from the domain, nlu and story files."""

domain = Domain.load(domain_file)
loop = asyncio.new_event_loop()
asyncio.new_event_loop()
stories = await StoryFileReader.read_from_folder(story_data, domain)
intents = load_data(nlu_data)

Expand Down
2 changes: 1 addition & 1 deletion rasa/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def read_yaml(content: Text) -> Union[List[Any], Dict[Text, Any]]:
# noinspection PyUnresolvedReferences
try:
return yaml_parser.load(content) or {}
except yaml.scanner.ScannerError as _:
except yaml.scanner.ScannerError:
# A `ruamel.yaml.scanner.ScannerError` might happen due to escaped
# unicode sequences that form surrogate pairs. Try converting the input
# to a parsable format based on
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ nbsphinx==0.3.2
aioresponses==0.6.0
moto==1.3.8

# lint/format
black==19.3b0; python_version>='3.6'
flake8==3.7.7

# pipeline dependencies
spacy==2.1.4
jieba==0.39
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ log_cli_level = WARNING
[metadata]
description-file = README.md
license_file = LICENSE.txt

[flake8]
max-line-length = 88
ignore = W503, E121, E126, E211, E225, E501, E203, W391, E402, F401, F811, F405, F403
2 changes: 1 addition & 1 deletion tests/core/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def test_agent_train(tmpdir, default_domain):
assert [s.name for s in loaded.domain.slots] == [s.name for s in agent.domain.slots]

# test policies
assert type(loaded.policy_ensemble) is type(agent.policy_ensemble) # nopep8
assert isinstance(loaded.policy_ensemble, type(agent.policy_ensemble))
assert [type(p) for p in loaded.policy_ensemble.policies] == [
type(p) for p in agent.policy_ensemble.policies
]
Expand Down
2 changes: 1 addition & 1 deletion tests/nlu/base/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_remove_model_invalid(empty_model_dir):
test_file_path = os.path.join(empty_model_dir, test_file)
write_to_file(test_file_path, test_content)

with pytest.raises(ValueError) as e:
with pytest.raises(ValueError):
remove_model(empty_model_dir)

os.remove(test_file_path)
Expand Down

0 comments on commit 03204cd

Please sign in to comment.