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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ install:

script:
# We also smoke test that our release process will work by running `package`.
- ./pants lint test package '::'
- ./pants lint typecheck test package '::'
- ./pants run helloworld/main.py
- ./pants run helloworld/main_py2.py
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,23 @@ Try these out in this repo!
## List targets

```
./pants list helloworld:: # All targets.
./pants list :: # All targets.
./pants list 'helloworld/**/*.py' # Just targets containing Python code.
```

## Run linters and formatters

```
./pants lint helloworld::
./pants lint ::
./pants fmt 'helloworld/**/*.py'
```

## Run MyPy

```
./pants typecheck ::
```

## Run tests

```
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions build-support/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[mypy]
# Optionals
no_implicit_optional = True

# Strictness
allow_untyped_globals = False
allow_redefinition = False
implicit_reexport = False
strict_equality = True

# Warnings
warn_unused_ignores = True
warn_no_return = True
warn_return_any = True
warn_redundant_casts = True
warn_unreachable = True

# Error output
show_column_numbers = True
show_error_context = True
show_error_codes = True
show_traceback = True
pretty = True
color_output = True
error_summary = True

[mypy-colors]
ignore_missing_imports = True

[mypy-translate]
ignore_missing_imports = True

[mypy-pytest]
ignore_missing_imports = True
Empty file added helloworld/greet/__init__.py
Empty file.
4 changes: 3 additions & 1 deletion helloworld/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

def say_hello() -> None:
config = load_config()
greeter = Greeter(languages=config.languages, greetings=config.greetings)
greeter = Greeter(
languages=list(config.languages), greetings=list(config.greetings)
)
sentence = greeter.greet("world")
print(green(sentence))

Expand Down
Empty file added helloworld/util/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions helloworld/util/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import random
from typing import List
from typing import List, cast

from translate import Translator

Expand All @@ -18,7 +18,7 @@ def translate(self, lang: str, phrase: str) -> str:
if lang not in self._langs:
raise self.UnknownLanguage(lang)
translator = Translator(lang)
return translator.translate(phrase)
return cast(str, translator.translate(phrase))

def translate_to_random_language(self, phrase: str) -> str:
return self.translate(self._pick_random_language(), phrase)
Expand Down
12 changes: 11 additions & 1 deletion helloworld/util/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@

# `name` defaults to the name of this directory, i.e., `proto`.
# `sources` defaults to ["*.proto"].
protobuf_library()
protobuf_library(dependencies=[":init"])


# Note that we need an `__init__.py` file for MyPy to recognize our generated code as a valid
# module. We include this in the dependencies for the `protobuf_library` to ensure the
# `__init__.py` is always used.
#
# Often, you won't want to put `__init__.py` files in your Protobuf directories; see
# https://www.pantsbuild.org/docs/protobuf#protobuf-and-source-roots for how to change where the
# protobuf code is generated.
python_library(name="init")
Empty file.
7 changes: 6 additions & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ backend_packages.add = [
'pants.backend.python.lint.black',
'pants.backend.python.lint.flake8',
'pants.backend.python.lint.isort',
'pants.backend.python.typecheck.mypy',
]

# This ensures that the result of `./pants package` is always unique. It will become the default in
Expand All @@ -34,9 +35,13 @@ requirement_constraints = "constraints.txt"
[python-protobuf]
# See https://www.pantsbuild.org/docs/protobuf.
runtime_dependencies = ["//:protobuf"]
mypy_plugin = true

[flake8]
config = ".flake8"
config = "build-support/.flake8"

[isort]
config = [".isort.cfg"]

[mypy]
config = "build-support/mypy.ini"