Skip to content

Commit

Permalink
Merge from 5.x: PR #20319
Browse files Browse the repository at this point in the history
Fixes #20176
  • Loading branch information
ccordoba12 committed Jan 12, 2023
2 parents d62ac9a + 00a9702 commit 2dbc9b8
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 72 deletions.
65 changes: 46 additions & 19 deletions installers-conda/build_conda_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, data={}, debug=False, shallow=False):
self._get_source(shallow=shallow)
self._get_version()

self._patch_source()

self.data = {'version': self.version}
self.data.update(data)

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

if self.source == HERE.parent:
self._bld_src = self.source
repo = Repo(self.source)
self.repo = Repo(self.source)
else:
# Determine source and commit
if self.source is not None:
Expand All @@ -97,10 +99,8 @@ def _get_source(self, shallow=False):
f"Cloning source shallow from tag {self.shallow_ver}...")
else:
self.logger.info("Cloning source...")
repo = Repo.clone_from(remote, **kwargs)
repo.git.checkout(commit)

self._patch_source(repo)
self.repo = Repo.clone_from(remote, **kwargs)
self.repo.git.checkout(commit)

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

def _patch_source(self, repo):
def _patch_source(self):
pass

def _patch_meta(self, meta):
Expand All @@ -127,7 +127,12 @@ def _patch_build_script(self):
pass

def patch_recipe(self):
"""Patch conda build recipe"""
"""
Patch conda build recipe
1. Patch meta.yaml
2. Patch build script
"""
if self._recipe_patched:
return

Expand Down Expand Up @@ -161,9 +166,8 @@ def build(self):
Build the conda package.
1. Patch the recipe
2. Patch the build script
3. Build the package
4. Remove cloned repositories
2. Build the package
3. Remove cloned repositories
"""
t0 = time()
try:
Expand Down Expand Up @@ -193,16 +197,27 @@ class SpyderCondaPkg(BuildCondaPkg):
feedstock = "https://github.com/conda-forge/spyder-feedstock"
shallow_ver = "v5.3.2"

def _patch_source(self, repo):
def _patch_source(self):
self.logger.info("Creating Spyder source patch...")

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

self.logger.info("Creating Spyder menu file...")
_menufile = RESOURCES / "spyder-menu.json"
menufile = DIST / "spyder-menu.json"
commit, branch = self.repo.head.commit.name_rev.split()
text = _menufile.read_text()
text = text.replace("__PKG_VERSION__", self.version)
text = text.replace("__SPY_BRANCH__", branch)
text = text.replace("__SPY_COMMIT__", commit[:8])
menufile.write_text(text)

def _patch_meta(self, meta):
# Add source code patch
search_patches = re.compile(
Expand Down Expand Up @@ -265,18 +280,30 @@ def _patch_build_script(self):

if os.name == 'posix':
file = self._fdstk_path / "recipe" / "build.sh"
build_patch = RESOURCES / "build-patch.sh"
text = file.read_text()
text += build_patch.read_text()
text += dedent(
"""
# Create the Menu directory
mkdir -p "${PREFIX}/Menu"
# Copy menu.json template
cp "${SRC_DIR}/installers-conda/dist/spyder-menu.json" "${PREFIX}/Menu/spyder-menu.json"
# Copy application icons
if [[ $OSTYPE == "darwin"* ]]; then
cp "${SRC_DIR}/img_src/spyder.icns" "${PREFIX}/Menu/spyder.icns"
else
cp "${SRC_DIR}/branding/logo/logomark/spyder-logomark-background.png" "${PREFIX}/Menu/spyder.png"
fi
"""
)

if os.name == 'nt':
file = self._fdstk_path / "recipe" / "bld.bat"
text = file.read_text()
text = text.replace(
r"copy %RECIPE_DIR%\menu-windows.json %MENU_DIR%\spyder_shortcut.json",
r"""powershell -Command"""
r""" "(gc %SRC_DIR%\installers-conda\resources\spyder-menu.json)"""
r""" -replace '__PKG_VERSION__', '%PKG_VERSION%' | """
r"""Out-File -encoding ASCII %MENU_DIR%\spyder-menu.json" """
r"copy %SRC_DIR%\installers-conda\dist\spyder-menu.json %MENU_DIR%\spyder-menu.json"
)
file.rename(file.parent / ("_" + file.name)) # keep copy of original
file.write_text(text)
Expand Down
17 changes: 9 additions & 8 deletions installers-conda/build_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ def _definitions():
"specs": [k + v for k, v in specs.items()],
},
},
"menu_packages": [
"spyder",
],
"extra_files": [
{str(RESOURCES / "bundle_readme.md"): "README.txt"},
{condarc: ".condarc"},
Expand All @@ -252,11 +249,16 @@ def _definitions():
definitions["channels"].insert(0, "local")

if LINUX:
definitions["default_prefix"] = os.path.join(
"$HOME", ".local", INSTALLER_DEFAULT_PATH_STEM
definitions.update(
{
"default_prefix": os.path.join(
"$HOME", ".local", INSTALLER_DEFAULT_PATH_STEM
),
"license_file": str(SPYREPO / "LICENSE.txt"),
"installer_type": "sh",
"post_install": str(RESOURCES / "post-install.sh"),
}
)
definitions["license_file"] = str(SPYREPO / "LICENSE.txt")
definitions["installer_type"] = "sh"

if MACOS:
welcome_text_tmpl = \
Expand All @@ -276,7 +278,6 @@ def _definitions():
"welcome_file": str(welcome_file),
"conclusion_text": "",
"readme_text": "",
"post_install": str(RESOURCES / "post-install.sh"),
}
)

