This repository was archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathenvironment.mk
More file actions
106 lines (95 loc) · 3.29 KB
/
environment.mk
File metadata and controls
106 lines (95 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Environment Management Makefile
define conda_environment_file
name: sdk\\n
channels:\\n
- default\\n
- apple\\n
- conda-forge\\n
dependencies:\\n
- python=$(shell cat .python-version)\\n
- pip\\n
- pip:\\n
\ \ - poetry==$(REQUIRED_POETRY_VERSION)
endef
.PHONY: create-environment
create-environment: create-environment-$(UNAME_SYS) ## Set up python environment
@rm -rf $(PYTHON_ENV_STAMP_DIR)
.PHONY: create-environment-Linux
create-environment-Linux: .python-version
ifeq ($(shell which pyenv),)
@echo "pyenv is not Installed, please install before creating an environment"
@exit 1
else
@pyenv install -s $(shell cat $<)
@echo "pyenv Python version $(shell cat $<) installed."
@echo "Activate shell with poetry shell"
endif
.PHONY: create-environment-Darwin
create-environment-Darwin:
ifeq ($(UNAME_ARCH), arm64)
ifdef CONDA_ENV_NAME
$(shell echo $(conda_environment_file) > .environment.M1.yml)
$(CONDA_EXE) env update -p build/$(PROJECT_NAME) -f .environment.M1.yml
@echo
@echo "Conda env is available and can be activated."
else
$(error Unsupported Environment. Please use conda)
endif
endif
.PHONY: delete-environment
delete-environment: delete-environment-$(UNAME_SYS)
.PHONY: delete-environment-Linux
delete-environment-Linux:
@echo "No action needed"
.PHONY: delete-environment-Darwin ## Delete the virtual (conda) environment
delete-environment-Darwin:
ifeq ($(UNAME_ARCH), arm64)
@echo "Deleting conda environment."
rm -fr build/$(PROJECT_NAME)
endif
$(PYTHON_ENV_STAMP):
@rm -rf $(PYTHON_ENV_STAMP_DIR_CURRENT)
@mkdir -p $(PYTHON_ENV_STAMP_DIR_CURRENT)
@touch $(PYTHON_ENV_STAMP)
$(PREREQ_STAMP): pyproject.toml poetry.lock $(PYTHON_ENV_STAMP)
ifeq ($(UNAME_ARCH), arm64)
ifdef CONDA_ENV_NAME
ifeq ($(CONDA_ENV_NAME), base)
@echo 'Please create a conda environment and make it active'
@exit 1
else
echo "installing conda deps"
@conda install -y $(call get_python_package_version,tokenizers) \
$(call get_python_package_version,xgboost) \
$(call get_python_package_version,lightgbm) \
$(call get_python_package_version,h5py) \
$(call get_python_package_version,pyarrow) \
$(call get_python_package_version,grpcio)
## https://github.com/python-poetry/poetry/issues/6408
@find $$CONDA_PREFIX/lib -name direct_url.json -delete
endif
else
@echo 'Not inside a conda environment or conda not installed, this is a requirement for Apple arm processors'
@echo 'See https://github.com/conda-forge/miniforge/'
@exit 1
endif
endif
@touch $(PREREQ_STAMP)
.PHONY: jupyter
jupyter: install ## Start a jupyter notebook with editable layer package
@IPYTHONDIR=$(ROOT_DIR)/build/ipython poetry run jupyter-notebook
.PHONY: clean
clean: ## Resets development environment.
@echo 'cleaning repo...'
@rm -rf .mypy_cache
@rm -rf .pytest_cache
@rm -f .coverage
@find . -type d -name '*.egg-info' -not -path "*build/$(PROJECT_NAME)/*" | xargs rm -rf {};
@find . -depth -type d -name '*.egg-info' -not -path "*build/$(PROJECT_NAME)/*" -delete
@rm -rf dist/
@rm -f $(INSTALL_STAMP)
@find . -type f -name '*.pyc' -not -path "*build/$(PROJECT_NAME)/*" -delete
@find . -type d -name "__pycache__" -not -path "*build/$(PROJECT_NAME)/*" | xargs rm -rf {};
@rm -rf $(OUTPUTS_DIR)
@echo 'done.'