Skip to content

Commit 41c553d

Browse files
committed
Normalize tox, Makefile, setup.py with lim-cli
1 parent f5ac555 commit 41c553d

File tree

4 files changed

+114
-44
lines changed

4 files changed

+114
-44
lines changed

.travis.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ matrix:
2828
env: TOXENV=pypi
2929

3030

31-
before_script:
32-
- git clone https://github.com/ztombol/bats-support.git ../bats-support
33-
- git clone https://github.com/jasonkarns/bats-assert-1.git ../bats-assert-1
34-
3531
branches:
3632
only:
3733
- master
3834
- develop
3935

4036
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
4137
install:
42-
- pip install .
43-
- pip install -r requirements.txt
38+
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
39+
- bash miniconda.sh -b -p $HOME/miniconda
40+
- export PATH=$HOME/miniconda/bin:$PATH
41+
- source "$HOME/miniconda/etc/profile.d/conda.sh"
42+
- hash -r
43+
- conda config --set always_yes yes --set changeps1 no
44+
- conda update --yes conda # Update CONDA without command line prompt
45+
- conda install -c conda-forge --yes tox
46+
# Useful for debugging any issues with conda
47+
- conda info -a
4448

4549
# command to run tests, e.g. python setup.py test
4650
script:

Makefile

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,42 @@ VERSION=$(shell cat VERSION)
55
REQUIRED_VENV:=python_secrets
66
VENV_DIR=$(HOME)/.virtualenvs/$(REQUIRED_VENV)
77
PROJECT:=$(shell basename `pwd`)
8+
PYTHON=python3
89

910
.PHONY: default
1011
default: all
1112

1213
.PHONY: all
1314
all: install-active
1415

16+
.PHONY: help
17+
help:
18+
@echo 'usage: make [VARIABLE=value] [target [target..]]'
19+
@echo ''
20+
@echo 'test - generic target for both "test-tox" and "test-bats"'
21+
@echo 'test-tox - run tox tests'
22+
@echo 'test-bats - run Bats unit tests'
23+
@echo 'test-bats-runtime - run Bats runtime integration/system tests'
24+
@echo 'release - produce a pypi production release'
25+
@echo 'release-test - produce a pypi test release'
26+
@echo 'release-prep - final documentation preparations for release'
27+
@echo 'sdist - run "$(PYTHON) setup.py sdist"'
28+
@echo 'bdist_wheel - build a universal binary wheel'
29+
@echo 'twine-check - run "twine check"'
30+
@echo 'clean - remove build artifacts'
31+
@echo 'spotless - deep clean'
32+
@echo 'build-packet-cafe - Build and bring up packet_cafe containers'
33+
@echo 'up-packet-cafe - Bring up packet_cafe containers'
34+
@echo 'down-packet-cafe - Bring up packet_cafe containers'
35+
@echo 'clean-packet-cafe - remove packet_cafe contents'
36+
@echo 'spotless-packet-cafe - Remove all packet_cafe files and containers'
37+
@echo 'install - install pip package'
38+
@echo 'install-active - run "$(PYTHON) -m pip install -U ."'
39+
@echo 'docs-tests - generate bats test output for documentation'
40+
@echo 'docs-help - generate "lim help" output for documentation'
41+
@echo 'docs - build Sphinx docs'
42+
43+
1544
#HELP test - run 'tox' for testing
1645
.PHONY: test
1746
test: test-tox
@@ -21,25 +50,25 @@ test: test-tox
2150
test-tox:
2251
@if [ -f .python_secrets_environment ]; then (echo '[!] Remove .python_secrets_environment prior to testing'; exit 1); fi
2352
touch docs/psec_help.txt
24-
tox
53+
@# See comment in tox.ini file.
54+
tox -e pep8,bandit,docs && tox -e py36,py37,py38,bats,pypi
55+
@-git checkout ChangeLog
2556

2657
.PHONY: test-bats
2758
test-bats: bats-libraries
2859
@if [ "$(TRAVIS)" != "true" ]; then \
2960
if ! type bats 2>/dev/null >/dev/null; then \
3061
echo "[-] Skipping bats tests"; \
3162
else \
32-
echo "[+] Running bats unit tests:"; \
33-
(cd tests && ls -1 [0-9][0-9]*.bats); \
34-
bats --tap tests/[0-9][0-9]*.bats; \
63+
echo "[+] Running bats tests: $(shell cd tests && echo [0-9][0-9]*.bats)"; \
64+
PYTHONWARNINGS="ignore" bats --tap tests/[0-9][0-9]*.bats; \
3565
fi \
3666
fi
3767