Expand Down
14 changes: 0 additions & 14 deletions installers-conda/resources/build-patch.sh

This file was deleted.

87 changes: 61 additions & 26 deletions installers-conda/resources/post-install.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,72 @@
#!/bin/bash
set -e

echo "*** Starting post install script for __NAME__.app"

cat <<EOF
* __PKG_NAME_LOWER__
* __NAME__
* __VERSION__
* __CHANNELS__
* __WRITE_CONDARC__
* __SHORTCUTS__
* __DEFAULT_PREFIX__
* __LICENSE__
* __FIRST_PAYLOAD_SIZE__
* __SECOND_PAYLOAD_SIZE__
* __MD5__
* __INSTALL_COMMANDS__
* __PLAT__
* __NAME_LOWER__
EOF
echo "*** Running post install script for ${INSTALLER_NAME} ..."

echo "Args = $@"
echo "$(declare -p)"

ENV_PREFIX=$(cd "${PREFIX}/envs/__NAME_LOWER__"; pwd)
app_path="$(dirname ${DSTROOT})/Applications/__NAME__.app"
name_lower=${INSTALLER_NAME,,}
_shortcut_path="$HOME/.local/share/applications/${name_lower}_${name_lower}.desktop"
shortcut_path="$(dirname ${_shortcut_path})/${name_lower}.desktop"
if [[ -e ${_shortcut_path} ]]; then
echo "Renaming ${_shortcut_path}..."
mv -f "${_shortcut_path}" "${shortcut_path}"
else
echo "${_shortcut_path} does not exist"
fi

case $SHELL in
(*"zsh") shell_init=$HOME/.zshrc ;;
(*"bash") shell_init=$HOME/.bashrc ;;
esac
spy_exe=$(echo ${PREFIX}/envs/*/bin/spyder)
u_spy_exe=${PREFIX}/uninstall-spyder.sh

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

echo "*** Post install script for __NAME__.app complete"
echo "Creating uninstall script..."
cat <<EOF > ${u_spy_exe}
#!/bin/bash
rm -rf ${shortcut_path}
rm -rf ${PREFIX}
EOF
if [[ -n "$shell_init" ]]; then
# Remove aliases from shell startup
echo "sed -i '/$m1/,/$m2/d' $shell_init" >> ${u_spy_exe}
fi
chmod +x ${u_spy_exe}

cat <<EOF
###############################################################################
Spyder can be launched by standard methods in Gnome and KDE desktop
environments. Additionally, Spyder can be launched in Gtk-based desktop
environments (e.g. Xfce) from the command line:
$ gtk-launch spyder
Spyder can also be launched from the command line for all Linux variants
by:
$ spyder
To uninstall Spyder, you need to run from the following from the command line:
$ uninstall-spyder
###############################################################################
EOF

echo "*** Post install script for ${INSTALLER_NAME} complete"
21 changes: 16 additions & 5 deletions installers-conda/resources/spyder-menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,34 @@
"terminal": false,
"platforms": {
"win": {
"desktop": true
"desktop": true,
"precommand": "set SPY_BRANCH=__SPY_BRANCH__\nset SPY_COMMIT=__SPY_COMMIT__"
},
"linux": {
"Categories": [
"Graphics",
"Science"
]
],
"precommand": "export SPY_BRANCH=__SPY_BRANCH__ && export SPY_COMMIT=__SPY_COMMIT__"
},
"osx": {
"precommand": "eval \"$($SHELL -l -c \"declare -x\")\"\nhere=$(dirname \"$0\")",
"command": ["${here}/python", "${CONDA_PREFIX}/bin/spyder", "$@"],
"precommand": "eval \"$($SHELL -l -c \"declare -x\")\"",
"command": [
"{{ MENU_ITEM_LOCATION }}/Contents/MacOS/python",
"{{ PREFIX }}/bin/spyder",
"$@"
],
"link_in_bundle": {
"{{ PREFIX }}/bin/python": "{{ MENU_ITEM_LOCATION }}/Contents/MacOS/python"
},
"CFBundleName": "Spyder",
"CFBundleDisplayName": "Spyder",
"CFBundleIdentifier": "org.spyder-ide.Spyder",
"CFBundleVersion": "__PKG_VERSION__",
"LSEnvironment": {
"SPYDER_APP": "True"
"SPYDER_APP": "True",
"SPY_BRANCH": "__SPY_BRANCH__",
"SPY_COMMIT": "__SPY_COMMIT__"
}
}
}
Expand Down

0 comments on commit 2dbc9b8

Please sign in to comment.