1 | # Copyright (C) 2003-2017, Stefan Schwarzer <sschwarzer@sschwarzer.net> |
---|
2 | # and ftputil contributors (see `doc/contributors.txt`) |
---|
3 | # See the file LICENSE for licensing terms. |
---|
4 | |
---|
5 | # This Makefile requires GNU Make. |
---|
6 | |
---|
7 | SHELL=/bin/sh |
---|
8 | PROJECT_DIR=$(shell pwd) |
---|
9 | VERSION=$(shell cat VERSION) |
---|
10 | PYTHON_BINARY?=python2 |
---|
11 | # Depending on the development system, this may be `pytest`, `py.test` |
---|
12 | # or even something else. |
---|
13 | PYTEST=pytest |
---|
14 | |
---|
15 | TEST_DIR=${PROJECT_DIR}/test |
---|
16 | |
---|
17 | SOURCE_DIR=${PROJECT_DIR}/ftputil |
---|
18 | |
---|
19 | DOC_DIR=${PROJECT_DIR}/doc |
---|
20 | STYLESHEET_PATH=${DOC_DIR}/default.css |
---|
21 | DOC_SOURCES=$(subst d/,${DOC_DIR}/, d/ftputil.txt \ |
---|
22 | d/whats_new_in_ftputil_3.0.txt) |
---|
23 | DOC_TARGETS=$(subst d/,${DOC_DIR}/, d/ftputil.html \ |
---|
24 | d/whats_new_in_ftputil_3.0.html) |
---|
25 | |
---|
26 | SED=sed -i'' -r -e |
---|
27 | |
---|
28 | PYTHONPATH=${PROJECT_DIR}:${TEST_DIR} |
---|
29 | |
---|
30 | #TODO Some platforms call that script rst2html.py - allow both. |
---|
31 | RST2HTML=rst2html |
---|
32 | |
---|
33 | # Name test files. Make sure the long-running tests come last. |
---|
34 | TEST_FILES=$(shell ls -1 ${TEST_DIR}/test_*.py | \ |
---|
35 | grep -v "test_real_ftp.py" | \ |
---|
36 | grep -v "test_public_servers.py" ) \ |
---|
37 | ${TEST_DIR}/test_real_ftp.py \ |
---|
38 | ${TEST_DIR}/test_public_servers.py |
---|
39 | |
---|
40 | .PHONY: dist extdist test tox_test coverage pylint \ |
---|
41 | find_missing_unicode_literals \ |
---|
42 | docs clean cleanorig upload patch remove_from_env |
---|
43 | |
---|
44 | # Patch various files to refer to a new version. |
---|
45 | patch: |
---|
46 | @echo "Patching files" |
---|
47 | ${SED} "s/^__version__ = \".*\"/__version__ = \"${VERSION}\"/" \ |
---|
48 | ${SOURCE_DIR}/version.py |
---|
49 | ${SED} "s/^:Version: .*/:Version: ${VERSION}/" \ |
---|
50 | ${DOC_DIR}/ftputil.txt |
---|
51 | ${SED} "s/^:Date: .*/:Date: `date +"%Y-%m-%d"`/" \ |
---|
52 | ${DOC_DIR}/ftputil.txt |
---|
53 | ${SED} "s/^Version: .*/Version: ${VERSION}/" PKG-INFO |
---|
54 | ${SED} "s/(\/wiki\/Download\/ftputil-).*(\.tar\.gz)/\1${VERSION}\2/" \ |
---|
55 | PKG-INFO |
---|
56 | |
---|
57 | # Documentation |
---|
58 | vpath %.txt ${DOC_DIR} |
---|
59 | |
---|
60 | docs: ${DOC_SOURCES} ${DOC_TARGETS} |
---|
61 | |
---|
62 | %.html: %.txt |
---|
63 | ${RST2HTML} --stylesheet-path=${STYLESHEET_PATH} --embed-stylesheet $< $@ |
---|
64 | |
---|
65 | # Quality assurance |
---|
66 | test: |
---|
67 | @echo -e "=== Running fast tests for ftputil ${VERSION} ===\n" |
---|
68 | ${PYTEST} -m "not slow_test" test |
---|
69 | |
---|
70 | # Alternative for symmetry with target `all_tests` |
---|
71 | tests: test |
---|
72 | |
---|
73 | all_tests: |
---|
74 | @echo -e "=== Running all tests for ftputil ${VERSION} ===\n" |
---|
75 | ${PYTEST} test |
---|
76 | |
---|
77 | tox_test: |
---|
78 | # Gets settings from `tox.ini` |
---|
79 | tox |
---|
80 | |
---|
81 | coverage: |
---|
82 | py.test --cov ftputil --cov-report html test |
---|
83 | |
---|
84 | pylint: |
---|
85 | pylint --rcfile=pylintrc ${PYLINT_OPTS} ${SOURCE_DIR}/*.py | less |
---|
86 | |
---|
87 | find_missing_unicode_literals: |
---|
88 | find ftputil test -name "*.py" \ |
---|
89 | -exec grep -L "from __future__ import unicode_literals" {} \; |
---|
90 | |
---|
91 | # Make a distribution tarball. |
---|
92 | dist: clean patch pylint docs |
---|
93 | ${PYTHON_BINARY} setup.py sdist |
---|
94 | |
---|
95 | extdist: all_tests dist upload |
---|
96 | |
---|
97 | # Upload package to PyPI. |
---|
98 | upload: |
---|
99 | @echo "Uploading new version to PyPI" |
---|
100 | ${PYTHON_BINARY} setup.py sdist upload |
---|
101 | |
---|
102 | # Remove files with `orig` suffix (caused by `hg revert`). |
---|
103 | cleanorig: |
---|
104 | find ${PROJECT_DIR} -name '*.orig' -exec rm {} \; |
---|
105 | |
---|
106 | # Remove generated files (but no distribution packages). |
---|
107 | clean: |
---|
108 | rm -f ${DOC_TARGETS} |
---|
109 | # Use absolute path to ensure we delete the right directory. |
---|
110 | rm -rf ${PROJECT_DIR}/build |
---|
111 | find ${PROJECT_DIR} -type f -name "*.pyc" -exec rm {} \; |
---|
112 | find ${PROJECT_DIR} -type d -name "__pycache__" -exec rm -r {} \; |
---|
113 | |
---|
114 | # Help testing test installations. Note that `pip uninstall` |
---|
115 | # doesn't work if the package wasn't installed with pip. |
---|
116 | remove_from_env: |
---|
117 | rm -rf ${VIRTUAL_ENV}/doc/ftputil |
---|
118 | rm -rf ${VIRTUAL_ENV}/lib/python2.7/site-packages/ftputil |
---|