Skip to content

Commit

Permalink
Merge pull request #22253 from mrclary/conda-lock
Browse files Browse the repository at this point in the history
PR: Update conda-lock for change in release workflow
  • Loading branch information
ccordoba12 authored Jul 16, 2024
2 parents 4f7976e + e28daaa commit 3b75314
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 118 deletions.
1 change: 1 addition & 0 deletions .github/workflows/installers-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ jobs:
env | sort
- name: Build ${{ matrix.target-platform }} spyder Conda Package
if: env.IS_RELEASE == 'false'
run: |
# Copy built packages to new build location because spyder cannot be
# built in workspace
Expand Down
22 changes: 1 addition & 21 deletions installers-conda/build_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,7 @@ def _create_conda_lock():
if logger.getEffectiveLevel() <= 20:
print(TMP_LOCK_FILE.read_text(), flush=True)


def _patch_conda_lock():
# Replace local channel url with conda-forge and remove checksum
dev_channel = ""
if SPYVER.is_prerelease:
dev_channel = "/label/spyder_dev"

tmp_text = TMP_LOCK_FILE.read_text()
text = re.sub(
f"^{_get_conda_bld_path_url()}(.*)#.*$",
fr"https://conda.anaconda.org/conda-forge{dev_channel}\1",
tmp_text, flags=re.MULTILINE
)
LOCK_FILE.write_text(text)

logger.info(f"Contents of {LOCK_FILE}:")
if logger.getEffectiveLevel() <= 20:
print(LOCK_FILE.read_text(), flush=True)
LOCK_FILE.write_text(TMP_LOCK_FILE.read_text())


def _generate_background_images(installer_type):
Expand Down Expand Up @@ -504,8 +487,6 @@ def main():
elapse = timedelta(seconds=int(time() - t0))
logger.info(f"Build time: {elapse}")

_patch_conda_lock()


if __name__ == "__main__":
if args.arch:
Expand All @@ -525,7 +506,6 @@ def main():
sys.exit()
if args.conda_lock:
_create_conda_lock()
_patch_conda_lock()
sys.exit()

main()
72 changes: 11 additions & 61 deletions spyder/plugins/updatemanager/tests/test_update_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def worker():
# ---- Test WorkerUpdate

@pytest.mark.parametrize("version", ["1.0.0", "1000.0.0"])
def test_updates_appenv(qtbot, mocker, version, caplog):
@pytest.mark.parametrize(
"channel", [
("pkgs/main", "https://repo.anaconda.com/pkgs/main"),
("conda-forge", "https://conda.anaconda.org/conda-forge"),
]
)
def test_updates(qtbot, mocker, caplog, version, channel):
"""
Test whether or not we offer updates for our installers according to the
current Spyder version.
Test whether or not we offer updates according to the current Spyder
version and package installation channel.
Uses UpdateManagerWidget in order to also test QThread.
"""
Expand All @@ -44,11 +50,8 @@ def test_updates_appenv(qtbot, mocker, version, caplog):
UpdateManagerWidget, "start_update", new=lambda x: None
)
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(workers, "is_anaconda", return_value=True)
mocker.patch.object(workers, "is_conda_based_app", return_value=True)
mocker.patch.object(
workers, "get_spyder_conda_channel",
return_value=("conda-forge", "https://conda.anaconda.org/conda-forge")
workers, "get_spyder_conda_channel", return_value=channel
)

with caplog.at_level(logging.DEBUG, logger='spyder.plugins.updatemanager'):
Expand All @@ -74,60 +77,7 @@ def test_updates_appenv(qtbot, mocker, version, caplog):
assert update_available
else:
assert not update_available
assert len(um.update_worker.releases) > 1


@pytest.mark.parametrize("version", ["1.0.0", "1000.0.0"])
@pytest.mark.parametrize(
"channel", [
("pkgs/main", "https://repo.anaconda.com/pkgs/main"),
("conda-forge", "https://conda.anaconda.org/conda-forge"),
("pypi", "https://conda.anaconda.org/pypi")
]
)
def test_updates_condaenv(qtbot, worker, mocker, version, channel):
"""
Test whether or not we offer updates for conda installed Spyder according
to the current version.
"""
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(workers, "is_anaconda", return_value=True)
mocker.patch.object(workers, "is_conda_based_app", return_value=False)
mocker.patch.object(
workers, "get_spyder_conda_channel", return_value=channel
)

