aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAlex Nicksay <nicksay@google.com>2016-12-21 04:17:11 -0500
committerEugene Kliuchnikov <eustas@google.com>2016-12-21 10:17:11 +0100
commit6ab0a5cee7a36b30012066caf6bca9a48fcae958 (patch)
tree23ae6ea4ace6e754de6629a2f3e65c2f7a7ae762 /python
parentfd96151b2a04667dac73242b72bc62e007b2b543 (diff)
downloadbrotli-6ab0a5cee7a36b30012066caf6bca9a48fcae958.zip
brotli-6ab0a5cee7a36b30012066caf6bca9a48fcae958.tar.gz
brotli-6ab0a5cee7a36b30012066caf6bca9a48fcae958.tar.bz2
Python: Create Makefile for development shortcuts (#488)
Diffstat (limited to 'python')
-rw-r--r--python/Makefile49
-rw-r--r--python/README.md33
2 files changed, 68 insertions, 14 deletions
diff --git a/python/Makefile b/python/Makefile
new file mode 100644
index 0000000..cdf3aac
--- /dev/null
+++ b/python/Makefile
@@ -0,0 +1,49 @@
+# Copyright 2016 The Brotli Authors. All rights reserved.
+#
+# Distributed under MIT license.
+# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
+
+
+# Default
+.PHONY: all
+# Build
+.PHONY: build
+# Test
+.PHONY: test tests
+# Clean
+.PHONY: clean
+# Format
+.PHONY: fix
+
+
+PYTHON ?= python
+YAPF ?= yapf
+
+EXT_SUFFIX=$(shell $(PYTHON) -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX"))')
+EXT_SOURCES=$(shell find . -name '*.cc')
+EXTENSIONS=$(EXT_SOURCES:%.cc=%$(EXT_SUFFIX))
+
+
+all: build
+
+build: $(EXTENSIONS)
+
+$(EXTENSIONS): $(EXT_SOURCES)
+ @cd .. && $(PYTHON) setup.py develop
+
+test: tests
+
+tests: build
+ @echo 'running tests'
+ @$(PYTHON) -m unittest discover -p '*_test.py'
+
+clean:
+ @cd .. && $(PYTHON) setup.py clean
+ @find .. -name '*.pyc' | xargs rm -v
+ @find .. -name '*.so' | xargs rm -v
+ @find .. -type d -name '__pycache__' | xargs rm -v -r
+ @find .. -type d -name '*.egg-info' | xargs rm -v -r
+
+fix:
+ @echo 'formatting code'
+ -@$(YAPF) --in-place --recursive --verify .
diff --git a/python/README.md b/python/README.md
index 6f5ce24..60ed84b 100644
--- a/python/README.md
+++ b/python/README.md
@@ -1,38 +1,43 @@
This directory contains the code for the Python `brotli` module,
`bro.py` tool, and roundtrip tests.
+### Installation
-### Development
+If you just want to install the module from source, execute the
+following from the root project directory:
+
+ $ python setup.py install
-To build the module, execute the following from the root project
-directory:
+### Development
- $ python setup.py build
+For development, reinstalling the module with every change is time
+consuming. Instead, we recommend using the `setuptools`
+"[development mode][]" to make the module available while still being
+able to edit the source files.
-To test the module, execute the following from the root project
-directory:
+We provide a `Makefile` to simplify common commands:
- $ python setup.py test
+ $ make # Deploy the module in "development mode"
+
+ $ make tests # Test the module
+ $ make clean # Remove all temporary files and build output
### Code Style
Brotli's code follows the [Google Python Style Guide][]. To
-automatically format your code, install [YAPF][]:
+automatically format your code, first install [YAPF][]:
$ pip install yapf
-Then, either format a single file:
-
- $ yapf --in-place FILE
-
-Or, format all files in a directory:
+Then, to format all files in the project, you can run:
- $ yapf --in-place --recursive DIR
+ $ make fix # Automatically format code
See the [YAPF usage][] documentation for more information.
+[development mode]: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
[Google Python Style Guide]: https://google.github.io/styleguide/pyguide.html
[YAPF]: https://github.com/google/yapf
[YAPF usage]: https://github.com/google/yapf#usage