Merge ~gabrielcocenza/juju-lint:bug/1978739 into juju-lint:master

Proposed by Gabriel Cocenza
Status: Merged
Approved by: Martin Kalcok
Approved revision: 5160caab5760de907af591d05de6217405ef989a
Merged at revision: ea3f3020a6e0d77cdb4ffc7f29d7f7ff3b9b112d
Proposed branch: ~gabrielcocenza/juju-lint:bug/1978739
Merge into: juju-lint:master
Diff against target: 450 lines (+144/-58)
19 files modified
.pre-commit-config.yaml (+19/-0)
CONTRIBUTING.md (+14/-5)
Makefile (+48/-7)
contrib/fcb-stein-bionic.yaml (+1/-1)
contrib/fcb-ussuri-bionic-ovs.yaml (+1/-1)
contrib/fcb-ussuri-bionic.yaml (+1/-1)
contrib/fcb-ussuri-focal-ovs.yaml (+1/-1)
contrib/fcb-ussuri-focal.yaml (+1/-1)
contrib/fcb-yoga-focal.yaml (+1/-1)
contrib/includes/aggregator-kubernetes.yaml (+16/-0)
contrib/includes/release/stein.yaml (+1/-1)
contrib/includes/release/ussuri.yaml (+1/-1)
contrib/includes/release/yoga.yaml (+1/-1)
contrib/includes/series/focal.yaml (+1/-1)
contrib/kubernetes.yaml (+1/-17)
setup.py (+1/-1)
tests/requirements.txt (+2/-0)
tests/test_jujulint.py (+5/-0)
tox.ini (+28/-18)
Reviewer Review Type Date Requested Status
Martin Kalcok (community) Approve
Eric Chen Approve
Review via email: mp+426219@code.launchpad.net

Commit message

applied pattern of bootstack charms for make and tox commands.

- added pre-commit support.
- solved lint issues.
- removed debug flag to build snap. If the build fails, it should
  stop the CI and not open the shell from the snap.
- added an aggregator-kubernetes to solve pre-commit yaml check.
- changed tox and make commands to match scripts on the bootstack CI.

Closes-Bug: #1978739
Partial-Bug: #1978841

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Eric Chen (eric-chen) :
review: Approve
Revision history for this message
Martin Kalcok (martin-kalcok) wrote :

Thanks for the cleanup effort. It's definitely needed. However I have two comments:

* We were talking with the rest of the bootstack that we won't be forcing pyptoject.toml into new charms/projects just yet. We already have tox and Makefiles and adding pyptoject on top seems unnecessary.

* pre-commits should use tox to execute actions to ensure that the same versions of tools (e.g. black, flake8) will be used as in the CI pipeline. Example of such pre-commit (by Robert Gildein): https://pastebin.canonical.com/p/gBjX3qqfkY/

review: Needs Fixing
Revision history for this message
Gabriel Cocenza (gabrielcocenza) wrote :

Thanks for your review Martin. I've removed the pyptoject.toml and changed the pre-commit as you said, to use the same environment of tox.

Revision history for this message
Martin Kalcok (martin-kalcok) wrote :

One small question in-line, otherwise LGTM.

