Skip to content

Commit efb9198

Browse files
committed
Makefile changes/pipenv usage
1 parent c37bd9b commit efb9198

File tree

4 files changed

+64
-27
lines changed

4 files changed

+64
-27
lines changed

Makefile

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,59 @@
11
TEST_DIR=tests
22

3+
## Sets up the virtual environment via pipenv.
4+
.PHONY: setup
5+
setup:
6+
pipenv --three install --dev
7+
8+
## Cleans test and packaging outputs.
39
.PHONY: clean
410
clean:
5-
rm -rf .coverage htmlcov/
6-
7-
.PHONY: create-env
8-
create-env:
9-
python3 -m venv env || python -m venv env
10-
echo "Run => 'source env/bin/activate' "
11-
12-
.PHONY: install
13-
install:
14-
pip install --upgrade pip
15-
pip install .
11+
rm -rf .coverage build/ dist/
1612

13+
## Runs tests.
1714
.PHONY: test
1815
test: clean
19-
pytest $(TEST_DIR) -v -s --disable-warnings
16+
pipenv run pytest $(TEST_DIR) -v -s --disable-warnings
17+
18+
## Creates coverage report.
19+
.PHONY: coverage
20+
coverage:
21+
pipenv run pytest --cov=src/ --cov-report=term-missing --disable-warnings
22+
23+
.DEFAULT:
24+
@$(MAKE) help
25+
26+
## This help message.
27+
.PHONY: help
28+
help:
29+
@printf "\nUsage:\n";
2030

21-
.PHONY: open-report
22-
open-report:
23-
pytest --cov=src/ --cov-report=term-missing --cov-report=html --disable-warnings
24-
open htmlcov/index.html || xdg-open htmlcov/index.html
31+
@awk '{ \
32+
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
33+
helpCommand = substr($$0, index($$0, ":") + 2); \
34+
if (helpMessage) { \
35+
printf "\033[36m%-20s\033[0m %s\n", \
36+
helpCommand, helpMessage; \
37+
helpMessage = ""; \
38+
} \
39+
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
40+
helpCommand = substr($$0, 0, index($$0, ":")); \
41+
if (helpMessage) { \
42+
printf "\033[36m%-20s\033[0m %s\n", \
43+
helpCommand, helpMessage; \
44+
helpMessage = ""; \
45+
} \
46+
} else if ($$0 ~ /^##/) { \
47+
if (helpMessage) { \
48+
helpMessage = helpMessage"\n "substr($$0, 3); \
49+
} else { \
50+
helpMessage = substr($$0, 3); \
51+
} \
52+
} else { \
53+
if (helpMessage) { \
54+
print "\n "helpMessage"\n" \
55+
} \
56+
helpMessage = ""; \
57+
} \
58+
}' \
59+
$(MAKEFILE_LIST)

Pipfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ grpcio = "*"
1616
protobuf = "*"
1717
six = "*"
1818
cryptography = "*"
19+
pytest = "*"
20+
pytest-cov = "*"
21+
pytest-mock = "*"
22+
pytest-coverage = "*"
1923

2024
[requires]
2125
python_version = "3.6"

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ git clone https://github.com/cisco-ie/cisco-gnmi-python.git
144144
cd cisco-gnmi-python
145145
# If pipenv not installed, install!
146146
pip install --user pipenv
147-
# Now use pipenv
147+
# Now use Makefile...
148+
make setup
149+
# Or pipenv manually if make not present
148150
pipenv --three install --dev
149151
# Enter virtual environment
150152
pipenv shell
151-
# Do your thing.
153+
# Work work
152154
exit
153155
```
154156

tests/README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# Tests
22

3-
> You should've cloned this project/repo, if not run the below command in your terminal:
3+
Clone the project and enter the project directory:
44
```
55
git clone git@github.com:cisco-ie/cisco-gnmi-python.git
6+
cd cisco-gnmi-python
67
```
78

89
## Pre-requisite
910

10-
- Create a virtual environment
11+
- Setup the developer virtual environment
1112
```
12-
make create-env
13-
```
14-
15-
- Install tests requirements
16-
```
17-
make install
13+
make setup
1814
```
1915

2016
## Usage
@@ -28,5 +24,5 @@ make test
2824
### How to open test coverage
2925

3026
```
31-
make open-report
27+
make coverage
3228
```

0 commit comments

Comments
 (0)