Skip to content

Commit

Permalink
Merge pull request #20827 from mrclary/cbi-updates
Browse files Browse the repository at this point in the history
PR: Change logic to detect conda-based installers and micromamba on them
  • Loading branch information
ccordoba12 committed Apr 28, 2023
2 parents c51a481 + c524c92 commit 90ce9ee
Show file tree
Hide file tree
Showing 33 changed files with 170 additions and 293 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/installers-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ jobs:
with:
fetch-depth: 0

- name: Install pcregrep
if: runner.os == 'macOS'
run: |
if [[ -z "$(which pcregrep)" ]]; then
brew install pcre
else
echo "$(which pcregrep) already installed."
fi
- name: Setup Build Environment
uses: mamba-org/provision-with-micromamba@main
with:
Expand Down Expand Up @@ -225,7 +216,7 @@ jobs:
if: runner.os == 'macOS' && (env.IS_RELEASE == 'true' || env.IS_PRE == 'true')
run: |
./certkeychain.sh "${MACOS_CERTIFICATE_PWD}" "${MACOS_CERTIFICATE}" "${MACOS_INSTALLER_CERTIFICATE}"
CNAME=$(security find-identity -p codesigning -v | pcregrep -o1 "\(([0-9A-Z]+)\)")
CNAME=$(security find-identity -p codesigning -v | pcre2grep -o1 "\(([0-9A-Z]+)\)")
echo "CNAME=$CNAME" >> $GITHUB_ENV
_codesign=$(which codesign)
Expand Down
2 changes: 1 addition & 1 deletion installers-conda/build_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _definitions():
),
"license_file": str(SPYREPO / "LICENSE.txt"),
"installer_type": "sh",
"post_install": str(RESOURCES / "post-install.sh"),
"post_install": str(RESOURCES / "post-install-linux.sh"),
}
)

Expand Down
6 changes: 3 additions & 3 deletions installers-conda/notarize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ shift $(($OPTIND - 1))
PKG=$(cd $(dirname $1) && pwd -P)/$(basename $1) # Resolve full path

# --- Get certificate id
CNAME=$(security find-identity -p codesigning -v | pcregrep -o1 "\(([0-9A-Z]+)\)")
CNAME=$(security find-identity -p codesigning -v | pcre2grep -o1 "\(([0-9A-Z]+)\)")
[[ -z $CNAME ]] && log "Could not locate certificate ID" && exit 1
log "Certificate ID: $CNAME"

Expand All @@ -54,8 +54,8 @@ notarize_args+=("--team-id" "$CNAME" "${pwd_args[@]}")
log "Notarizing..."
xcrun notarytool submit $PKG --wait ${notarize_args[@]} | tee temp.txt

submitid=$(pcregrep -o1 "^\s*id: ([0-9a-z-]+)" temp.txt | head -1)
status=$(pcregrep -o1 "^\s*status: (\w+$)" temp.txt)
submitid=$(pcre2grep -o1 "^\s*id: ([0-9a-z-]+)" temp.txt | head -1)
status=$(pcre2grep -o1 "^\s*status: (\w+$)" temp.txt)
rm temp.txt

