diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | python/Makefile | 49 | ||||
-rw-r--r-- | python/README.md | 33 |
3 files changed, 71 insertions, 17 deletions
@@ -51,12 +51,12 @@ See [Premake5](https://premake.github.io/) #### Python -The basic commands to build, test, and install the Python module are: +To install the Python module from source, run the following: - $ python setup.py build test $ python setup.py install -See the [Python readme](python/README.md) for more details. +See the [Python readme](python/README.md) for more details on testing +and development. ### Benchmarks * [Squash Compression Benchmark](https://quixdb.github.io/squash-benchmark/) / [Unstable Squash Compression Benchmark](https://quixdb.github.io/squash-benchmark/unstable/) 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 |