Merge ~peppepetra/charm-sudo-pair:makefile-20.08 into charm-sudo-pair:master
- Git
- lp:~peppepetra/charm-sudo-pair
- makefile-20.08
- Merge into master
Proposed by
Giuseppe Petralia
Status: | Merged |
---|---|
Approved by: | Xav Paice |
Approved revision: | 421e6853e4098e11025c4e180215b1eeb76c604e |
Merged at revision: | 421e6853e4098e11025c4e180215b1eeb76c604e |
Proposed branch: | ~peppepetra/charm-sudo-pair:makefile-20.08 |
Merge into: | charm-sudo-pair:master |
Diff against target: |
441 lines (+133/-78) 9 files modified
.gitignore (+24/-16) Makefile (+60/-33) dev/null (+0/-1) interfaces/.empty (+0/-0) layers/.empty (+0/-0) src/actions/remove-sudopair (+1/-0) src/tests/functional/conftest.py (+1/-1) src/tests/functional/test_deploy.py (+2/-2) src/tox.ini (+45/-25) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Xav Paice (community) | Approve | ||
Paul Goins | Approve | ||
Review via email: mp+388996@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Xav Paice (xavpaice) wrote : | # |
LGTM, agreed on the things that could be cleaned up but I don't want to delay this change for those.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/.gitignore b/.gitignore |
2 | index eda8bea..6f1f367 100644 |
3 | --- a/.gitignore |
4 | +++ b/.gitignore |
5 | @@ -1,33 +1,41 @@ |
6 | +# Juju files |
7 | +.unit-state.db |
8 | +.go-cookies |
9 | + |
10 | +layers/* |
11 | +interfaces/* |
12 | + |
13 | # Byte-compiled / optimized / DLL files |
14 | __pycache__/ |
15 | *.py[cod] |
16 | *$py.class |
17 | |
18 | +# Tests files and dir |
19 | +.pytest_cache/ |
20 | +.coverage |
21 | +.tox |
22 | +report/ |
23 | +htmlcov/ |
24 | + |
25 | # Log files |
26 | *.log |
27 | |
28 | -.tox/ |
29 | -src/.tox/ |
30 | -.coverage |
31 | +# pycharm |
32 | +.idea/ |
33 | |
34 | # vi |
35 | .*.swp |
36 | |
37 | -# pycharm |
38 | -.idea/ |
39 | -.unit-state.db |
40 | -src/.unit-state.db |
41 | - |
42 | # version data |
43 | repo-info |
44 | +version |
45 | |
46 | +# Python builds |
47 | +deb_dist/ |
48 | +dist/ |
49 | |
50 | -# reports |
51 | -report/* |
52 | -src/report/* |
53 | - |
54 | -# virtual env |
55 | -venv/* |
56 | +# Snaps |
57 | +*.snap |
58 | |
59 | -# builds |
60 | -builds/* |
61 | \ No newline at end of file |
62 | +# Builds |
63 | +.build/ |
64 | \ No newline at end of file |
65 | diff --git a/Makefile b/Makefile |
66 | index c7506b2..0a84b5f 100644 |
67 | --- a/Makefile |
68 | +++ b/Makefile |
69 | @@ -1,53 +1,80 @@ |
70 | -PROJECTPATH = $(dir $(realpath $(MAKEFILE_LIST))) |
71 | -DIRNAME = $(notdir $(PROJECTPATH:%/=%)) |
72 | +PYTHON := /usr/bin/python3 |
73 | |
74 | +PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST))) |
75 | ifndef CHARM_BUILD_DIR |
76 | - CHARM_BUILD_DIR := /tmp/$(DIRNAME)-builds |
77 | - $(warning Warning CHARM_BUILD_DIR was not set, defaulting to $(CHARM_BUILD_DIR)) |
78 | + CHARM_BUILD_DIR=${PROJECTPATH}.build |
79 | endif |
80 | +ifndef CHARM_LAYERS_DIR |
81 | + CHARM_LAYERS_DIR=${PROJECTPATH}/layers |
82 | +endif |
83 | +ifndef CHARM_INTERFACES_DIR |
84 | + CHARM_INTERFACES_DIR=${PROJECTPATH}/interfaces |
85 | +endif |
86 | +METADATA_FILE="src/metadata.yaml" |
87 | +CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E "^name:" | awk '{print $$2}') |
88 | |
89 | help: |
90 | @echo "This project supports the following targets" |
91 | @echo "" |
92 | @echo " make help - show this text" |
93 | - @echo " make lint - run flake8" |
94 | - @echo " make test - run the functional tests, unittests and lint" |
95 | - @echo " make unittest - run the tests defined in the unittest subdirectory" |
96 | - @echo " make functional - run the tests defined in the functional subdirectory" |
97 | - @echo " make release - build the charm" |
98 | @echo " make clean - remove unneeded files" |
99 | + @echo " make submodules - make sure that the submodules are up-to-date" |
100 | + @echo " make submodules-update - update submodules to latest changes on remote branch" |
101 | + @echo " make build - build the charm" |
102 | + @echo " make release - run clean, submodules, and build targets" |
103 | + @echo " make lint - run flake8 and black --check" |
104 | + @echo " make black - run black and reformat files" |
105 | + @echo " make proof - run charm proof" |
106 | + @echo " make unittests - run the tests defined in the unittest subdirectory" |
107 | + @echo " make functional - run the tests defined in the functional subdirectory" |
108 | + @echo " make test - run lint, proof, unittests and functional targets" |
109 | @echo "" |
110 | |
111 | -lint: |
112 | - @echo "Running flake8" |
113 | - @tox -e lint |
114 | - |
115 | -test: lint unittest functional |
116 | +clean: |
117 | + @echo "Cleaning files" |
118 | + @git clean -ffXd -e '!.idea' |
119 | + @echo "Cleaning existing build" |
120 | + @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME} |
121 | |
122 | -functional: build |
123 | - @PYTEST_KEEP_MODEL=$(PYTEST_KEEP_MODEL) \ |
124 | - PYTEST_CLOUD_NAME=$(PYTEST_CLOUD_NAME) \ |
125 | - PYTEST_CLOUD_REGION=$(PYTEST_CLOUD_REGION) \ |
126 | - tox -e functional |
127 | +submodules: |
128 | + # @git submodule update --init --recursive |
129 | + @echo "No submodules. Skipping." |
130 | |
131 | -unittest: |
132 | - @tox -e unit |
133 | +submodules-update: |
134 | + # @git submodule update --init --recursive --remote --merge |
135 | + @echo "No submodules. Skipping." |
136 | |
137 | build: |
138 | - @echo "Building charm to base directory $(CHARM_BUILD_DIR)" |
139 | - @-git describe --tags > ./repo-info |
140 | - @CHARM_LAYERS_DIR=./layers CHARM_INTERFACES_DIR=./interfaces TERM=linux\ |
141 | - charm build --output-dir $(CHARM_BUILD_DIR) $(PROJECTPATH) --force |
142 | + @echo "Building charm to directory ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
143 | + @-git rev-parse --abbrev-ref HEAD > ./src/repo-info |
144 | + @CHARM_LAYERS_DIR=${CHARM_LAYERS_DIR} CHARM_INTERFACES_DIR=${CHARM_INTERFACES_DIR} \ |
145 | + TERM=linux CHARM_BUILD_DIR=${CHARM_BUILD_DIR} charm build src/ |
146 | |
147 | release: clean build |
148 | - @echo "Charm is built at $(CHARM_BUILD_DIR)/builds" |
149 | + @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
150 | |
151 | -clean: |
152 | - @echo "Cleaning files" |
153 | - @find $(PROJECTPATH) -iname __pycache__ -exec rm -r {} + |
154 | - @if [ -d $(CHARM_BUILD_DIR)/builds ] ; then rm -r $(CHARM_BUILD_DIR)/builds ; fi |
155 | - @if [ -d $(PROJECTPATH)/.tox ] ; then rm -r $(PROJECTPATH)/.tox ; fi |
156 | - @if [ -d $(PROJECTPATH)/.pytest_cache ] ; then rm -r $(PROJECTPATH)/.pytest_cache ; fi |
157 | +lint: |
158 | + @echo "Running lint checks" |
159 | + @cd src && tox -e lint |
160 | + |
161 | +black: |
162 | + @echo "Reformat files with black" |
163 | + @cd src && tox -e black |
164 | + |
165 | +proof: build |
166 | + @echo "Running charm proof" |
167 | + @charm proof ${CHARM_BUILD_DIR}/${CHARM_NAME} |
168 | + |
169 | +unittests: |
170 | + @echo "Running unit tests" |
171 | + @cd src && tox -e unit |
172 | + |
173 | +functional: build |
174 | + @echo "Executing functional tests in ${CHARM_BUILD_DIR}" |
175 | + @cd src && CHARM_BUILD_DIR=${CHARM_BUILD_DIR} tox -e func |
176 | + |
177 | +test: lint proof unittests functional |
178 | + @echo "Tests completed for charm ${CHARM_NAME}." |
179 | |
180 | # The targets below don't depend on a file |
181 | -.PHONY: lint test unittest functional build release clean help |
182 | +.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test |
183 | diff --git a/actions/remove-sudopair b/actions/remove-sudopair |
184 | deleted file mode 120000 |
185 | index ff9536b..0000000 |
186 | --- a/actions/remove-sudopair |
187 | +++ /dev/null |
188 | @@ -1 +0,0 @@ |
189 | -./actions.py |
190 | \ No newline at end of file |
191 | diff --git a/interfaces/.empty b/interfaces/.empty |
192 | new file mode 100644 |
193 | index 0000000..e69de29 |
194 | --- /dev/null |
195 | +++ b/interfaces/.empty |
196 | diff --git a/layers/.empty b/layers/.empty |
197 | new file mode 100644 |
198 | index 0000000..e69de29 |
199 | --- /dev/null |
200 | +++ b/layers/.empty |
201 | diff --git a/README.md b/src/README.md |
202 | similarity index 100% |
203 | rename from README.md |
204 | rename to src/README.md |
205 | diff --git a/actions.yaml b/src/actions.yaml |
206 | similarity index 100% |
207 | rename from actions.yaml |
208 | rename to src/actions.yaml |
209 | diff --git a/actions/actions.py b/src/actions/actions.py |
210 | similarity index 100% |
211 | rename from actions/actions.py |
212 | rename to src/actions/actions.py |
213 | diff --git a/src/actions/remove-sudopair b/src/actions/remove-sudopair |
214 | new file mode 120000 |
215 | index 0000000..ff9536b |
216 | --- /dev/null |
217 | +++ b/src/actions/remove-sudopair |
218 | @@ -0,0 +1 @@ |
219 | +./actions.py |
220 | \ No newline at end of file |
221 | diff --git a/config.yaml b/src/config.yaml |
222 | similarity index 100% |
223 | rename from config.yaml |
224 | rename to src/config.yaml |
225 | diff --git a/files/sudo.prompt.pair b/src/files/sudo.prompt.pair |
226 | similarity index 100% |
227 | rename from files/sudo.prompt.pair |
228 | rename to src/files/sudo.prompt.pair |
229 | diff --git a/files/sudo.prompt.user b/src/files/sudo.prompt.user |
230 | similarity index 100% |
231 | rename from files/sudo.prompt.user |
232 | rename to src/files/sudo.prompt.user |
233 | diff --git a/files/sudo_pair.so b/src/files/sudo_pair.so |
234 | similarity index 100% |
235 | rename from files/sudo_pair.so |
236 | rename to src/files/sudo_pair.so |
237 | Binary files a/files/sudo_pair.so and b/src/files/sudo_pair.so differ |
238 | diff --git a/files/sudoers b/src/files/sudoers |
239 | similarity index 100% |
240 | rename from files/sudoers |
241 | rename to src/files/sudoers |
242 | diff --git a/layer.yaml b/src/layer.yaml |
243 | similarity index 100% |
244 | rename from layer.yaml |
245 | rename to src/layer.yaml |
246 | diff --git a/lib/libsudopair.py b/src/lib/libsudopair.py |
247 | similarity index 100% |
248 | rename from lib/libsudopair.py |
249 | rename to src/lib/libsudopair.py |
250 | diff --git a/metadata.yaml b/src/metadata.yaml |
251 | similarity index 100% |
252 | rename from metadata.yaml |
253 | rename to src/metadata.yaml |
254 | diff --git a/reactive/sudo_pair.py b/src/reactive/sudo_pair.py |
255 | similarity index 100% |
256 | rename from reactive/sudo_pair.py |
257 | rename to src/reactive/sudo_pair.py |
258 | diff --git a/templates/91-bypass-sudopair-cmds.tmpl b/src/templates/91-bypass-sudopair-cmds.tmpl |
259 | similarity index 100% |
260 | rename from templates/91-bypass-sudopair-cmds.tmpl |
261 | rename to src/templates/91-bypass-sudopair-cmds.tmpl |
262 | diff --git a/templates/sudo.conf.tmpl b/src/templates/sudo.conf.tmpl |
263 | similarity index 100% |
264 | rename from templates/sudo.conf.tmpl |
265 | rename to src/templates/sudo.conf.tmpl |
266 | diff --git a/templates/sudo_approve.tmpl b/src/templates/sudo_approve.tmpl |
267 | similarity index 100% |
268 | rename from templates/sudo_approve.tmpl |
269 | rename to src/templates/sudo_approve.tmpl |
270 | diff --git a/tests/00-unit b/src/tests/00-unit |
271 | similarity index 100% |
272 | rename from tests/00-unit |
273 | rename to src/tests/00-unit |
274 | diff --git a/tests/01-functional b/src/tests/01-functional |
275 | similarity index 100% |
276 | rename from tests/01-functional |
277 | rename to src/tests/01-functional |
278 | diff --git a/tests/functional/conftest.py b/src/tests/functional/conftest.py |
279 | similarity index 99% |
280 | rename from tests/functional/conftest.py |
281 | rename to src/tests/functional/conftest.py |
282 | index aa42a09..68f3ffe 100644 |
283 | --- a/tests/functional/conftest.py |
284 | +++ b/src/tests/functional/conftest.py |
285 | @@ -43,7 +43,7 @@ async def model(controller): |
286 | model = await controller.add_model(model_name) |
287 | yield model |
288 | await model.disconnect() |
289 | - if os.getenv('test_preserve_model'): |
290 | + if os.getenv('PYTEST_KEEP_MODEL'): |
291 | return |
292 | await controller.destroy_model(model_name) |
293 | while model_name in await controller.list_models(): |
294 | diff --git a/tests/functional/requirements.txt b/src/tests/functional/requirements.txt |
295 | similarity index 100% |
296 | rename from tests/functional/requirements.txt |
297 | rename to src/tests/functional/requirements.txt |
298 | diff --git a/tests/functional/test_deploy.py b/src/tests/functional/test_deploy.py |
299 | similarity index 98% |
300 | rename from tests/functional/test_deploy.py |
301 | rename to src/tests/functional/test_deploy.py |
302 | index 2f0f272..1d531d1 100644 |
303 | --- a/tests/functional/test_deploy.py |
304 | +++ b/src/tests/functional/test_deploy.py |
305 | @@ -6,10 +6,10 @@ import pytest |
306 | |
307 | pytestmark = pytest.mark.asyncio |
308 | |
309 | -charm_build_dir = os.getenv("CHARM_BUILD_DIR", "..").rstrip("/") |
310 | +charm_build_dir = os.getenv("CHARM_BUILD_DIR").rstrip("/") |
311 | |
312 | |
313 | -sources = [("local", "{}/builds/sudo-pair".format(charm_build_dir))] |
314 | +sources = [("local", "{}/sudo-pair".format(charm_build_dir))] |
315 | |
316 | series = [ |
317 | "xenial", |
318 | diff --git a/tests/tests.yaml b/src/tests/tests.yaml |
319 | similarity index 100% |
320 | rename from tests/tests.yaml |
321 | rename to src/tests/tests.yaml |
322 | diff --git a/tests/unit/conftest.py b/src/tests/unit/conftest.py |
323 | similarity index 100% |
324 | rename from tests/unit/conftest.py |
325 | rename to src/tests/unit/conftest.py |
326 | diff --git a/tests/unit/requirements.txt b/src/tests/unit/requirements.txt |
327 | similarity index 100% |
328 | rename from tests/unit/requirements.txt |
329 | rename to src/tests/unit/requirements.txt |
330 | diff --git a/tests/unit/test_actions.py b/src/tests/unit/test_actions.py |
331 | similarity index 100% |
332 | rename from tests/unit/test_actions.py |
333 | rename to src/tests/unit/test_actions.py |
334 | diff --git a/tests/unit/test_libsudopair.py b/src/tests/unit/test_libsudopair.py |
335 | similarity index 100% |
336 | rename from tests/unit/test_libsudopair.py |
337 | rename to src/tests/unit/test_libsudopair.py |
338 | diff --git a/tox.ini b/src/tox.ini |
339 | similarity index 62% |
340 | rename from tox.ini |
341 | rename to src/tox.ini |
342 | index fc364de..d07b692 100644 |
343 | --- a/tox.ini |
344 | +++ b/src/tox.ini |
345 | @@ -1,51 +1,71 @@ |
346 | [tox] |
347 | skipsdist=True |
348 | -envlist = unit, functional |
349 | skip_missing_interpreters = True |
350 | +envlist = lint, unit, func |
351 | |
352 | [testenv] |
353 | basepython = python3 |
354 | setenv = |
355 | - PYTHONPATH = . |
356 | - |
357 | -[testenv:unit] |
358 | -commands = pytest -v --ignore {toxinidir}/tests/functional \ |
359 | - --cov=lib \ |
360 | - --cov=reactive \ |
361 | - --cov=actions \ |
362 | - --cov-report=term \ |
363 | - --cov-report=annotate:report/annotated \ |
364 | - --cov-report=html:report/html |
365 | -deps = -r{toxinidir}/tests/unit/requirements.txt |
366 | - |
367 | -setenv = PYTHONPATH={toxinidir}/lib |
368 | - |
369 | -[testenv:functional] |
370 | + PYTHONPATH = {toxinidir}:{toxinidir}/lib/:{toxinidir}/hooks/ |
371 | passenv = |
372 | HOME |
373 | - CHARM_BUILD_DIR |
374 | PATH |
375 | + CHARM_BUILD_DIR |
376 | PYTEST_KEEP_MODEL |
377 | PYTEST_CLOUD_NAME |
378 | PYTEST_CLOUD_REGION |
379 | -commands = pytest -v --ignore {toxinidir}/tests/unit |
380 | -deps = -r{toxinidir}/tests/functional/requirements.txt |
381 | - |
382 | + PYTEST_MODEL |
383 | + MODEL_SETTINGS |
384 | + HTTP_PROXY |
385 | + HTTPS_PROXY |
386 | + NO_PROXY |
387 | + SNAP_HTTP_PROXY |
388 | + SNAP_HTTPS_PROXY |
389 | |
390 | [testenv:lint] |
391 | -commands = flake8 |
392 | +commands = |
393 | + flake8 |
394 | +#TODO black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
395 | deps = |
396 | + black |
397 | flake8 |
398 | - flake8-docstrings |
399 | - flake8-import-order |
400 | - pep8-naming |
401 | +#TODO flake8-docstrings |
402 | +#TODO flake8-import-order |
403 | +#TODO pep8-naming |
404 | flake8-colors |
405 | |
406 | [flake8] |
407 | -ignore = D100,D103 # Missing docstring in public module/function |
408 | exclude = |
409 | .git, |
410 | __pycache__, |
411 | .tox, |
412 | + charmhelpers, |
413 | + mod, |
414 | + .build |
415 | + |
416 | max-line-length = 120 |
417 | +#TODO max-line-length = 88 |
418 | max-complexity = 10 |
419 | + |
420 | +[testenv:black] |
421 | +commands = |
422 | + black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
423 | +deps = |
424 | + black |
425 | + |
426 | +[testenv:unit] |
427 | +commands = |
428 | + pytest -v --ignore {toxinidir}/tests/functional \ |
429 | + --cov=lib \ |
430 | + --cov=reactive \ |
431 | + --cov=actions \ |
432 | + --cov=hooks \ |
433 | + --cov=src \ |
434 | + --cov-report=term \ |
435 | + --cov-report=annotate:report/annotated \ |
436 | + --cov-report=html:report/html |
437 | +deps = -r{toxinidir}/tests/unit/requirements.txt |
438 | + |
439 | +[testenv:func] |
440 | +commands = pytest -v --ignore {toxinidir}/tests/unit |
441 | +deps = -r{toxinidir}/tests/functional/requirements.txt |
LGTM. I did notice a couple of things which could get cleaned up and are (maybe, arguably) within scope, but they're not critical.