/
env.clj
218 lines (163 loc) · 7.55 KB
/
env.clj
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
(ns clojupyter.install.conda.env
(:require [clojure.java.io :as io]
[clojure.string :as str]
[io.simplect.compose :refer [C]]))
(defn- mkcomment
[platforms comment]
(let [platforms (if (= platforms :all) [:macos :linux :windows] platforms)]
(str/join \newline [comment
nil
(str " Platforms: " (str/join ", " (map (C name str/upper-case) platforms)))])))
(defmacro ^:private def-conda-var
[nm platforms comment]
(let [comment (mkcomment platforms comment)]
`(do
(defn ~nm
~comment
[]
(System/getenv ~(name nm)))
(defn ~(symbol (str nm "!"))
~(str comment "\n Throws an Exception if not found.")
[]
(or (System/getenv ~(name nm))
(throw (Exception. ~(str "CONDA environment variable undefined: " nm))))))))
;;; ----------------------------------------------------------------------------------------------------
;;; CONDA ENVIRONMENT VARIABLES
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var ARCH :all
"Either 32 or 64, to specify whether the build is 32-bit or
64-bit. The value depends on the ARCH environment variable and
defaults to the architecture the interpreter running conda was
compiled with.")
(def-conda-var PREFIX :all
"Build prefix to which the build script should install.")
(def-conda-var DIRTY :all
"Set to 1 if the `--dirty` flag is passed to the conda-build
command. May be used to skip parts of a build script conditionally
for faster iteration time when developing recipes. For example,
downloads, extraction and other things that need not be repeated.")
(def-conda-var PKG_BUILDNUM :all
"Build number of the package being built.")
(def-conda-var PKG_NAME :all
"Name of the package being built.")
(def-conda-var PKG_VERSION :all
"Version of the package being built.")
(def-conda-var PKG_BUILD_STRING :all
"Complete build string of the package being built, including
hash. EXAMPLE: py27h21422ab_0 . Conda-build 3.0+.")
(def-conda-var PKG_HASH :all
"Hash of the package being built, without leading h. EXAMPLE:
21422ab . Conda-build 3.0+.")
(def-conda-var RECIPE_DIR :all
"Directory of the recipe.")
(def-conda-var SRC_DIR :all
"Path to where source is unpacked or cloned. If the source file is
not a recognized file type (`zip`, `tar`, `tar.bz2`, or `tar.xz`)
this is a directory containing a copy of the source file.")
;;; ----------------------------------------------------------------------------------------------------
;;; WINDOWS-ONLY
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var CYGWIN_PREFIX [:windows]
"Same as `PREFIX`, but as a Unix-style path, such as `/cygdrive/c/path/to/prefix`.")
(def-conda-var LIBRARY_BIN [:windows]
"`<build prefix>\\Library\\bin`")
(def-conda-var LIBRARY_INC [:windows]
"`<build prefix>\\Library\\include`")
(def-conda-var LIBRARY_LIB [:windows]
"`<build prefix>\\Library\\lib`")
(def-conda-var LIBRARY_PREFIX [:windows]
"`<build prefix>\\Library`")
(def-conda-var SCRIPTS [:windows]
"`<build prefix>\\Scripts`")
(def-conda-var VS_MAJOR [:windows]
"`The major version number of the Visual Studio version activated
within the build, such as 9.`")
(def-conda-var VS_VERSION [:windows]
"`The version number of the Visual Studio version activated within
the build, such as 9.0.`")
(def-conda-var VS_YEAR [:windows]
"The release year of the Visual Studio version activated within the
build, such as 2008.")
;;; ----------------------------------------------------------------------------------------------------
;;; MacOS + Linux
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var HOME [:macos :linux]
"Standard `$HOME` environment variable.")
(def-conda-var PKG_CONFIG_PATH [:macos :linux]
"Path to pkgconfig directory.")
;;; ----------------------------------------------------------------------------------------------------
;;; MacOS-only
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var CFLAGS [:macos]
"`-arch` flag.")
(def-conda-var CXXFLAGS [:macos]
"Same as `CFLAGS`.")
(def-conda-var LDFLAGS [:macos]
"Same as `CFLAGS`.")
(def-conda-var MACOSX_DEPLOYMENT_TARGET [:macos]
"Same as the Anaconda Python macOS deployment target. Currently
10.6.")
(def-conda-var OSX_ARCH [:macos]
"`i386` or `x86_64`, depending on Python build.")
;;; ----------------------------------------------------------------------------------------------------
;;; Linux-only
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var LD_RUN_PATH [:linux]
"`<build prefix>/lib`")
;;; ----------------------------------------------------------------------------------------------------
;;; Other
;;; ----------------------------------------------------------------------------------------------------
(def-conda-var GIT_BUILD_STR :all
"String that joins `GIT_DESCRIBE_NUMBER` and `GIT_DESCRIBE_HASH` by an
underscore.")
(def-conda-var GIT_DESCRIBE_HASH :all
"The current commit short-hash as displayed from git describe
`--tags`.")
(def-conda-var GIT_DESCRIBE_NUMBER :all
"String denoting the number of commits since the most recent tag.")
(def-conda-var GIT_DESCRIBE_TAG :all
"String denoting the most recent tag from the current commit, based
on the output of git describe `--tags`.")
(def-conda-var GIT_FULL_HASH :all
"String with the full SHA1 of the current `HEAD`.")
(def-conda-var HG_BRANCH :all
"String denoting the presently active branch.")
(def-conda-var HG_BUILD_STR :all
"String that joins HG_NUM_ID and HG_SHORT_ID by an underscore.")
(def-conda-var HG_LATEST_TAG :all
"String denoting the most recent tag from the current commit.")
(def-conda-var HG_LATEST_TAG_DISTANCE :all
"String denoting number of commits since the most recent tag.")
(def-conda-var HG_NUM_ID :all
"String denoting the revision number.")
(def-conda-var HG_SHORT_ID :all
"String denoting the hash of the commit.")
(def-conda-var CONDA_PY :all
"The Python version used to build the package. Should be 27, 34, 35
or 36.")
(def-conda-var CONDA_NPY :all
"The NumPy version used to build the package, such as 19, 110 or 111.")
(def-conda-var CONDA_PREFIX :all
"The path to the conda environment used to build the package, such
as `/path/to/conda/env`. Useful to pass as the environment prefix
parameter to various conda tools, usually labeled `-p` or `--prefix`.")
(def-conda-var FEATURE_NOMKL :all
"Adds the `nomkl` feature to the built package. Accepts 0 for off and
1 for on.")
(def-conda-var FEATURE_DEBUG :all
"Adds the debug feature to the built package. Accepts 0 for off and 1 for on.")
(def-conda-var FEATURE_OPT :all
"Adds the opt feature to the built package. Accepts 0 for off and 1 for on.")
;;; ----------------------------------------------------------------------------------------------------
;;; AUXILIARY FUNCTIONS
;;; ----------------------------------------------------------------------------------------------------
(defn pkg-name-ver-num!
"Returns the string consisting of `PKG_NAME`, `PKG_VERSION` and
`PKG_BUILDNUM` joined by '-' characters."
[]
(str (PKG_NAME!) "-" (PKG_VERSION!) "-" (PKG_BUILDNUM!)))
(defn pkg-dir!
"Returns a file object referring to the package directory in the
`pkgs` directory in `PREFIX`."
[]
(io/file (str (PREFIX!) "/pkgs/" (pkg-name-ver-num!))))