Add to_directory method to relevant object classes
[oam.git] / code / network-generator / Makefile
1 .ONESHELL:
2 ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.oam/bin/pip').exists(): print('.oam/bin/')")
3 USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes")
4
5 .PHONY: help
6 help:             ## Show the help.
7         @echo "Usage: make <target>"
8         @echo ""
9         @echo "Targets:"
10         @fgrep "##" Makefile | fgrep -v fgrep
11
12
13 .PHONY: show
14 show:             ## Show the current environment.
15         @echo "Current environment:"
16         @if [ "$(USING_POETRY)" ]; then poetry env info && exit; fi
17         @echo "Running using $(ENV_PREFIX)"
18         @$(ENV_PREFIX)python -V
19         @$(ENV_PREFIX)python -m site
20
21 .PHONY: install
22 install:          ## Install the project in dev mode.
23         @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
24         @echo "Don't forget to run 'make virtual_env_4_oam' if you got errors."
25         $(ENV_PREFIX)pip install -e .[test]
26
27 .PHONY: format
28 format:           ## Format code using black & isort.
29         $(ENV_PREFIX)isort network_generation/
30         $(ENV_PREFIX)black -l 79 network_generation/
31         $(ENV_PREFIX)black -l 79 tests/
32
33 .PHONY: lint
34 lint:             ## Run pep8, black, mypy linters.
35         $(ENV_PREFIX)flake8 network_generation/
36         $(ENV_PREFIX)flake8 tests/
37         $(ENV_PREFIX)black -l 79 --check network_generation/
38         $(ENV_PREFIX)black -l 79 --check tests/
39         $(ENV_PREFIX)mypy --ignore-missing-imports --disallow-untyped-defs --check-untyped-def network_generation/
40
41 .PHONY: test
42 test: lint        ## Run tests and generate coverage report.
43         $(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=network_generation -l --tb=short --maxfail=1 tests/
44         $(ENV_PREFIX)coverage xml
45         $(ENV_PREFIX)coverage html
46
47 .PHONY: watch
48 watch:            ## Run tests on every change.
49         ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/
50
51 .PHONY: clean
52 clean:            ## Clean unused files.
53         @find ./ -name '*.pyc' -exec rm -f {} \;
54         @find ./ -name '__pycache__' -exec rm -rf {} \;
55         @find ./ -name 'Thumbs.db' -exec rm -f {} \;
56         @find ./ -name '*~' -exec rm -f {} \;
57         @rm -rf .cache
58         @rm -rf .pytest_cache
59         @rm -rf .mypy_cache
60         @rm -rf build
61         @rm -rf dist
62         @rm -rf *.egg-info
63         @rm -rf htmlcov
64         @rm -rf .tox/
65         @rm -rf docs/_build
66
67 .PHONY: virtual_env_4_oam
68 virtual_env_4_oam:       ## Create a virtual environment for O-RAN-SC OAM project.
69         @if [ "$(USING_POETRY)" ]; then poetry install && exit; fi
70         @echo "Creating a virtual environment for O-RAN-SC OAM project ..."
71         @rm -rf .oam
72         @python3 -m venv .oam
73         @./.oam/bin/pip install -U pip
74         @./.oam/bin/pip install -e .[test]
75         @./.oam/bin/pip install -r requirements.txt
76         @./.oam/bin/pip install -r requirements-test.txt
77
78         @echo
79         @echo "!!! Please run 'source .oam/bin/activate' to enable the OAM environment !!!"
80
81 .PHONY: release
82 release:          ## Create a new tag for release.
83         @echo "WARNING: This operation will create s version tag and push to github"
84         @read -p "Version? (provide the next x.y.z semver) : " TAG
85         @echo "$${TAG}" > network_generation/VERSION
86         @$(ENV_PREFIX)gitchangelog > HISTORY.md
87         @git add network_generation/VERSION HISTORY.md
88         @git commit -m "release: version $${TAG} ðŸš€"
89         @echo "creating git tag : $${TAG}"
90         @git tag $${TAG}
91         @git push -u origin HEAD --tags
92         @echo "Github Actions will detect the new tag and release the new version."
93
94 .PHONY: docs
95 docs:             ## Build the documentation.
96         @echo "building documentation ..."
97         @$(ENV_PREFIX)mkdocs build
98         URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
99
100 .PHONY: switch-to-poetry
101 switch-to-poetry: ## Switch to poetry package manager.
102         @echo "Switching to poetry ..."
103         @if ! poetry --version > /dev/null; then echo 'poetry is required, install from https://python-poetry.org/'; exit 1; fi
104         @rm -rf .oam
105         @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
106         @echo "" >> pyproject.toml
107         @echo "[tool.poetry.scripts]" >> pyproject.toml
108         @echo "network_generation = 'network_generation.__main__:main'" >> pyproject.toml
109         @cat requirements.txt | while read in; do poetry add --no-interaction "$${in}"; done
110         @cat requirements-test.txt | while read in; do poetry add --no-interaction "$${in}" --dev; done
111         @poetry install --no-interaction
112         @mkdir -p .github/backup
113         @mv requirements* .github/backup
114         @mv setup.py .github/backup
115         @echo "You have switched to https://python-poetry.org/ package manager."
116         @echo "Please run 'poetry shell' or 'poetry run network_generation'"
117
118 .PHONY: init
119 init:             ## Initialize the project based on an application template.
120         @./.github/init.sh
121
122
123 # This project has been generated from rochacbruno/python-project-template
124 # __author__ = 'rochacbruno'
125 # __repo__ = https://github.com/rochacbruno/python-project-template
126 # __sponsor__ = https://github.com/sponsors/rochacbruno/