Skip to content

Commit 2dbc9b8

Browse files
committed
Merge from 5.x: PR #20319
Fixes #20176
2 parents d62ac9a + 00a9702 commit 2dbc9b8

File tree

5 files changed

+132
-72
lines changed

5 files changed

+132
-72
lines changed

installers-conda/build_conda_pkgs.py

Lines changed: 46 additions & 19 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,16 +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("..origin/installers-conda-patch",
200-
"--stdout")
203+
patch = self.repo.git.format_patch(
204+
"..origin/installers-conda-patch", "--stdout", "-U3"
205+
)
201206
# newline keyword is not added to pathlib until Python>=3.10,
202207
# so we must use open to ensure LF on Windows
203208
with open(SPYPATCHFILE, 'w', newline='\n') as f:
204209
f.write(patch)
205210

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+
206221
def _patch_meta(self, meta):
207222
# Add source code patch
208223
search_patches = re.compile(
@@ -265,18 +280,30 @@ def _patch_build_script(self):
265280

266281
if os.name == 'posix':
267282
file = self._fdstk_path / "recipe" / "build.sh"
268-
build_patch = RESOURCES / "build-patch.sh"
269283
text = file.read_text()
270-
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+
271301
if os.name == 'nt':
272302
file = self._fdstk_path / "recipe" / "bld.bat"
273303
text = file.read_text()
274304
text = text.replace(
275305
r"copy %RECIPE_DIR%\menu-windows.json %MENU_DIR%\spyder_shortcut.json",
276-
r"""powershell -Command"""
277-
r""" "(gc %SRC_DIR%\installers-conda\resources\spyder-menu.json)"""
278-
r""" -replace '__PKG_VERSION__', '%PKG_VERSION%' | """
279-
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"
280307
)
281308
file.rename(file.parent / ("_" + file.name)) # keep copy of original
282309
file.write_text(text)

installers-conda/build_installers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ def _definitions():
239239
"specs": [k + v for k, v in specs.items()],
240240
},
241241
},
242-
"menu_packages": [
243-
"spyder",
244-
],
245242
"extra_files": [
246243
{str(RESOURCES / "bundle_readme.md"): "README.txt"},
247244
{condarc: ".condarc"},
@@ -252,11 +249,16 @@ def _definitions():
252249
definitions["channels"].insert(0, "local")
253250

254251
if LINUX:
255-
definitions["default_prefix"] = os.path.join(
256-
"$HOME", ".local", INSTALLER_DEFAULT_PATH_STEM
252+
definitions.update(
253+
{
254+
"default_prefix": os.path.join(
255+
"$HOME", ".local", INSTALLER_DEFAULT_PATH_STEM
256+
),
257+
"license_file": str(SPYREPO / "LICENSE.txt"),
258+
"installer_type": "sh",
259+
"post_install": str(RESOURCES / "post-install.sh"),
260+
}
257261
)
258-
definitions["license_file"] = str(SPYREPO / "LICENSE.txt")
259-
definitions["installer_type"] = "sh"
260262

261263
if MACOS:
262264
welcome_text_tmpl = \
@@ -276,7 +278,6 @@ def _definitions():
276278
"welcome_file": str(welcome_file),
277279
"conclusion_text": "",
278280
"readme_text": "",
279-
"post_install": str(RESOURCES / "post-install.sh"),
280281
}
281282
)
282283

installers-conda/resources/build-patch.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,72 @@
11
#!/bin/bash
22
set -e
33

4-
echo "*** Starting post install script for __NAME__.app"
5-
6-
cat <<EOF
7-
* __PKG_NAME_LOWER__
8-
* __NAME__
9-
* __VERSION__
10-
* __CHANNELS__
11-
* __WRITE_CONDARC__
12-
* __SHORTCUTS__
13-
* __DEFAULT_PREFIX__
14-
* __LICENSE__
15-
* __FIRST_PAYLOAD_SIZE__
16-
* __SECOND_PAYLOAD_SIZE__
17-
* __MD5__
18-
* __INSTALL_COMMANDS__
19-
* __PLAT__
20-
* __NAME_LOWER__
21-
EOF
4+
echo "*** Running post install script for ${INSTALLER_NAME} ..."
225

236
echo "Args = $@"
247
echo "$(declare -p)"
258

