Skip to content

Commit

Permalink
Remove unused CI file and bootstrap file and add back recording scrip…
Browse files Browse the repository at this point in the history
…ts (#571)

* Remove unused CI file and bootstrap file

* Add devcontainer for running recordings

* Add powershell to devcontainer
  • Loading branch information
xinyi-joffre authored Feb 8, 2024
1 parent bd4fc51 commit cf424ed
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 123 deletions.
45 changes: 45 additions & 0 deletions .devcontainer/recordings/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Generate Recordings",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"features": {
"ghcr.io/devcontainers/features/conda:1": {},
"ghcr.io/devcontainers/features/powershell:1": {}
},
"customizations": {
"codespaces": {
"openFiles": []
},
"vscode": {
"extensions": [
"quantum.qsharp-lang-vscode",
"ms-python.python"
]
}
},
"secrets": {
"AZURE_CLIENT_ID": {
"description": "The client ID of your Azure Quantum service principal."
},
"AZURE_CLIENT_SECRET": {
"description": "The client secret of your Azure Quantum service principal."
},
"AZURE_TENANT_ID": {
"description": "The tenant ID of your Azure Quantum service principal."
},
"AZURE_QUANTUM_SUBSCRIPTION_ID": {
"description": "The subscription ID of your Azure Quantum workspace."
},
"AZURE_QUANTUM_WORKSPACE_RG": {
"description": "The resource group of your Azure Quantum workspace."
},
"AZURE_QUANTUM_WORKSPACE_NAME": {
"description": "The name of your Azure Quantum workspace."
},
"AZURE_QUANTUM_WORKSPACE_LOCATION": {
"description": "The location of your Azure Quantum workspace."
}
}
}
8 changes: 2 additions & 6 deletions azure-quantum/tests.live/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ if ($True -eq $SkipInstall) {

Enable-Conda

# Try installing IQ# dotnet tool, IQ# kernel and the qsharp Python package
# Used for running tests between the Azure Quantum Python SDK and IQ# (Q#+QIR job submission)
# Try activating the azurequantum conda environment
if ([string]::IsNullOrEmpty($PackageName) -or ($PackageName -eq "azure-quantum")) {
try {
$EnvExists = conda env list | Select-String -Pattern "azurequantum " | Measure-Object | Select-Object -Exp Count
if ($EnvExists) {
conda activate azurequantum
If ($null -eq $Env:TOOLS_DIR) { $Env:TOOLS_DIR = [IO.Path]::GetFullPath((Join-Path $RootDir ".tools")) }
If (-not (Test-Path -Path $Env:TOOLS_DIR)) { [IO.Directory]::CreateDirectory($Env:TOOLS_DIR) }
& (Join-Path $RootDir "build" "install-iqsharp.ps1");
}
}
catch {
Write-Host "##[warning]Failed to install IQ#."
Write-Host "##[warning]Failed to active conda environment."
}
}

Expand Down
62 changes: 0 additions & 62 deletions bootstrap.ps1

This file was deleted.

55 changes: 0 additions & 55 deletions build/ci.yml

This file was deleted.

142 changes: 142 additions & 0 deletions build/conda-utils.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

<#
.SYNOPSIS
Includes utility cmdlets for working with conda both locally,
and in Azure Pipelines and other hosted environments.
#>

function Test-CondaEnabled {
<#
.SYNOPSIS
Tests if conda has been enabled for shell
use (e.g.: if conda activate will work).
#>

# The shell hook for conda creates a new cmdlet called
# Invoke-Conda that is then aliased to `conda`. If the
# full name (without an alias) is available, then the hook
# has been run already.
if ($null -ne (Get-Command Invoke-Conda -ErrorAction SilentlyContinue)) {
return $true;
}
return $false;
}

function Enable-Conda {
<#
.SYNOPSIS
Attempts to enable conda for shell usage, first using
the CONDA environment variable for the path, falling back
to PATH, and then failing.
If conda is already enabled, this cmdlet does nothing,
so that this cmdlet is idempotent.
#>

if (Test-CondaEnabled) { return $true; }

if ("$Env:CONDA" -ne "") {
# Try and run the shell hook from the path nominated
# by CONDA.

# On Windows, this is $Env:CONDA/Scripts/conda.exe, while on
# Linux and macOS, this is $Env:CONDA/bin/conda.

if ($IsWindows) {
$condaBin = Join-Path $Env:CONDA "Scripts" "conda.exe";
} else {
$condaBin = Join-Path $Env:CONDA "bin" "conda";
}

if ($null -eq (Get-Command $condaBin -ErrorAction SilentlyContinue)) {
Write-Error "##[error] conda binary was expected at $condaBin (CONDA = $Env:CONDA), but was not found.";
throw;
}

(& $condaBin shell.powershell hook) | Out-String | Invoke-Expression;
} else {
(conda shell.powershell hook) | Out-String | Invoke-Expression;
}
}

function Use-CondaEnv {
param (
[string] $EnvName
)
<#
.SYNOPSIS
Activates a conda environment, reporting the new configuration
after having done so. If conda has not already been enabled, this
cmdlet will enable it before activating.
#>

Enable-Conda
# NB: We use the PowerShell cmdlet created by the conda shell hook here
# to avoid accidentally using the conda binary.
Enter-CondaEnvironment $EnvName
Write-Host "##[info]Activated Conda env: $(Get-PythonConfiguration | Out-String)"
}

function Install-Package() {
param(
[string] $EnvName,
[string] $PackageName,
[bool] $FromSource
)
# Activate env
Use-CondaEnv $EnvName
# Install package
if ($True -eq $FromSource) {
$ParentPath = Split-Path -parent $PSScriptRoot
$AbsPackageDir = Join-Path $ParentPath $PackageName
Write-Host "##[info]Install package $AbsPackageDir in development mode for env $EnvName"
pip install -e $AbsPackageDir
} else {
Write-Host "##[info]Install package $PackageName for env $EnvName"
pip install $PackageName
}
}

function Get-PythonConfiguration {
<#
.SYNOPSIS
Returns a table describing the current Python configuration,
useful for diagnostic purposes.
#>

$table = @{};

$python = (Get-Command python -ErrorAction SilentlyContinue);
if ($null -ne $python) {
$table["PythonLocation"] = $python.Source;
try {
$table["PythonVersion"] = & $python --version;
} catch { }
}

# If the CONDA environment variable is set, allow that to override
# the local PATH.
$conda = Get-Command conda -ErrorAction SilentlyContinue;

if ($null -ne $conda) {
$table["CondaLocation"] = $conda.Source;
try {
$table["CondaVersion"] = & $conda --version;
} catch { }
}

# If the conda hook has already been run, we can get some additional
# information for the table.
if (Test-CondaEnabled) {
try {
$env = Get-CondaEnvironment | Where-Object -Property Active;
if ($null -ne $env) {
$table["CondaEnvName"] = $env.Name;
$table["CondaEnvPath"] = $env.Path;
}
} catch { }
}

$table | Write-Output;
}
Loading

0 comments on commit cf424ed

Please sign in to comment.