Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Makefile 4.8 KB

You have to be logged in to leave a comment. Sign In
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
  1. .PHONY: clean data lint requirements sync_data_to_s3 sync_data_from_s3 initialize_version_control
  2. #################################################################################
  3. # GLOBALS #
  4. #################################################################################
  5. PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
  6. BUCKET = [OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')
  7. PROFILE = default
  8. PROJECT_NAME = 002_data_publica
  9. PYTHON_INTERPRETER = python3
  10. ifeq (,$(shell which conda))
  11. HAS_CONDA=False
  12. else
  13. HAS_CONDA=True
  14. endif
  15. #################################################################################
  16. # COMMANDS #
  17. #################################################################################
  18. ## Install Python Dependencies
  19. requirements: test_environment
  20. $(PYTHON_INTERPRETER) -m pip install -U pip setuptools wheel
  21. $(PYTHON_INTERPRETER) -m pip install -r requirements.txt
  22. .dvc: requirements
  23. git init
  24. dvc init
  25. dvc config cache.type reflink,copy
  26. dvc remote add -d origin s3://$(BUCKET)/data
  27. ifneq (default,$(PROFILE))
  28. dvc remote modify origin profile $(PROFILE)
  29. endif
  30. dvc add data
  31. dvc push
  32. git add data.dvc
  33. git commit -m 'Initialize data version control'
  34. ## Inititalize git + dvc if data version conrol is used
  35. initialize_version_control: .dvc
  36. ## Make Dataset
  37. data: initialize_version_control
  38. $(PYTHON_INTERPRETER) src/data/make_dataset.py
  39. ## Delete all compiled Python files
  40. clean:
  41. find . -type f -name "*.py[co]" -delete
  42. find . -type d -name "__pycache__" -delete
  43. ## Lint using flake8
  44. lint:
  45. flake8 src
  46. ## Upload Data to S3
  47. sync_data_to_s3:
  48. dvc add data
  49. dvc push data.dvc
  50. git commit data.dvc -m "Save data directory"
  51. ## Download Data from S3
  52. sync_data_from_s3:
  53. dvc pull data.dvc
  54. ## Set up python interpreter environment
  55. create_environment:
  56. ifeq (True,$(HAS_CONDA))
  57. @echo ">>> Detected conda, creating conda environment."
  58. ifeq (3,$(findstring 3,$(PYTHON_INTERPRETER)))
  59. conda create --name $(PROJECT_NAME) python=3
  60. else
  61. conda create --name $(PROJECT_NAME) python=2.7
  62. endif
  63. @echo ">>> New conda env created. Activate with:\nsource activate $(PROJECT_NAME)"
  64. else
  65. $(PYTHON_INTERPRETER) -m pip install -q virtualenv virtualenvwrapper
  66. @echo ">>> Installing virtualenvwrapper if not already intalled.\nMake sure the following lines are in shell startup file\n\
  67. export WORKON_HOME=$$HOME/.virtualenvs\nexport PROJECT_HOME=$$HOME/Devel\nsource /usr/local/bin/virtualenvwrapper.sh\n"
  68. @bash -c "source `which virtualenvwrapper.sh`;mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER)"
  69. @echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)"
  70. endif
  71. ## Test python environment is setup correctly
  72. test_environment:
  73. $(PYTHON_INTERPRETER) test_environment.py
  74. #################################################################################
  75. # PROJECT RULES #
  76. #################################################################################
  77. #################################################################################
  78. # Self Documenting Commands #
  79. #################################################################################
  80. .DEFAULT_GOAL := help
  81. # Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
  82. # sed script explained:
  83. # /^##/:
  84. # * save line in hold space
  85. # * purge line
  86. # * Loop:
  87. # * append newline + line to hold space
  88. # * go to next line
  89. # * if line starts with doc comment, strip comment character off and loop
  90. # * remove target prerequisites
  91. # A
  92. # * append hold space (+ newline) to line
  93. # * replace newline plus comments by `---`
  94. # * print line
  95. # Separate expressions are necessary because labels cannot be delimited by
  96. # semicolon; see <http://stackoverflow.com/a/11799865/1968>
  97. .PHONY: help
  98. help:
  99. @echo "$$(tput bold)Available rules:$$(tput sgr0)"
  100. @echo
  101. @sed -n -e "/^## / { \
  102. h; \
  103. s/.*//; \
  104. :doc" \
  105. -e "H; \
  106. n; \
  107. s/^## //; \
  108. t doc" \
  109. -e "s/:.*//; \
  110. G; \
  111. s/\\n## /---/; \
  112. s/\\n/ /g; \
  113. p; \
  114. }" ${MAKEFILE_LIST} \
  115. | LC_ALL='C' sort --ignore-case \
  116. | awk -F '---' \
  117. -v ncol=$$(tput cols) \
  118. -v indent=26 \
  119. -v col_on="$$(tput setaf 6)" \
  120. -v col_off="$$(tput sgr0)" \
  121. '{ \
  122. printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
  123. n = split($$2, words, " "); \
  124. line_length = ncol - indent; \
  125. for (i = 1; i <= n; i++) { \
  126. line_length -= length(words[i]) + 1; \
  127. if (line_length <= 0) { \
  128. line_length = ncol - indent - length(words[i]) - 1; \
  129. printf "\n%*s ", -indent, " "; \
  130. } \
  131. printf "%s ", words[i]; \
  132. } \
  133. printf "\n"; \
  134. }' \
  135. | more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...