Revision history for this message
Gabriel Cocenza (gabrielcocenza) :
Revision history for this message
Martin Kalcok (martin-kalcok) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision ea3f3020a6e0d77cdb4ffc7f29d7f7ff3b9b112d

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
0new file mode 1006440new file mode 100644
index 0000000..c327de3
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,19 @@
1repos:
2 - repo: https://github.com/pre-commit/pre-commit-hooks
3 rev: v4.0.1
4 hooks:
5 - id: check-executables-have-shebangs
6 - id: check-merge-conflict
7 - id: end-of-file-fixer
8 - id: trailing-whitespace
9 - id: check-added-large-files
10 - id: check-json
11 - id: check-yaml
12 args: ["--unsafe"]
13 - repo: local
14 hooks:
15 - id: lint
16 name: lint
17 entry: tox -e lint
18 language: system
19 types: [ python ]
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7e46600..1e5c9b9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -22,11 +22,17 @@ git clone git+ssh://<LAUNCHPAD_USER>@git.launchpad.net/juju-lint
22cd juju-lint/22cd juju-lint/
23```23```
2424
25You can use the environments created by `tox` for development:25Create and activate a virtualenv with the development requirements:
2626
27```shell27```shell
28tox --notest -e unit28make dev-environment
29source .tox/unit/bin/activate29```
30
31This step is mandatory, otherwise a message like this will appear if you try to commit:
32
33```shell
34$ git commit
35`pre-commit` not found. Did you forget to activate your virtualenv?
30```36```
3137
32After making your changes you can run the CI without the need of building and installing the snap by using:38After making your changes you can run the CI without the need of building and installing the snap by using:
@@ -40,9 +46,12 @@ python3 -m jujulint.cli <PATH_TO_YAML> -c <PATH_TO_RULE_FILE> -l debug
4046
41```shell47```shell
42make lint # check code style48make lint # check code style
43make test # unit tests49make reformat # reformat the code using black and isort
50make unittests # run unit tests
51make functional # run functional tests
52make test # run lint, unittests and functional
44make build # build the snap53make build # build the snap
45make clean # clean the snapcraft lxd containers54make clean # clean the snapcraft lxd containers and the snap files created
46```55```
4756
48## Canonical Contributor Agreement57## Canonical Contributor Agreement
diff --git a/Makefile b/Makefile
index 452acd4..49303b3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,56 @@
1help:
2 @echo "This project supports the following targets"
3 @echo ""
4 @echo " make help - show this text"
5 @echo " make clean - remove unneeded files"
6 @echo " make dev-environment - setup the development environment"
7 @echo " make build - build the snap"
8 @echo " make lint - run flake8, black --check and isort --check-only"
9 @echo " make reformat - run black and isort and reformat files"
10 @echo " make unittests - run the tests defined in the unittest subdirectory"
11 @echo " make functional - run the tests defined in the functional subdirectory"
12 @echo " make test - run lint, proof, unittests and functional targets"
13 @echo " make pre-commit - run pre-commit checks on all the files"
14 @echo ""
15
16
1lint:17lint:
2 tox -e lintverbose18 @echo "Running lint checks"
19 @tox -e lint
20
21unittests:
22 @echo "Running unit tests"
23 @tox -e unit
324
4test:25test: lint unittests functional
5 tox -e unit26 @echo "Tests completed for the snap."
627
7format-code:28reformat:
8 tox -e format-code29 @echo "Reformat files with black and isort"
30 tox -e reformat
931
10build:32build:
11 snapcraft --use-lxd --debug33 @echo "Building the snap"
34 @snapcraft --use-lxd
1235
13clean:36clean:
14 snapcraft clean --use-lxd37 @echo "Cleaning snap"
38 @snapcraft clean --use-lxd
39 @echo "Cleaning existing snap builds"
40 @find . -name "*.snap" -delete
41
42dev-environment:
43 @echo "Creating virtualenv and installing pre-commit"
44 @virtualenv -p python3 .venv
45 @.venv/bin/pip install -r tests/requirements.txt
46 @.venv/bin/pre-commit install
47
48functional: build
49 @echo "Executing functional tests using built snap"
50 @tox -e func
51
52pre-commit:
53 @tox -e pre-commit
1554
55# The targets below don't depend on a file
56.PHONY: help clean dev-environment build lint reformat unittests functional test pre-commit
diff --git a/contrib/fcb-stein-bionic.yaml b/contrib/fcb-stein-bionic.yaml
index 863058f..6d9f16f 100644
--- a/contrib/fcb-stein-bionic.yaml
+++ b/contrib/fcb-stein-bionic.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/fcb-ussuri-bionic-ovs.yaml b/contrib/fcb-ussuri-bionic-ovs.yaml
index 51de731..86d624d 100644
--- a/contrib/fcb-ussuri-bionic-ovs.yaml
+++ b/contrib/fcb-ussuri-bionic-ovs.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/fcb-ussuri-bionic.yaml b/contrib/fcb-ussuri-bionic.yaml
index 6fade6b..76e899b 100644
--- a/contrib/fcb-ussuri-bionic.yaml
+++ b/contrib/fcb-ussuri-bionic.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/fcb-ussuri-focal-ovs.yaml b/contrib/fcb-ussuri-focal-ovs.yaml
index a29ed0e..0e989a0 100644
--- a/contrib/fcb-ussuri-focal-ovs.yaml
+++ b/contrib/fcb-ussuri-focal-ovs.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/fcb-ussuri-focal.yaml b/contrib/fcb-ussuri-focal.yaml
index 2e6f2eb..8b53cfe 100644
--- a/contrib/fcb-ussuri-focal.yaml
+++ b/contrib/fcb-ussuri-focal.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/fcb-yoga-focal.yaml b/contrib/fcb-yoga-focal.yaml
index 4293a7d..632a73a 100644
--- a/contrib/fcb-yoga-focal.yaml
+++ b/contrib/fcb-yoga-focal.yaml
@@ -6,4 +6,4 @@
6!include includes/openstack.yaml6!include includes/openstack.yaml
7!include includes/operations.yaml7!include includes/operations.yaml
8!include includes/saas.yaml8!include includes/saas.yaml
9!include includes/aggregator-openstack.yaml
10\ No newline at end of file9\ No newline at end of file
10!include includes/aggregator-openstack.yaml
diff --git a/contrib/includes/aggregator-kubernetes.yaml b/contrib/includes/aggregator-kubernetes.yaml
11new file mode 10064411new file mode 100644
index 0000000..95c2099
--- /dev/null
+++ b/contrib/includes/aggregator-kubernetes.yaml
@@ -0,0 +1,16 @@
1operations charms: &operations-charms
2 - *operations-kubernetes-mandatory-charms
3 - *operations-mandatory-charms
4 - *operations-mandatory-deps
5 - *operations-mandatory-subs
6 - *operations-optional-charms
7 - *operations-optional-subs
8
9kubernetes charms: &kubernetes-charms
10 - *kubernetes-mandatory-charms
11 - *kubernetes-optional-charms
12
13known charms:
14 - ubuntu
15 - *operations-charms
16 - *kubernetes-charms
diff --git a/contrib/includes/release/stein.yaml b/contrib/includes/release/stein.yaml
index 7319287..3195046 100644
--- a/contrib/includes/release/stein.yaml
+++ b/contrib/includes/release/stein.yaml
@@ -1,4 +1,4 @@
1# add prometheus ceph exporter if openstack version is lesser than ussuri1# add prometheus ceph exporter if openstack version is lesser than ussuri
22
3operations openstack mandatory release: &operations-openstack-mandatory-release3operations openstack mandatory release: &operations-openstack-mandatory-release
4 - prometheus-ceph-exporter
5\ No newline at end of file4\ No newline at end of file
5 - prometheus-ceph-exporter
diff --git a/contrib/includes/release/ussuri.yaml b/contrib/includes/release/ussuri.yaml
index ddf9beb..4080368 100644
--- a/contrib/includes/release/ussuri.yaml
+++ b/contrib/includes/release/ussuri.yaml
@@ -2,4 +2,4 @@
2# Instead, use ceph-dashboard2# Instead, use ceph-dashboard
33
4operations openstack mandatory release: &operations-openstack-mandatory-release4operations openstack mandatory release: &operations-openstack-mandatory-release
5 - ceph-dashboard
6\ No newline at end of file5\ No newline at end of file
6 - ceph-dashboard
diff --git a/contrib/includes/release/yoga.yaml b/contrib/includes/release/yoga.yaml
index ddf9beb..4080368 100644
--- a/contrib/includes/release/yoga.yaml
+++ b/contrib/includes/release/yoga.yaml
@@ -2,4 +2,4 @@
2# Instead, use ceph-dashboard2# Instead, use ceph-dashboard
33
4operations openstack mandatory release: &operations-openstack-mandatory-release4operations openstack mandatory release: &operations-openstack-mandatory-release
5 - ceph-dashboard
6\ No newline at end of file5\ No newline at end of file
6 - ceph-dashboard
diff --git a/contrib/includes/series/focal.yaml b/contrib/includes/series/focal.yaml
index 4084113..4771d14 100644
--- a/contrib/includes/series/focal.yaml
+++ b/contrib/includes/series/focal.yaml
@@ -1,3 +1,3 @@
1openstack loadbalancer: &openstack-loadbalancer1openstack loadbalancer: &openstack-loadbalancer
2 - openstack-loadbalancer2 - openstack-loadbalancer
3operations openstack mandatory series: &operations-openstack-mandatory-series []
4\ No newline at end of file3\ No newline at end of file
4operations openstack mandatory series: &operations-openstack-mandatory-series []
diff --git a/contrib/kubernetes.yaml b/contrib/kubernetes.yaml
index 27eeba6..4e90b94 100644
--- a/contrib/kubernetes.yaml
+++ b/contrib/kubernetes.yaml
@@ -4,20 +4,4 @@
4!include includes/operations.yaml4!include includes/operations.yaml
5!include includes/kubernetes.yaml5!include includes/kubernetes.yaml
6!include includes/saas.yaml6!include includes/saas.yaml
77!include includes/aggregator-kubernetes.yaml
8operations charms: &operations-charms
9 - *operations-kubernetes-mandatory-charms
10 - *operations-mandatory-charms
11 - *operations-mandatory-deps
12 - *operations-mandatory-subs
13 - *operations-optional-charms
14 - *operations-optional-subs
15
16kubernetes charms: &kubernetes-charms
17 - *kubernetes-mandatory-charms
18 - *kubernetes-optional-charms
19
20known charms:
21 - ubuntu
22 - *operations-charms
23 - *kubernetes-charms
diff --git a/setup.py b/setup.py
index b6b3dc9..9314d60 100644
--- a/setup.py
+++ b/setup.py
@@ -16,9 +16,9 @@
16# You should have received a copy of the GNU General Public License16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18"""Setuptools packaging metadata for juju-lint."""18"""Setuptools packaging metadata for juju-lint."""
19import warnings
1920
20import setuptools21import setuptools
21import warnings
2222
23warnings.simplefilter("ignore", UserWarning) # Older pips complain about newer options.23warnings.simplefilter("ignore", UserWarning) # Older pips complain about newer options.
2424
diff --git a/tests/requirements.txt b/tests/requirements.txt
index 2575eb3..d31d3fb 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,5 +1,6 @@
1# Module requirements1# Module requirements
2black2black
3colorama
3flake84flake8
4flake8-colors5flake8-colors
5flake8-docstrings6flake8-docstrings
@@ -13,3 +14,4 @@ pytest
13pytest-cov14pytest-cov
14pytest-html15pytest-html
15pytest-mock16pytest-mock
17pre-commit
diff --git a/tests/test_jujulint.py b/tests/test_jujulint.py
index e99401a..6e40b74 100644
--- a/tests/test_jujulint.py
+++ b/tests/test_jujulint.py
@@ -787,6 +787,7 @@ applications:
787 }787 }
788788
789 def test_check_spaces_detect_mismatches(self, linter, mocker):789 def test_check_spaces_detect_mismatches(self, linter, mocker):
790 """Test that check spaces mismatch gives warning message."""
790 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")791 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")
791 linter.model.app_to_charm = self.check_spaces_example_app_charm_map792 linter.model.app_to_charm = self.check_spaces_example_app_charm_map
792793
@@ -805,6 +806,7 @@ applications:
805 )806 )
806807
807 def test_check_spaces_enforce_endpoints(self, linter):808 def test_check_spaces_enforce_endpoints(self, linter):
809 """Test that check spaces enforce endpoints."""
808 linter.model.app_to_charm = self.check_spaces_example_app_charm_map810 linter.model.app_to_charm = self.check_spaces_example_app_charm_map
809811
810 # Run the space check with prometheus:target endpoint enforced.812 # Run the space check with prometheus:target endpoint enforced.
@@ -824,6 +826,7 @@ applications:
824 assert len(errors) == 2826 assert len(errors) == 2
825827
826 def test_check_spaces_enforce_relations(self, linter):828 def test_check_spaces_enforce_relations(self, linter):
829 """Test that check spaces enforce relations."""
827 linter.model.app_to_charm = self.check_spaces_example_app_charm_map830 linter.model.app_to_charm = self.check_spaces_example_app_charm_map
828831
829 # Run the space check with prometheus:target endpoint enforced.832 # Run the space check with prometheus:target endpoint enforced.
@@ -845,6 +848,7 @@ applications:
845 assert len(errors) == 2848 assert len(errors) == 2
846849
847 def test_check_spaces_ignore_endpoints(self, linter, mocker):850 def test_check_spaces_ignore_endpoints(self, linter, mocker):
851 """Test that check spaces can ignore endpoints."""
848 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")852 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")
849 linter.model.app_to_charm = self.check_spaces_example_app_charm_map853 linter.model.app_to_charm = self.check_spaces_example_app_charm_map
850854
@@ -867,6 +871,7 @@ applications:
867 assert mock_log.call_count == 0871 assert mock_log.call_count == 0
868872
869 def test_check_spaces_ignore_relations(self, linter, mocker):873 def test_check_spaces_ignore_relations(self, linter, mocker):
874 """Test that check spaces can ignore relations."""
870 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")875 mock_log: mock.MagicMock = mocker.patch("jujulint.lint.Linter._log_with_header")
871 linter.model.app_to_charm = self.check_spaces_example_app_charm_map876 linter.model.app_to_charm = self.check_spaces_example_app_charm_map
872877
diff --git a/tox.ini b/tox.ini
index 843a442..40349c8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,14 +4,15 @@ exclude =
4 __pycache__,4 __pycache__,
5 .tox,5 .tox,
6 .eggs,6 .eggs,
7 .venv,
7 venv,8 venv,
8max-line-length = 1209max-line-length = 120
9max-complexity = 1010max-complexity = 10
10ignore = C90111ignore = D100, D103, C901
1112
12[tox]13[tox]
13skipsdist=True14skipsdist=True
14envlist = lintverbose, unit15envlist = lint, unit, func
15skip_missing_interpreters = True16skip_missing_interpreters = True
1617
17[testenv]18[testenv]
@@ -19,9 +20,6 @@ basepython = python3.8
19deps =20deps =
20 -r{toxinidir}/tests/requirements.txt21 -r{toxinidir}/tests/requirements.txt
21 -r{toxinidir}/requirements.txt22 -r{toxinidir}/requirements.txt
22commands =
23 lint: flake8 {toxinidir}
24 test: python3 -m unittest discover tests
2523
26[testenv:unit]24[testenv:unit]
27commands =25commands =
@@ -38,27 +36,39 @@ commands =
38setenv = PYTHONPATH={toxinidir}/lib36setenv = PYTHONPATH={toxinidir}/lib
3937
40[testenv:lint]38[testenv:lint]
41commands = flake8 jujulint --format=html --htmldir=tests/report/lint/ --tee
42
43[testenv:lintverbose]
44commands =39commands =
45 flake8 {toxinidir}/jujulint {toxinidir}/tests40 flake8 --color always
46 black --check {toxinidir}/jujulint {toxinidir}/tests41 black --check --diff --color .
47 isort --check {toxinidir}/jujulint {toxinidir}/tests42 isort --check-only --diff --color .
4843
4944
50[testenv:format-code]45[testenv:reformat]
51commands =46commands =
52 black {toxinidir}/jujulint {toxinidir}/tests47 black .
53 isort {toxinidir}/jujulint {toxinidir}/tests48 isort .
54
5549
56[testenv:lintjunit]50[testenv:func]
57commands = flake8 jujulint --format junit-xml --output-file=report/lint/junit.xml51#TODO(gabrielcocenza) add func tests
5852
59[pytest]53[pytest]
60filterwarnings = 54filterwarnings =
61 ignore::DeprecationWarning55 ignore::DeprecationWarning
6256
63[isort]57[isort]
64profile = black58profile = black
59skip_glob =
60 .eggs,
61 __pycache__,
62 .git,
63 .tox,
64 .venv,
65 .build,
66 venv,
67 dist,
68 mod,
69 build,
70
71[testenv:pre-commit]
72deps = pre-commit
73commands =
74 pre-commit run -a

Subscribers

People subscribed via source and target branches