xcrun notarytool log $submitid ${notarize_args[@]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ by:
$ spyder
To uninstall Spyder, you need to run from the following from the command line:
To uninstall Spyder, run the following from the command line:
$ uninstall-spyder
Expand Down
6 changes: 3 additions & 3 deletions installers-conda/resources/spyder-menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
"name": "Spyder",
"description": "Scientific PYthon Development EnviRonment",
"icon": "{{ MENU_DIR }}/spyder.{{ ICON_EXT }}",
"command": ["spyder", "$@"],
"activate": true,
"terminal": false,
"platforms": {
"win": {
"desktop": true,
"precommand": "set SPY_BRANCH=__SPY_BRANCH__\nset SPY_COMMIT=__SPY_COMMIT__"
"precommand": "set SPY_BRANCH=__SPY_BRANCH__\nset SPY_COMMIT=__SPY_COMMIT__",
"command": ["spyder", "%*"]
},
"linux": {
"Categories": [
"Graphics",
"Science"
],
"precommand": "export SPY_BRANCH=__SPY_BRANCH__ && export SPY_COMMIT=__SPY_COMMIT__",
"command": ["spyder", "$@"],
"StartupWMClass": "Spyder"
},
"osx": {
Expand All @@ -38,7 +39,6 @@
"CFBundleIdentifier": "org.spyder-ide.Spyder",
"CFBundleVersion": "__PKG_VERSION__",
"LSEnvironment": {
"SPYDER_APP": "True",
"SPY_BRANCH": "__SPY_BRANCH__",
"SPY_COMMIT": "__SPY_COMMIT__"
}
Expand Down
17 changes: 7 additions & 10 deletions spyder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,16 @@ def get_versions(reporev=True):
import qtpy.QtCore

from spyder.utils.conda import is_conda_env
from spyder.config.base import is_pynsist, running_in_mac_app
from spyder.config.base import is_conda_based_app

revision = branch = None
if reporev:
if running_in_mac_app():
revision = os.environ.get('SPY_COMMIT', None)
branch = os.environ.get('SPY_BRANCH', None)
else:
from spyder.utils import vcs
revision, branch = vcs.get_git_revision(
os.path.dirname(__current_directory__))

if is_pynsist() or running_in_mac_app():
from spyder.utils import vcs
revision, branch = vcs.get_git_revision(
os.path.dirname(__current_directory__)
)

if is_conda_based_app():
installer = 'standalone'
elif is_conda_env(pyexec=sys.executable):
installer = 'conda'
Expand Down
2 changes: 1 addition & 1 deletion spyder/app/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_options(argv=None):
default=None,
type=str,
dest="project",
help="Path that contains an Spyder project"
help="Path that contains a Spyder project"
)
parser.add_argument(
'--opengl',
Expand Down
4 changes: 2 additions & 2 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.config.base import (_, DEV, get_conf_path, get_debug_level,
get_home_dir, is_pynsist, running_in_mac_app,
get_home_dir, is_conda_based_app,
running_under_pytest, STDERR)
from spyder.config.gui import is_dark_font_color
from spyder.config.main import OPEN_FILES_PORT
Expand Down Expand Up @@ -945,7 +945,7 @@ def set_window_title(self):
title = u"Spyder %s (Python %s.%s)" % (__version__,
sys.version_info[0],
sys.version_info[1])
elif running_in_mac_app() or is_pynsist():
elif is_conda_based_app():
title = "Spyder"
else:
title = u"Spyder (Python %s.%s)" % (sys.version_info[0],
Expand Down
17 changes: 13 additions & 4 deletions spyder/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@

# Local imports
from spyder.app.cli_options import get_options
from spyder.config.base import (get_conf_path, running_in_mac_app,
reset_config_files, running_under_pytest)
from spyder.config.base import (get_conf_path, reset_config_files,
running_under_pytest, is_conda_based_app)
from spyder.utils.conda import get_conda_root_prefix
from spyder.utils.external import lockfile
from spyder.py3compat import is_text_string

# Enforce correct CONDA_EXE environment variable
# Do not rely on CONDA_PYTHON_EXE or CONDA_PREFIX in case Spyder is started
# from the commandline
if is_conda_based_app():
conda_root = get_conda_root_prefix()
if os.name == 'nt':
os.environ['CONDA_EXE'] = conda_root + r'\Scripts\conda.exe'
else:
os.environ['CONDA_EXE'] = conda_root + '/bin/conda'

# Get argv
if running_under_pytest():
Expand Down Expand Up @@ -200,8 +210,7 @@ def main():
return

if (CONF.get('main', 'single_instance') and not options.new_instance
and not options.reset_config_files
and not running_in_mac_app()):
and not options.reset_config_files):
# Minimal delay (0.1-0.2 secs) to avoid that several
# instances started at the same time step in their
# own foots while trying to create the lock file
Expand Down
4 changes: 2 additions & 2 deletions spyder/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Local imports
from spyder.config.base import (
DEV, get_conf_path, get_debug_level, running_in_mac_app,
DEV, get_conf_path, get_debug_level, is_conda_based_app,
running_under_pytest)
from spyder.config.manager import CONF
from spyder.utils.external.dafsa.dafsa import DAFSA
Expand Down Expand Up @@ -312,7 +312,7 @@ def create_window(WindowClass, app, splash, options, args):

# Open external files with our Mac app
# ??? Do we need this?
if running_in_mac_app():
if sys.platform == 'darwin' and is_conda_based_app():
app.sig_open_external_file.connect(main.open_external_file)
app._has_started = True
if hasattr(app, '_pending_file_open'):
Expand Down
55 changes: 17 additions & 38 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
sip API incompatibility issue in spyder's non-gui modules)
"""

from glob import glob
import locale
import os
import os.path as osp
Expand Down Expand Up @@ -341,16 +342,6 @@ def is_py2exe_or_cx_Freeze():
return osp.isfile(osp.join(get_module_path('spyder'), osp.pardir))


def is_pynsist():
"""Return True if this is a pynsist installation of Spyder."""
base_path = osp.abspath(osp.dirname(__file__))
pkgs_path = osp.abspath(
osp.join(base_path, '..', '..', '..', 'pkgs'))
if os.environ.get('PYTHONPATH') is not None:
return pkgs_path in os.environ.get('PYTHONPATH')
return False


#==============================================================================
# Translations
#==============================================================================
Expand Down Expand Up @@ -541,44 +532,32 @@ def translate_gettext(x):


#==============================================================================
# Mac application utilities
# Conda-based installer application utilities
#==============================================================================
def running_in_mac_app(pyexec=sys.executable):
def is_conda_based_app(pyexec=sys.executable):
"""
Check if Spyder is running as a macOS bundle app by looking for the
`SPYDER_APP` environment variable.
Check if Spyder is running from the conda-based installer by looking for
the `spyder-menu.json` file.
If a python executable is provided, checks if it is the same as the macOS
bundle app environment executable.
If a Python executable is provided, checks if it is in a conda-based
installer environment or the root environment thereof.
"""
# Spyder is macOS app
mac_app = os.environ.get('SPYDER_APP') is not None
real_pyexec = osp.realpath(pyexec) # pyexec may be symlink
if os.name == 'nt':
env_path = osp.dirname(real_pyexec)
else:
env_path = osp.dirname(osp.dirname(real_pyexec))

if sys.platform == 'darwin' and mac_app and pyexec == sys.executable:
# executable is macOS app
menu_rel_path = '/Menu/spyder-menu.json'
if (
osp.exists(env_path + menu_rel_path)
or glob(env_path + '/envs/*' + menu_rel_path)
):
return True
else:
return False


# =============================================================================
# Micromamba
# =============================================================================
def get_spyder_umamba_path():
"""Return the path to the Micromamba executable bundled with Spyder."""
if running_in_mac_app():
# TODO: Change to CONDA_EXE when
# conda-forge/conda-standalone-feedstock#45 is resolved
path = os.environ.get('CONDA_PYTHON_EXE')
elif is_pynsist():
path = osp.abspath(osp.join(osp.dirname(osp.dirname(__file__)),
'bin', 'micromamba.exe'))
else:
path = None

return path


#==============================================================================
# Reset config files
#==============================================================================
Expand Down
12 changes: 4 additions & 8 deletions spyder/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys

# Local imports
from spyder.config.base import _, is_pynsist, running_in_ci, running_in_mac_app
from spyder.config.base import _, running_in_ci, is_conda_based_app
from spyder.utils import programs

HERE = osp.dirname(osp.abspath(__file__))
Expand All @@ -35,9 +35,7 @@
CLOUDPICKLE_REQVER = '>=0.5.0'
COOKIECUTTER_REQVER = '>=1.6.0'
DIFF_MATCH_PATCH_REQVER = '>=20181111'
# None for pynsist install for now
# (check way to add dist.info/egg.info from packages without wheels available)
INTERVALTREE_REQVER = None if is_pynsist() else '>=3.0.2'
INTERVALTREE_REQVER = '>=3.0.2'
IPYTHON_REQVER = ">=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0"
JEDI_REQVER = '>=0.17.2,<0.19.0'
JELLYFISH_REQVER = '>=0.7'
Expand Down Expand Up @@ -69,9 +67,7 @@
SPYDER_KERNELS_REQVER = '>=2.4.3,<2.5.0'
TEXTDISTANCE_REQVER = '>=4.2.0'
THREE_MERGE_REQVER = '>=0.1.1'
# None for pynsist install for now
# (check way to add dist.info/egg.info from packages without wheels available)
WATCHDOG_REQVER = None if is_pynsist() else '>=0.10.3'
WATCHDOG_REQVER = '>=0.10.3'


# Optional dependencies
Expand All @@ -95,7 +91,7 @@
'package_name': "applaunchservices",
'features': _("Notify macOS that Spyder can open Python files"),
'required_version': APPLAUNCHSERVICES_REQVER,
'display': sys.platform == "darwin" and not running_in_mac_app()},
'display': sys.platform == "darwin" and not is_conda_based_app()},
{'modname': "atomicwrites",
'package_name': "atomicwrites",
'features': _("Atomic file writes in the Editor"),
Expand Down
9 changes: 5 additions & 4 deletions spyder/plugins/application/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
QVBoxLayout, QWidget)

from spyder.config.base import (_, DISABLED_LANGUAGES, LANGUAGE_CODES,
running_in_mac_app, save_lang_conf)
is_conda_based_app, save_lang_conf)
from spyder.api.preferences import PluginConfigPage
from spyder.py3compat import to_text_string

Expand Down Expand Up @@ -69,7 +69,8 @@ def setup_page(self):
'check_updates_on_startup')

# Decide if it's possible to activate or not single instance mode
if running_in_mac_app():
# ??? Should we allow multiple instances for macOS?
if sys.platform == 'darwin' and is_conda_based_app():
self.set_option("single_instance", True)
single_instance_box.setEnabled(False)

Expand Down Expand Up @@ -135,7 +136,7 @@ def setup_page(self):
interface_layout.addLayout(margins_cursor_layout)
interface_group.setLayout(interface_layout)

if sys.platform == "darwin" and not running_in_mac_app():
if sys.platform == "darwin" and not is_conda_based_app():
# To open files from Finder directly in Spyder.
from spyder.utils.qthelpers import (register_app_launchservices,
restore_launchservices)
Expand Down Expand Up @@ -224,7 +225,7 @@ def set_open_file(state):

screen_resolution_layout.addLayout(screen_resolution_inner_layout)
screen_resolution_group.setLayout(screen_resolution_layout)
if sys.platform == "darwin" and not running_in_mac_app():
if sys.platform == "darwin" and not is_conda_based_app():
interface_tab = self.create_tab(screen_resolution_group,
interface_group, macOS_group)
else:
Expand Down
8 changes: 4 additions & 4 deletions spyder/plugins/application/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from spyder.api.widgets.main_container import PluginMainContainer
from spyder.utils.installers import InstallerMissingDependencies
from spyder.config.utils import is_anaconda
from spyder.config.base import (get_conf_path, get_debug_level, is_pynsist,
running_in_mac_app)
from spyder.config.base import (get_conf_path, get_debug_level,
is_conda_based_app)
from spyder.plugins.application.widgets.status import ApplicationUpdateStatus
from spyder.plugins.console.api import ConsoleActions
from spyder.utils.environ import UserEnvDialog
Expand Down Expand Up @@ -105,7 +105,7 @@ def setup(self):
# Attributes
self.dialog_manager = DialogManager()
self.application_update_status = None
if is_pynsist() or running_in_mac_app():
if is_conda_based_app():
self.application_update_status = ApplicationUpdateStatus(
parent=self)
(self.application_update_status.sig_check_for_updates_requested
Expand Down Expand Up @@ -318,7 +318,7 @@ def _check_updates_ready(self):
"<code>conda update anaconda</code><br>"
"<code>conda install spyder={}</code><br><br>"
).format(latest_release)
elif is_pynsist() or running_in_mac_app():
elif is_conda_based_app():
box.setStandardButtons(QMessageBox.Yes |
QMessageBox.No)
content = _(
Expand Down
Loading

0 comments on commit 90ce9ee

Please sign in to comment.