Skip to content

Commit faebf9a

Browse files
committed
Add SPY_BRANCH and SPY_COMMIT environment variables to standalone runtime environments.
- Patch spyder-menu.json in build_conda_pkgs.py instead of build.sh and bld.bat, i.e. patching the feedstock rather than having the feedstock patch the build. This is more efficient since these variables are not available to conda-build. - Move the build.sh patch to build_conda_pkgs.py from a separate script file. Note that handling the application icon for Windows as this will never be executed.
1 parent c362b85 commit faebf9a

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

installers-conda/build_conda_pkgs.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self, data={}, debug=False, shallow=False):
6666
self._get_source(shallow=shallow)
6767
self._get_version()
6868

69+
self._patch_source()
70+
6971
self.data = {'version': self.version}
7072
self.data.update(data)
7173

@@ -77,7 +79,7 @@ def _get_source(self, shallow=False):
7779

7880
if self.source == HERE.parent:
7981
self._bld_src = self.source
80-
repo = Repo(self.source)
82+
self.repo = Repo(self.source)
8183
else:
8284
# Determine source and commit
8385
if self.source is not None:
@@ -97,10 +99,8 @@ def _get_source(self, shallow=False):
9799
f"Cloning source shallow from tag {self.shallow_ver}...")
98100
else:
99101
self.logger.info("Cloning source...")
100-
repo = Repo.clone_from(remote, **kwargs)
101-
repo.git.checkout(commit)
102-
103-
self._patch_source(repo)
102+
self.repo = Repo.clone_from(remote, **kwargs)
103+
self.repo.git.checkout(commit)
104104

105105
# Clone feedstock
106106
self.logger.info("Cloning feedstock...")
@@ -117,7 +117,7 @@ def _get_version(self):
117117
"""Get source version using setuptools_scm"""
118118
self.version = get_version(self._bld_src).split('+')[0]
119119

120-
def _patch_source(self, repo):
120+
def _patch_source(self):
121121
pass
122122

123123
def _patch_meta(self, meta):
@@ -127,7 +127,12 @@ def _patch_build_script(self):
127127
pass
128128

129129
def patch_recipe(self):
130-
"""Patch conda build recipe"""
130+
"""
131+
Patch conda build recipe
132+
133+
1. Patch meta.yaml
134+
2. Patch build script
135+
"""
131136
if self._recipe_patched:
132137
return
133138

@@ -161,9 +166,8 @@ def build(self):
161166
Build the conda package.
162167
163168
1. Patch the recipe
164-
2. Patch the build script
165-
3. Build the package
166-
4. Remove cloned repositories
169+
2. Build the package
170+
3. Remove cloned repositories
167171
"""
168172
t0 = time()
169173
try:
@@ -193,17 +197,27 @@ class SpyderCondaPkg(BuildCondaPkg):
193197
feedstock = "https://github.com/conda-forge/spyder-feedstock"
194198
shallow_ver = "v5.3.2"
195199

196-
def _patch_source(self, repo):
200+
def _patch_source(self):
197201
self.logger.info("Creating Spyder source patch...")
198202

199-
patch = repo.git.format_patch(
203+
patch = self.repo.git.format_patch(
200204
"..origin/installers-conda-patch", "--stdout", "-U3"
201205
)
202206
# newline keyword is not added to pathlib until Python>=3.10,
203207
# so we must use open to ensure LF on Windows
204208
with open(SPYPATCHFILE, 'w', newline='\n') as f:
205209
f.write(patch)
206210

211+
self.logger.info("Creating Spyder menu file...")
212+
_menufile = RESOURCES / "spyder-menu.json"
213+
menufile = DIST / "spyder-menu.json"
214+
commit, branch = self.repo.head.commit.name_rev.split()
215+
text = _menufile.read_text()
216+
text = text.replace("__PKG_VERSION__", self.version)
217+
text = text.replace("__SPY_BRANCH__", branch)
218+
text = text.replace("__SPY_COMMIT__", commit[:8])
219+
menufile.write_text(text)
220+
207221
def _patch_meta(self, meta):
208222
# Add source code patch
209223
search_patches = re.compile(
@@ -266,18 +280,30 @@ def _patch_build_script(self):
266280

267281
if os.name == 'posix':
268282
file = self._fdstk_path / "recipe" / "build.sh"
269-
build_patch = RESOURCES / "build-patch.sh"
270283
text = file.read_text()
271-
text += build_patch.read_text()
284+
text += dedent(
285+
"""
286+
# Create the Menu directory
287+
mkdir -p "${PREFIX}/Menu"
288+
289+
# Copy menu.json template
290+
cp "${SRC_DIR}/installers-conda/dist/spyder-menu.json" "${PREFIX}/Menu/spyder-menu.json"
291+
292+
# Copy application icons
293+
if [[ $OSTYPE == "darwin"* ]]; then
294+
cp "${SRC_DIR}/img_src/spyder.icns" "${PREFIX}/Menu/spyder.icns"
295+
else
296+
cp "${SRC_DIR}/branding/logo/logomark/spyder-logomark-background.png" "${PREFIX}/Menu/spyder.png"
297+
fi
298+
"""
299+
)
300+
272301
if os.name == 'nt':
273302
file = self._fdstk_path / "recipe" / "bld.bat"
274303
text = file.read_text()
275304
text = text.replace(
276305
r"copy %RECIPE_DIR%\menu-windows.json %MENU_DIR%\spyder_shortcut.json",
277-
r"""powershell -Command"""
278-
r""" "(gc %SRC_DIR%\installers-conda\resources\spyder-menu.json)"""
279-
r""" -replace '__PKG_VERSION__', '%PKG_VERSION%' | """
280-
r"""Out-File -encoding ASCII %MENU_DIR%\spyder-menu.json" """
306+
r"copy %SRC_DIR%\installers-conda\dist\spyder-menu.json %MENU_DIR%\spyder-menu.json"
281307
)
282308
file.rename(file.parent / ("_" + file.name)) # keep copy of original
283309
file.write_text(text)

installers-conda/resources/build-patch.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

installers-conda/resources/spyder-menu.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
"terminal": false,
1313
"platforms": {
1414
"win": {
15-
"desktop": true
15+
"desktop": true,
16+
"precommand": "set SPY_BRANCH=__SPY_BRANCH__\nset SPY_COMMIT=__SPY_COMMIT__"
1617
},
1718
"linux": {
1819
"Categories": [
1920
"Graphics",
2021
"Science"
21-
]
22+
],
23+
"precommand": "export SPY_BRANCH=__SPY_BRANCH__ && export SPY_COMMIT=__SPY_COMMIT__"
2224
},
2325
"osx": {
2426
"precommand": "eval \"$($SHELL -l -c \"declare -x\")\"",
@@ -35,7 +37,9 @@
3537
"CFBundleIdentifier": "org.spyder-ide.Spyder",
3638
"CFBundleVersion": "__PKG_VERSION__",
3739
"LSEnvironment": {
38-
"SPYDER_APP": "True"
40+
"SPYDER_APP": "True",
41+
"SPY_BRANCH": "__SPY_BRANCH__",
42+
"SPY_COMMIT": "__SPY_COMMIT__"
3943
}
4044
}
4145
}

0 commit comments

Comments
 (0)