26-
ENV_PREFIX=$(cd "${PREFIX}/envs/__NAME_LOWER__"; pwd)
27-
app_path="$(dirname ${DSTROOT})/Applications/__NAME__.app"
9+
name_lower=${INSTALLER_NAME,,}
10+
_shortcut_path="$HOME/.local/share/applications/${name_lower}_${name_lower}.desktop"
11+
shortcut_path="$(dirname ${_shortcut_path})/${name_lower}.desktop"
12+
if [[ -e ${_shortcut_path} ]]; then
13+
echo "Renaming ${_shortcut_path}..."
14+
mv -f "${_shortcut_path}" "${shortcut_path}"
15+
else
16+
echo "${_shortcut_path} does not exist"
17+
fi
18+
19+
case $SHELL in
20+
(*"zsh") shell_init=$HOME/.zshrc ;;
21+
(*"bash") shell_init=$HOME/.bashrc ;;
22+
esac
23+
spy_exe=$(echo ${PREFIX}/envs/*/bin/spyder)
24+
u_spy_exe=${PREFIX}/uninstall-spyder.sh
2825

29-
if [[ -e "$app_path" ]]; then
30-
echo "Creating python symbolic link..."
31-
ln -sf "${ENV_PREFIX}/bin/python" "$app_path/Contents/MacOS/python"
26+
if [[ ! -e "$spy_exe" ]]; then
27+
echo "$spy_exe not found. Alias not created."
28+
elif [[ -z "$shell_init" ]]; then
29+
echo "Aliasing for $SHELL not implemented."
3230
else
33-
echo "ERROR: $app_path does not exist"
34-
exit 1
31+
echo "Aliasing Spyder's executable in $shell_init ..."
32+
m1="# <<<< Added by Spyder <<<<"
33+
m2="# >>>> Added by Spyder >>>>"
34+
new_text="$m1\nalias spyder=${spy_exe}\nalias uninstall-spyder=${u_spy_exe}\n$m2"
35+
sed -i "/$m1/,/$m2/{h;/$m2/ s|.*|${new_text}|; t; d};\${x;/^$/{s||\n${new_text}|;H};x}" $shell_init
3536
fi
3637

37-
echo "*** Post install script for __NAME__.app complete"
38+
echo "Creating uninstall script..."
39+
cat <<EOF > ${u_spy_exe}
40+
#!/bin/bash
41+
rm -rf ${shortcut_path}
42+
rm -rf ${PREFIX}
43+
EOF
44+
if [[ -n "$shell_init" ]]; then
45+
# Remove aliases from shell startup
46+
echo "sed -i '/$m1/,/$m2/d' $shell_init" >> ${u_spy_exe}
47+
fi
48+
chmod +x ${u_spy_exe}
49+
50+
cat <<EOF
51+
52+
###############################################################################
53+
Spyder can be launched by standard methods in Gnome and KDE desktop
54+
environments. Additionally, Spyder can be launched in Gtk-based desktop
55+
environments (e.g. Xfce) from the command line:
56+
57+
$ gtk-launch spyder
58+
59+
Spyder can also be launched from the command line for all Linux variants
60+
by:
61+
62+
$ spyder
63+
64+
To uninstall Spyder, you need to run from the following from the command line:
65+
66+
$ uninstall-spyder
67+
68+
###############################################################################
69+
70+
EOF
71+
72+
echo "*** Post install script for ${INSTALLER_NAME} complete"

installers-conda/resources/spyder-menu.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@
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": {
24-
"precommand": "eval \"$($SHELL -l -c \"declare -x\")\"\nhere=$(dirname \"$0\")",
25-
"command": ["${here}/python", "${CONDA_PREFIX}/bin/spyder", "$@"],
26+
"precommand": "eval \"$($SHELL -l -c \"declare -x\")\"",
27+
"command": [
28+
"{{ MENU_ITEM_LOCATION }}/Contents/MacOS/python",
29+
"{{ PREFIX }}/bin/spyder",
30+
"$@"
31+
],
32+
"link_in_bundle": {
33+
"{{ PREFIX }}/bin/python": "{{ MENU_ITEM_LOCATION }}/Contents/MacOS/python"
34+
},
2635
"CFBundleName": "Spyder",
2736
"CFBundleDisplayName": "Spyder",
2837
"CFBundleIdentifier": "org.spyder-ide.Spyder",
2938
"CFBundleVersion": "__PKG_VERSION__",
3039
"LSEnvironment": {
31-
"SPYDER_APP": "True"
40+
"SPYDER_APP": "True",
41+
"SPY_BRANCH": "__SPY_BRANCH__",
42+
"SPY_COMMIT": "__SPY_COMMIT__"
3243
}
3344
}
3445
}

0 commit comments

Comments
 (0)