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