with qtbot.waitSignal(worker.sig_ready, timeout=5000):
worker.start()

update_available = worker.update_available
if version.split('.')[0] == '1':
assert update_available
else:
assert not update_available
assert len(worker.releases) == 1


@pytest.mark.parametrize("version", ["1.0.0", "1000.0.0"])
def test_updates_pipenv(qtbot, worker, mocker, version):
"""Test updates for pip installed Spyder."""
mocker.patch.object(workers, "__version__", new=version)
mocker.patch.object(workers, "is_anaconda", return_value=False)
mocker.patch.object(workers, "is_conda_based_app", return_value=False)
mocker.patch.object(
workers, "get_spyder_conda_channel",
return_value=("pypi", "https://conda.anaconda.org/pypi")
)

with qtbot.waitSignal(worker.sig_ready, timeout=5000):
worker.start()

update_available = worker.update_available
if version.split('.')[0] == '1':
assert update_available
else:
assert not update_available
assert len(worker.releases) == 1
assert len(um.update_worker.releases) >= 1


@pytest.mark.parametrize("release", ["4.0.1", "4.0.1a1"])
Expand Down
56 changes: 20 additions & 36 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

# Local imports
from spyder import __version__
from spyder.config.base import (_, is_stable_version, is_conda_based_app,
running_in_ci)
from spyder.config.base import _, is_stable_version, running_in_ci
from spyder.config.utils import is_anaconda
from spyder.utils.conda import get_spyder_conda_channel
from spyder.utils.programs import check_version
Expand Down Expand Up @@ -120,7 +119,6 @@ def __init__(self, stable_only):
self.releases = None
self.update_available = False
self.error = None
self.channel = None

def _check_update_available(self):
"""Checks if there is an update available from releases."""
Expand All @@ -147,31 +145,19 @@ def start(self):
self.latest_release = None
self.update_available = False
error_msg = None
pypi_url = "https://pypi.org/pypi/spyder/json"
github_url = 'https://api.github.com/repos/spyder-ide/spyder/releases'

if is_conda_based_app():
url = github_url
elif is_anaconda():
self.channel, channel_url = get_spyder_conda_channel()

if self.channel is None or channel_url is None:
logger.debug(
f"channel = {self.channel}; channel_url = {channel_url}. "
)

# Spyder installed in development mode, use GitHub
url = github_url
elif self.channel == "pypi":
url = pypi_url
else:
url = 'https://api.github.com/repos/spyder-ide/spyder/releases'

# If Spyder is installed from defaults channel (pkgs/main), then use
# that channel to get updates. The defaults channel can be far behind
# our latest release
if is_anaconda():
channel, channel_url = get_spyder_conda_channel()
if channel == "pkgs/main":
url = channel_url + '/channeldata.json'
else:
url = pypi_url

headers = {}
token = os.getenv('GITHUB_TOKEN')
if running_in_ci() and url == github_url and token:
if running_in_ci() and token:
headers.update(Authorization=f"Bearer {token}")

logger.info(f"Checking for updates from {url}")
Expand All @@ -181,18 +167,16 @@ def start(self):
page.raise_for_status()

data = page.json()
if self.releases is None:
if url == github_url:
self.releases = [
item['tag_name'].replace('v', '') for item in data
]
elif url == pypi_url:
self.releases = [data['info']['version']]
else:
# Conda type url
spyder_data = data['packages'].get('spyder')
if spyder_data:
self.releases = [spyder_data["version"]]
if url.endswith('releases'):
# Github url
self.releases = [
item['tag_name'].replace('v', '') for item in data
]
else:
# Conda url
spyder_data = data['packages'].get('spyder')
if spyder_data:
self.releases = [spyder_data["version"]]
self.releases.sort(key=parse)

self._check_update_available()
Expand Down

0 comments on commit 3b75314

Please sign in to comment.