3868
.PHONY: test-bats-runtime
3969
test-bats-runtime: bats-libraries
40-
@echo "[+] Running bats runtime tests:"
41-
@cd tests && ls -1 runtime_[0-9][0-9]*.bats
42-
bats --tap tests/runtime_*.bats || true
70+
@echo "[+] Running bats runtime tests: $(shell cd tests && echo runtime_[0-9][0-9]*.bats)"; \
71+
PYTHONWARNINGS="ignore" bats --tap tests/runtime_[0-9][0-9]*.bats
4372

4473
.PHONY: no-diffs
4574
no-diffs:
@@ -48,39 +77,44 @@ no-diffs:
4877

4978
#HELP release - package and upload a release to pypi
5079
.PHONY: release
51-
release: clean twine-check
80+
release: clean docs sdist bdist_wheel twine-check
5281
twine upload $(shell cat dist/.LATEST_*) -r pypi
5382

83+
#HELP release-prep - final documentation preparations for release
84+
.PHONY: release-prep
85+
release-prep: install-active clean sdist docs-help docs-tests
86+
@echo 'Check in help text docs and ChangeLog?'
87+
5488
#HELP release-test - upload to "testpypi"
5589
.PHONY: release-test
5690
release-test: clean test docs-tests docs twine-check
5791
$(MAKE) no-diffs
5892
twine upload $(shell cat dist/.LATEST_*) -r testpypi
5993

