libcsound 0.18.0__tar.gz → 0.18.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {libcsound-0.18.0 → libcsound-0.18.2}/PKG-INFO +1 -1
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/_dll.py +4 -412
- libcsound-0.18.2/libcsound/_install.py +514 -0
- libcsound-0.18.2/libcsound/_terminal.py +114 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/data/getcsound.ps1 +64 -1
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/data/getcsound.sh +25 -5
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/PKG-INFO +1 -1
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/SOURCES.txt +2 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/scm_file_list.json +2 -0
- libcsound-0.18.2/libcsound.egg-info/scm_version.json +8 -0
- libcsound-0.18.0/libcsound.egg-info/scm_version.json +0 -8
- {libcsound-0.18.0 → libcsound-0.18.2}/.github/workflows/test.yml +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/AGENTS.md +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/LICENSE +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/MANIFEST.in +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/README.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/cmake/csound-custom-macos.cmake +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/Makefile +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/_static/custom.css +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/conf.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/csound6.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/csound7.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/index.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/introduction.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/make.bat +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/01-Introduction.ipynb +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/02-Threading.ipynb +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/no-queue.png +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/no-queue.wav +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/threading-example1.mp3 +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/threading-example2.mp3 +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks/with-queue.wav +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/notebooks.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/porting.rst +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/docs/requirements.txt +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/__init__.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/_util.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/api6.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/api7.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/common.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound/py.typed +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/dependency_links.txt +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/requires.txt +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/libcsound.egg-info/top_level.txt +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/pyproject.toml +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/setup.cfg +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/actions-test1.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/actionstest.csd +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/bufferInOut.csd +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/check-installer-sync.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/linux-install-render.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/macos-install-render.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/numpfields.csd +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/simple1.csd +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/simple2.csd +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/test-numpfields.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/test0.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/test1.py +0 -0
- {libcsound-0.18.0 → libcsound-0.18.2}/test/windows-install-render.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libcsound
|
|
3
|
-
Version: 0.18.
|
|
3
|
+
Version: 0.18.2
|
|
4
4
|
Summary: Python bindings to the Csound API, supporting all versions of csound higher or equal to 6.18, including csound 7
|
|
5
5
|
Author-email: Eduardo Moguillansky <eduardo.moguillansky@gmail.com>
|
|
6
6
|
License: GNU LESSER GENERAL PUBLIC LICENSE
|
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
import ctypes as ct
|
|
3
3
|
import ctypes.util
|
|
4
4
|
import sys
|
|
5
|
-
import hashlib
|
|
6
5
|
import os
|
|
7
6
|
from .common import BUILDING_DOCS, logger
|
|
8
7
|
from typing import Sequence
|
|
@@ -439,13 +438,14 @@ def csoundDLL(install=True) -> tuple[ct.CDLL, str]:
|
|
|
439
438
|
return _libcsound, _libcsoundpath
|
|
440
439
|
|
|
441
440
|
if install:
|
|
441
|
+
from . import _install
|
|
442
442
|
try:
|
|
443
443
|
if sys.platform == 'linux':
|
|
444
|
-
|
|
444
|
+
_install.install_csound_linux()
|
|
445
445
|
elif sys.platform == 'darwin':
|
|
446
|
-
|
|
446
|
+
_install.install_csound_macos()
|
|
447
447
|
elif sys.platform.startswith('win'):
|
|
448
|
-
|
|
448
|
+
_install.install_csound_windows()
|
|
449
449
|
except ImportError:
|
|
450
450
|
raise
|
|
451
451
|
except (RuntimeError, OSError) as e:
|
|
@@ -523,411 +523,3 @@ def _ensure_user_plugins_dir(version: int | None = None) -> None:
|
|
|
523
523
|
os.environ["CS_USER_PLUGINDIR"] = str(pluginsdir)
|
|
524
524
|
|
|
525
525
|
|
|
526
|
-
def _hexdigest(path: str) -> str:
|
|
527
|
-
hashsum = hashlib.sha256()
|
|
528
|
-
with open(path, "rb") as f:
|
|
529
|
-
for chunk in iter(lambda: f.read(65536), b""):
|
|
530
|
-
hashsum.update(chunk)
|
|
531
|
-
return hashsum.hexdigest()
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
def _download(url: str, target: str, verbose=False, retries: int = 3) -> None:
|
|
535
|
-
import time
|
|
536
|
-
import urllib.request
|
|
537
|
-
import urllib.error
|
|
538
|
-
import http.client
|
|
539
|
-
import shutil
|
|
540
|
-
asset = os.path.basename(target)
|
|
541
|
-
if verbose:
|
|
542
|
-
print("Downloading URL:", url, "to", target)
|
|
543
|
-
else:
|
|
544
|
-
logger.info("Downloading URL: %s to %s...", url, asset)
|
|
545
|
-
last_error: Exception | None = None
|
|
546
|
-
for attempt in range(1, retries + 1):
|
|
547
|
-
try:
|
|
548
|
-
req = urllib.request.Request(url, headers={"User-Agent": "libcsound"})
|
|
549
|
-
with urllib.request.urlopen(req, timeout=120) as resp, \
|
|
550
|
-
open(target, "wb") as out:
|
|
551
|
-
shutil.copyfileobj(resp, out)
|
|
552
|
-
return
|
|
553
|
-
except (OSError, http.client.HTTPException, ValueError) as e:
|
|
554
|
-
# OSError covers urllib.error.URLError/HTTPError, socket and file errors;
|
|
555
|
-
# HTTPException covers BadStatusLine/IncompleteRead; ValueError covers
|
|
556
|
-
# malformed/unknown URLs.
|
|
557
|
-
last_error = e
|
|
558
|
-
if attempt < retries:
|
|
559
|
-
wait = 2 * attempt
|
|
560
|
-
logger.warning("Download of '%s' failed (attempt %d/%d): %s. "
|
|
561
|
-
"Retrying in %ds...",
|
|
562
|
-
asset, attempt, retries, e, wait)
|
|
563
|
-
time.sleep(wait)
|
|
564
|
-
raise RuntimeError(f"Failed to download '{asset}' from {url} "
|
|
565
|
-
f"(temporary file: {target}) after {retries} attempts\n"
|
|
566
|
-
f"{last_error}") from last_error
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
def _run_installer(cmd: Sequence[str], failure_hint: str = "") -> None:
|
|
570
|
-
"""Run an installer command, streaming its output live while capturing it.
|
|
571
|
-
|
|
572
|
-
The child inherits stdin so interactive prompts keep working; stdout and
|
|
573
|
-
stderr are merged, printed as they arrive (so progress stays visible) and
|
|
574
|
-
retained for diagnostics.
|
|
575
|
-
|
|
576
|
-
Raises:
|
|
577
|
-
RuntimeError: if the command exits with a non-zero status. The error
|
|
578
|
-
includes the exit status, the full command, the tail of the
|
|
579
|
-
captured output and ``failure_hint``.
|
|
580
|
-
"""
|
|
581
|
-
import subprocess
|
|
582
|
-
logger.info("Running bundled installer: %s", " ".join(str(c) for c in cmd))
|
|
583
|
-
proc = subprocess.Popen(list(cmd),
|
|
584
|
-
stdout=subprocess.PIPE,
|
|
585
|
-
stderr=subprocess.STDOUT,
|
|
586
|
-
text=True, bufsize=1)
|
|
587
|
-
lines: list[str] = []
|
|
588
|
-
assert proc.stdout is not None
|
|
589
|
-
for line in proc.stdout:
|
|
590
|
-
lines.append(line)
|
|
591
|
-
print(line, end="")
|
|
592
|
-
returncode = proc.wait()
|
|
593
|
-
if returncode != 0:
|
|
594
|
-
tail = "".join(lines[-50:]).rstrip() or "<no output captured>"
|
|
595
|
-
message = (f"Installer exited with status {returncode}\n"
|
|
596
|
-
f"Command: {' '.join(str(c) for c in cmd)}\n"
|
|
597
|
-
f"--- installer output (last {min(len(lines), 50)} lines) ---\n"
|
|
598
|
-
f"{tail}")
|
|
599
|
-
if failure_hint:
|
|
600
|
-
message += f"\n{failure_hint}"
|
|
601
|
-
raise RuntimeError(message)
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
def _install_csound_linux() -> None:
|
|
605
|
-
"""Install the latest csound 7 portable release for linux.
|
|
606
|
-
|
|
607
|
-
This mirrors the process of the one-line installer at
|
|
608
|
-
https://csound-plugins.github.io/getcsound.sh
|
|
609
|
-
|
|
610
|
-
It downloads the release asset ``csound7-linux-<arch>.zip`` from the
|
|
611
|
-
``csound-plugins/csound-plugins`` GitHub repository, verifies the
|
|
612
|
-
SHA-256 checksum, extracts it and runs the
|
|
613
|
-
bundled ``install.sh``. When running inside a tty the installer is run
|
|
614
|
-
interactively; otherwise it is run with ``--user -y`` so that csound is
|
|
615
|
-
installed to ``~/.local/csound``
|
|
616
|
-
|
|
617
|
-
After a successful installation, the environment variables ``LIBCSOUNDPATH``
|
|
618
|
-
and ``OPCODE7DIR64`` point to the installed library and plugin
|
|
619
|
-
directory, so that the current process can find csound without
|
|
620
|
-
the need to open a new terminal.
|
|
621
|
-
|
|
622
|
-
Raises:
|
|
623
|
-
RuntimeError: if the download or the checksum verification failed, if the
|
|
624
|
-
bundled ``install.sh`` could not be found or failed, or if csound
|
|
625
|
-
could not be located post installation.
|
|
626
|
-
"""
|
|
627
|
-
import platform
|
|
628
|
-
import stat
|
|
629
|
-
import tempfile
|
|
630
|
-
import zipfile
|
|
631
|
-
|
|
632
|
-
repo = "csound-plugins/csound-plugins"
|
|
633
|
-
tag = os.getenv("CSOUND7_TAG", "latest")
|
|
634
|
-
|
|
635
|
-
# Detect the CPU architecture
|
|
636
|
-
machine = platform.machine().lower()
|
|
637
|
-
if machine in ("x86_64", "amd64"):
|
|
638
|
-
arch = "x86_64"
|
|
639
|
-
elif machine in ("aarch64", "arm64"):
|
|
640
|
-
arch = "aarch64"
|
|
641
|
-
else:
|
|
642
|
-
raise RuntimeError(f"Unsupported architecture: {machine}. "
|
|
643
|
-
"Supported architectures: x86_64, aarch64.")
|
|
644
|
-
|
|
645
|
-
asset = os.getenv("CSOUND7_ASSET", f"csound7-linux-{arch}.zip")
|
|
646
|
-
checksum_asset = f"{asset}.sha256"
|
|
647
|
-
if tag == 'latest':
|
|
648
|
-
# Notice how github changes the format to address the latest release
|
|
649
|
-
base_url = f"https://github.com/{repo}/releases/latest/download"
|
|
650
|
-
else:
|
|
651
|
-
# Here this is a real tag, it must exist
|
|
652
|
-
base_url = f"https://github.com/{repo}/releases/download/{tag}"
|
|
653
|
-
|
|
654
|
-
checksum_url = f"{base_url}/{checksum_asset}"
|
|
655
|
-
|
|
656
|
-
with tempfile.TemporaryDirectory(prefix="libcsound-install-") as tmpdir:
|
|
657
|
-
zip_path = os.path.join(tmpdir, asset)
|
|
658
|
-
checksum_path = f"{zip_path}.sha256"
|
|
659
|
-
_download(f"{base_url}/{asset}", zip_path, verbose=True)
|
|
660
|
-
_download(checksum_url, checksum_path)
|
|
661
|
-
|
|
662
|
-
# Verify SHA256 checksum before extracting
|
|
663
|
-
try:
|
|
664
|
-
with open(checksum_path, encoding="utf-8") as f:
|
|
665
|
-
tokens = f.readline().split()
|
|
666
|
-
except (OSError, UnicodeDecodeError) as e:
|
|
667
|
-
raise RuntimeError(
|
|
668
|
-
f"Could not read the checksum file downloaded from {checksum_url}: {e}"
|
|
669
|
-
) from e
|
|
670
|
-
expected = tokens[0] if tokens else ""
|
|
671
|
-
actual = _hexdigest(zip_path)
|
|
672
|
-
if not expected or expected != actual:
|
|
673
|
-
raise RuntimeError(
|
|
674
|
-
f"SHA-256 checksum verification failed for {asset}\n"
|
|
675
|
-
f"Expected: {expected}\n"
|
|
676
|
-
f"Actual: {actual}\n"
|
|
677
|
-
f"The downloaded file may be corrupted or have been modified.\n"
|
|
678
|
-
f"Checksum URL: {checksum_url}")
|
|
679
|
-
logger.info("Checksum verified.")
|
|
680
|
-
|
|
681
|
-
extract_dir = os.path.join(tmpdir, "extracted")
|
|
682
|
-
try:
|
|
683
|
-
zip_size = os.path.getsize(zip_path)
|
|
684
|
-
except OSError:
|
|
685
|
-
zip_size = -1
|
|
686
|
-
try:
|
|
687
|
-
with zipfile.ZipFile(zip_path) as zf:
|
|
688
|
-
zf.extractall(extract_dir)
|
|
689
|
-
except zipfile.BadZipFile as e:
|
|
690
|
-
raise RuntimeError(
|
|
691
|
-
f"The downloaded archive '{asset}' is not a valid zip file "
|
|
692
|
-
f"(size: {zip_size} bytes, temporary file: {zip_path}): {e}"
|
|
693
|
-
) from e
|
|
694
|
-
except zipfile.LargeZipFile as e:
|
|
695
|
-
raise RuntimeError(
|
|
696
|
-
f"The downloaded archive '{asset}' requires 64-bit zip support "
|
|
697
|
-
f"(size: {zip_size} bytes, temporary file: {zip_path}): {e}"
|
|
698
|
-
) from e
|
|
699
|
-
except NotImplementedError as e:
|
|
700
|
-
# Unsupported compression method.
|
|
701
|
-
raise RuntimeError(
|
|
702
|
-
f"The downloaded archive '{asset}' uses an unsupported "
|
|
703
|
-
f"compression method (temporary file: {zip_path}): {e}"
|
|
704
|
-
) from e
|
|
705
|
-
except OSError as e:
|
|
706
|
-
raise RuntimeError(
|
|
707
|
-
f"Could not extract the downloaded archive '{asset}' "
|
|
708
|
-
f"(temporary file: {zip_path}, extract dir: {extract_dir}): {e}"
|
|
709
|
-
) from e
|
|
710
|
-
|
|
711
|
-
# Locate the bundled installer
|
|
712
|
-
for root, _dirs, files in os.walk(extract_dir):
|
|
713
|
-
if "install.sh" in files:
|
|
714
|
-
installer = os.path.join(root, "install.sh")
|
|
715
|
-
break
|
|
716
|
-
else:
|
|
717
|
-
raise RuntimeError(f"install.sh was not found inside {asset}")
|
|
718
|
-
|
|
719
|
-
try:
|
|
720
|
-
os.chmod(installer, os.stat(installer).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
721
|
-
except OSError as e:
|
|
722
|
-
raise RuntimeError(
|
|
723
|
-
f"Could not make the bundled installer executable: '{installer}' "
|
|
724
|
-
f"(from archive '{asset}'): {e}"
|
|
725
|
-
) from e
|
|
726
|
-
|
|
727
|
-
# Run the bundled installer (output streams live and is captured, so a
|
|
728
|
-
# failure carries the installer log; see _run_installer)
|
|
729
|
-
if sys.stdin is not None and not sys.stdin.closed and sys.stdin.isatty():
|
|
730
|
-
# running inside a terminal: run interactively
|
|
731
|
-
_run_installer([installer])
|
|
732
|
-
else:
|
|
733
|
-
# no terminal: install for the current user, answering yes to all
|
|
734
|
-
# questions so that the installer does not block on any prompt
|
|
735
|
-
_run_installer([installer, "--user", "-y"])
|
|
736
|
-
|
|
737
|
-
# Make the freshly installed csound available to the current process
|
|
738
|
-
home = Path.home()
|
|
739
|
-
userpath = home/".local/csound/libcsound64.so"
|
|
740
|
-
systempath = Path("/usr/local/lib/libcsound64.so")
|
|
741
|
-
if userpath.exists():
|
|
742
|
-
pluginspath = home/".local/lib/csound/7.0/plugins64"
|
|
743
|
-
if not pluginspath.is_dir():
|
|
744
|
-
raise RuntimeError(f"csound 7 installation failed: plugin directory "
|
|
745
|
-
f"'{pluginspath}' was not found")
|
|
746
|
-
os.environ["LIBCSOUNDPATH"] = str(userpath.resolve())
|
|
747
|
-
os.environ['OPCODE7DIR64'] = str(pluginspath.resolve())
|
|
748
|
-
elif systempath.exists():
|
|
749
|
-
pluginspath = Path("/usr/local/lib/csound/plugins64-7.0")
|
|
750
|
-
if not pluginspath.is_dir():
|
|
751
|
-
raise RuntimeError(f"csound 7 installation failed: plugin directory "
|
|
752
|
-
f"'{pluginspath}' was not found")
|
|
753
|
-
os.environ["LIBCSOUNDPATH"] = str(systempath.resolve())
|
|
754
|
-
os.environ['OPCODE7DIR64'] = str(pluginspath.resolve())
|
|
755
|
-
else:
|
|
756
|
-
raise RuntimeError("csound 7 installation failed: "
|
|
757
|
-
"libcsound64.so was not found in any of the standard locations")
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
def _install_csound_macos() -> None:
|
|
761
|
-
"""Install the latest csound 7 .pkg for macOS by running the bundled installer.
|
|
762
|
-
|
|
763
|
-
The official Csound 7 macOS package is produced by the "csound_builds"
|
|
764
|
-
workflow of the csound/csound repository on the "develop" branch and is
|
|
765
|
-
installed with the system ``installer`` under sudo. An interactive terminal
|
|
766
|
-
session is used when available (so sudo can prompt for the password).
|
|
767
|
-
When there is no terminal (e.g. on CI) the install still succeeds if sudo is
|
|
768
|
-
configured to run password-less.
|
|
769
|
-
|
|
770
|
-
This runs the bundled copy of the one-line installer used at
|
|
771
|
-
https://csound-plugins.github.io/getcsound.sh, which resolves the latest
|
|
772
|
-
successful workflow run, downloads its ``csound-7.*-macos*`` artifact
|
|
773
|
-
through the anonymous nightly.link mirror and installs the extracted .pkg.
|
|
774
|
-
|
|
775
|
-
After installation the environment variables ``LIBCSOUNDPATH``
|
|
776
|
-
and ``OPCODE7DIR64`` point to the installed library and plugin
|
|
777
|
-
directory, so that the current process can find csound immediately without
|
|
778
|
-
the need to open a new session.
|
|
779
|
-
|
|
780
|
-
Raises:
|
|
781
|
-
RuntimeError: if the bundled installer could not be found or failed, or
|
|
782
|
-
if no csound installation could be located after running it.
|
|
783
|
-
"""
|
|
784
|
-
import importlib.resources
|
|
785
|
-
|
|
786
|
-
installer = importlib.resources.files(__package__).joinpath("data", "getcsound.sh")
|
|
787
|
-
if not installer.is_file():
|
|
788
|
-
raise RuntimeError(f"The bundled installer was not found: {installer}")
|
|
789
|
-
|
|
790
|
-
# as_file() yields a real filesystem path, extracting to a temporary file
|
|
791
|
-
# first when the package is loaded from an archive (e.g. a zip).
|
|
792
|
-
macos_hint = ("The csound macOS .pkg is installed with sudo and needs an interactive "
|
|
793
|
-
"terminal (or passwordless sudo).\n"
|
|
794
|
-
"Alternatively, csound can be installed manually:\n"
|
|
795
|
-
" curl -fsSL https://csound-plugins.github.io/getcsound.sh | bash")
|
|
796
|
-
with importlib.resources.as_file(installer) as script:
|
|
797
|
-
_run_installer(["bash", str(script)], failure_hint=macos_hint)
|
|
798
|
-
|
|
799
|
-
# Make the freshly installed csound available to the current process
|
|
800
|
-
csound_dir = Path("/Applications/Csound")
|
|
801
|
-
libpath = csound_dir / "CsoundLib64.framework" / "CsoundLib64"
|
|
802
|
-
pluginspath = csound_dir / "CsoundLib64.framework" / "Resources" / "Opcodes64"
|
|
803
|
-
if libpath.exists():
|
|
804
|
-
os.environ["LIBCSOUNDPATH"] = str(libpath.resolve())
|
|
805
|
-
if pluginspath.exists() and pluginspath.is_dir():
|
|
806
|
-
os.environ['OPCODE7DIR64'] = str(pluginspath.resolve())
|
|
807
|
-
logger.info("Csound installed successfully to %s", csound_dir)
|
|
808
|
-
return
|
|
809
|
-
|
|
810
|
-
raise RuntimeError("csound 7 installation failed: "
|
|
811
|
-
"CsoundLib64 was not found in /Applications/Csound")
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
def _windows_is_admin() -> bool:
|
|
815
|
-
"""Return True if the current Windows session is elevated.
|
|
816
|
-
|
|
817
|
-
Returns False when the check cannot confirm elevation (including when the
|
|
818
|
-
check itself is unavailable), so callers fail with a helpful message
|
|
819
|
-
rather than assuming admin rights.
|
|
820
|
-
"""
|
|
821
|
-
try:
|
|
822
|
-
return bool(ct.windll.shell32.IsUserAnAdmin()) # type: ignore[attr-defined]
|
|
823
|
-
except Exception as e:
|
|
824
|
-
logger.debug("Could not determine Windows elevation status: %s", e)
|
|
825
|
-
return False
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
def _stdin_is_tty() -> bool:
|
|
829
|
-
"""Return True if stdin is an interactive terminal."""
|
|
830
|
-
try:
|
|
831
|
-
return bool(sys.stdin is not None and not sys.stdin.closed and sys.stdin.isatty())
|
|
832
|
-
except Exception:
|
|
833
|
-
return False
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
def _install_csound_windows() -> None:
|
|
837
|
-
"""Install the latest csound 7 for Windows by running the bundled installer.
|
|
838
|
-
|
|
839
|
-
This runs the bundled copy of the official installer at
|
|
840
|
-
https://csound-plugins.github.io/getcsound.ps1 with Windows PowerShell. The
|
|
841
|
-
installer resolves the latest successful ``csound_builds`` workflow run of
|
|
842
|
-
the ``csound/csound`` repository on the ``develop`` branch, downloads the
|
|
843
|
-
Windows x86_64 Inno Setup package and installs it silently to
|
|
844
|
-
``%ProgramFiles%\\Csound7``. Windows on ARM64 is not supported yet.
|
|
845
|
-
|
|
846
|
-
The package is installed machine-wide and needs admin rights: when the current
|
|
847
|
-
session is not elevated the installer triggers a UAC prompt, so an interactive
|
|
848
|
-
(or pre-elevated) session is required. On CI runners the session is usually
|
|
849
|
-
already elevated.
|
|
850
|
-
|
|
851
|
-
After a successful installation the env vars ``LIBCSOUNDPATH``
|
|
852
|
-
and ``OPCODE7DIR64`` are set to point to the installed library and plugin
|
|
853
|
-
folder, so that the current process can find csound immediately without
|
|
854
|
-
the need to open a new terminal.
|
|
855
|
-
|
|
856
|
-
Raises:
|
|
857
|
-
RuntimeError: if PowerShell or the bundled installer could not be found,
|
|
858
|
-
if the installer failed, or if no csound installation could be
|
|
859
|
-
located after running it.
|
|
860
|
-
"""
|
|
861
|
-
import importlib.resources
|
|
862
|
-
import platform
|
|
863
|
-
import shutil
|
|
864
|
-
|
|
865
|
-
machine = platform.machine().lower()
|
|
866
|
-
if machine in ("arm64", "aarch64"):
|
|
867
|
-
raise RuntimeError(
|
|
868
|
-
f"Windows on ARM64 (detected: '{platform.machine()}') is not supported "
|
|
869
|
-
"by the automatic csound installer, which provides an x86_64 package only.\n"
|
|
870
|
-
"Install csound manually (e.g. from https://github.com/csound/csound/releases) "
|
|
871
|
-
"and point LIBCSOUNDPATH at the installed csound64.dll."
|
|
872
|
-
)
|
|
873
|
-
|
|
874
|
-
if not _windows_is_admin():
|
|
875
|
-
if _stdin_is_tty():
|
|
876
|
-
logger.warning("The Csound Windows installer installs machine-wide and needs "
|
|
877
|
-
"admin rights; the installer will request elevation (UAC prompt).")
|
|
878
|
-
else:
|
|
879
|
-
raise RuntimeError(
|
|
880
|
-
"The Csound Windows installer installs machine-wide and needs admin "
|
|
881
|
-
"rights, but the current session is not elevated and there is no "
|
|
882
|
-
"interactive terminal to show the UAC prompt.\n"
|
|
883
|
-
"Run from an interactive (or already elevated) PowerShell session, or "
|
|
884
|
-
"install csound manually:\n"
|
|
885
|
-
" irm https://csound-plugins.github.io/getcsound.ps1 | iex"
|
|
886
|
-
)
|
|
887
|
-
|
|
888
|
-
installer = importlib.resources.files(__package__).joinpath("data", "getcsound.ps1")
|
|
889
|
-
if not installer.is_file():
|
|
890
|
-
raise RuntimeError(f"The bundled installer was not found: {installer}")
|
|
891
|
-
|
|
892
|
-
powershell = shutil.which("powershell") or shutil.which("pwsh")
|
|
893
|
-
if not powershell:
|
|
894
|
-
raise RuntimeError(
|
|
895
|
-
"PowerShell was not found. It is needed to install csound on Windows.\n"
|
|
896
|
-
"Alternatively, csound can be installed manually:\n"
|
|
897
|
-
" irm https://csound-plugins.github.io/getcsound.ps1 | iex"
|
|
898
|
-
)
|
|
899
|
-
|
|
900
|
-
# as_file() yields a real filesystem path, extracting to a temporary file
|
|
901
|
-
# first when the package is loaded from an archive (e.g. a zip).
|
|
902
|
-
windows_hint = ("The Csound Windows installer installs machine-wide and needs "
|
|
903
|
-
"admin rights: run it from an interactive (or elevated) "
|
|
904
|
-
"PowerShell session.\n"
|
|
905
|
-
"Alternatively, csound can be installed manually:\n"
|
|
906
|
-
" irm https://csound-plugins.github.io/getcsound.ps1 | iex")
|
|
907
|
-
with importlib.resources.as_file(installer) as script:
|
|
908
|
-
_run_installer(
|
|
909
|
-
[powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(script)],
|
|
910
|
-
failure_hint=windows_hint
|
|
911
|
-
)
|
|
912
|
-
|
|
913
|
-
# Make the freshly installed csound available to the current process
|
|
914
|
-
programfiles = (os.environ.get("ProgramW6432")
|
|
915
|
-
or os.environ.get("ProgramFiles")
|
|
916
|
-
or r"C:\Program Files")
|
|
917
|
-
csound_dir = Path(programfiles) / "Csound7"
|
|
918
|
-
bindir = csound_dir / "bin"
|
|
919
|
-
libpath = bindir / "csound64.dll"
|
|
920
|
-
pluginspath = csound_dir / "plugins64"
|
|
921
|
-
if libpath.is_file():
|
|
922
|
-
os.environ["LIBCSOUNDPATH"] = str(libpath.resolve())
|
|
923
|
-
# The machine-wide PATH set by the installer is not visible to this
|
|
924
|
-
# process yet, so add the bin directory here to let csound's dependent
|
|
925
|
-
# DLLs (e.g. libsndfile) be resolved when the library is loaded.
|
|
926
|
-
os.environ["PATH"] = str(bindir.resolve()) + os.pathsep + os.environ.get("PATH", "")
|
|
927
|
-
if pluginspath.is_dir():
|
|
928
|
-
os.environ['OPCODE7DIR64'] = str(pluginspath.resolve())
|
|
929
|
-
logger.info("Csound installed successfully to %s", csound_dir)
|
|
930
|
-
return
|
|
931
|
-
|
|
932
|
-
raise RuntimeError("csound 7 installation failed: csound64.dll was not found in "
|
|
933
|
-
f"'{bindir}'")
|