94+
#HELP sdist - build a source package
95+
.PHONY: sdist
96+
sdist: clean-docs docs
97+
rm -f dist/.LATEST_SDIST
98+
$(PYTHON) setup.py sdist
99+
ls -t dist/*.tar.gz 2>/dev/null | head -n 1 > dist/.LATEST_SDIST
100+
ls -l dist/*.tar.gz
101+
60102
#HELP bdist_egg - build an egg package
61103
.PHONY: bdist_egg
62104
bdist_egg:
63105
rm -f dist/.LATEST_EGG
64-
python setup.py bdist_egg
106+
$(PYTHON) setup.py bdist_egg
65107
ls -t dist/*.egg 2>/dev/null | head -n 1 > dist/.LATEST_EGG
66108
ls -lt dist/*.egg
67109

68110
#HELP bdist_wheel - build a wheel package
69111
.PHONY: bdist_wheel
70112
bdist_wheel:
71113
rm -f dist/.LATEST_WHEEL
72-
python setup.py bdist_wheel
114+
$(PYTHON) setup.py bdist_wheel
73115
ls -t dist/*.whl 2>/dev/null | head -n 1 > dist/.LATEST_WHEEL
74116
ls -lt dist/*.whl
75117

76-
#HELP sdist - build a source package
77-
.PHONY: sdist
78-
sdist: clean-docs docs
79-
rm -f dist/.LATEST_SDIST
80-
python setup.py sdist
81-
ls -t dist/*.tar.gz 2>/dev/null | head -n 1 > dist/.LATEST_SDIST
82-
ls -l dist/*.tar.gz
83-
84118
#HELP twine-check
85119
.PHONY: twine-check
86120
twine-check: sdist bdist_egg bdist_wheel
@@ -89,7 +123,7 @@ twine-check: sdist bdist_egg bdist_wheel
89123
#HELP clean - remove build artifacts
90124
.PHONY: clean
91125
clean: clean-docs
92-
python setup.py clean
126+
$(PYTHON) setup.py clean
93127
rm -rf dist build *.egg-info
94128
find . -name '*.pyc' -delete
95129

@@ -109,23 +143,36 @@ install:
109143
exit 1; \
110144
else \
111145
echo "Installing into $(REQUIRED_VENV) virtual environment"; \
112-
$(VENV_DIR)/bin/python -m pip uninstall -y $(PROJECT); \
113-
$(VENV_DIR)/bin/python setup.py install; \
146+
$(VENV_DIR)/bin/$(PYTHON) -m pip uninstall -y $(PROJECT); \
147+
$(VENV_DIR)/bin/$(PYTHON) setup.py install; \
114148
fi
115149

116150
#HELP install-active - install in the active Python virtual environment
151+
.PHONY: i
117152
.PHONY: install-active
118-
install-active:
119-
python -m pip install -U .
153+
i install-active: bdist_wheel
154+
$(PYTHON) -m pip uninstall -y $(PROJECT)
155+
$(PYTHON) -m pip install -U "dist/$(shell cat dist/.LATEST_WHEEL)" | grep -v 'already satisfied'
156+
git checkout ChangeLog
120157

121158
#HELP docs-tests - generate bats test output for documentation
122159
.PHONY: docs-tests
123160
PR=pr --omit-header --omit-pagination --page-width 80
124161
docs-tests:
162+
$(MAKE) -B docs/test-tox.txt
163+
$(MAKE) -B docs/test-bats.txt
164+
$(MAKE) -B docs/test-bats-runtime.txt
165+
166+
docs/test-tox.txt:
125167
(echo '$$ make test-tox' && $(MAKE) test-tox) |\
126168
$(PR) | tee docs/test-tox.txt
169+
170+
docs/test-bats.txt:
127171
$(MAKE) test-bats | $(PR) | tee docs/test-bats.txt
128172

173+
docs/test-bats-runtime.txt:
174+
(echo '$$ make test-bats-runtime' && $(MAKE) test-bats-runtime) |\
175+
$(PR) | tee docs/test-bats-runtime.txt
129176

130177
#HELP docs - build Sphinx docs (NOT INTEGRATED YET FROM OPENSTACK CODE BASE)
131178
.PHONY: docs
@@ -135,6 +182,11 @@ docs: docs/psec_help.txt
135182
docs/psec_help.txt: install-active
136183
psec help | tee docs/psec_help.txt
137184

185+
#HELP examples - produce some example output for docs
186+
.PHONY: examples
187+
examples:
188+
psec --help
189+
138190
# Git submodules and subtrees are both a huge PITA. This is way simpler.
139191

140192
.PHONY: bats-libraries

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def get_absolute_path(*args):
8282
'Intended Audience :: Other Audience',
8383
'Intended Audience :: Science/Research',
8484
'Intended Audience :: System Administrators',
85-
'Operating System :: OS Independent',
8685
'License :: OSI Approved :: Apache Software License',
8786
'Natural Language :: English',
87+
'Operating System :: OS Independent',
8888
'Programming Language :: Python :: 3',
8989
'Programming Language :: Python :: 3.6',
9090
'Programming Language :: Python :: 3.7',

tox.ini

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
[tox]
2-
envlist = py36,py37,py38,py39,pep8,bandit,bats,docs,pypi
2+
# In practice, you can optimize by first running basic tests
3+
# 'pep8,bandit,docs' and only after those succeed go on to
4+
# run the remaining (default) tests. E.g.,
5+
# $ tox -e pep8,bandit,docs && tox -e py36,py37,py38,bats,pypi
6+
7+
# envlist = pep8,bandit,docs,py36,py37,py38,bats,pypi
8+
envlist = py36,py37,py38,bats,pypi
39
skip_missing_interpreters = true
4-
requires =
5-
setuptools >= 40.9.0
6-
pip >= 20.1
10+
requires = tox-conda
711

812
[testenv]
913
setenv =
@@ -12,9 +16,17 @@ setenv =
1216
PYTHONPATH={toxinidir}:{toxinidir}/psec
1317
distribute = False
1418
install_command = python -m pip install {opts} {packages}
15-
deps = -r{toxinidir}/requirements.txt
19+
conda_deps =
20+
pytest
21+
conda_channels =
22+
conda-forge
23+
# Make sure these match setup.py!
24+
deps = -Ur{toxinidir}/requirements.txt
25+
setuptools>=40.9.0
26+
pbr>=5.4.5
27+
pip>=20.2.2
1628
pytest
17-
commands = pytest
29+
commands = pytest {posargs}
1830

1931
; If you want to make tox run the tests with the same versions, create a
2032
; requirements.txt with the pinned versions and uncomment the following lines:
@@ -28,15 +40,21 @@ commands = make twine-check
2840

2941
[testenv:pep8]
3042
basepython = python3.8
31-
deps = flake8
43+
deps = flake8>=3.8.3
3244
commands = flake8 psec docs/conf.py setup.py
3345

3446
[testenv:bandit]
3547
basepython = python3.8
3648
; Run security linter
37-
deps = bandit
49+
deps = bandit>=1.1.0
3850
commands = bandit -c bandit.yaml -r psec -x tests -n5
3951

52+
[testenv:docs]
53+
basepython = python3.8
54+
deps = -Ur{toxinidir}/requirements.txt
55+
sphinx
56+
commands = sphinx-build -b html docs docs/_build
57+
4058
[testenv:bats]
4159
; Run bats unit tests
4260
; Deal with this by requiring docutils==0.15:
@@ -50,12 +68,8 @@ commands = bandit -c bandit.yaml -r psec -x tests -n5
5068
; # File "/Users/dittrich/git/python_secrets/.tox/bats/lib/python3.7/site-packages/pkg_resources/__init__.py", line 792, in resolve
5169
; # raise VersionConflict(dist, req).with_context(dependent_req)
5270
; # pkg_resources.ContextualVersionConflict: (docutils 0.16 (/Users/dittrich/git/python_secrets/.tox/bats/lib/python3.7/site-packages), Requirement.parse('docutils<0.16,>=0.10'), {'botocore'})
53-
deps = docutils==0.15
71+
deps = -Ur{toxinidir}/requirements.txt
72+
docutils==0.15
5473
whitelist_externals = make
5574
commands = make test-bats
5675

57-
[testenv:docs]
58-
basepython = python3.8
59-
deps = -Ur{toxinidir}/requirements.txt
60-
sphinx
61-
commands = sphinx-build -b html docs docs/build/html

0 commit comments

Comments
 (0)