Skip to content

Commit

Permalink
Change debugpy bundling code to include binaries for all supported pl…
Browse files Browse the repository at this point in the history
…atforms.
  • Loading branch information
Hugues Valois committed Aug 21, 2020
1 parent c66f2f3 commit c3e539f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Build/PreBuild.ps1
Expand Up @@ -56,7 +56,11 @@ try {
Write-Host "Creating symlink for $_.$($versions[$_])"
New-Item -ItemType Junction "$outdir\$_" -Value "$outdir\$_.$($versions[$_])"
} | Out-Null


$debugpyver = Get-Content "$buildroot\Build\debugpy-version.txt" -Raw
Write-Host "Downloading debugpy version $debugpyver"
$debugpyarglist = "install_debugpy.py", $debugpyver, $outdir
Start-Process -Wait -NoNewWindow "$outdir\python\tools\python.exe" -ErrorAction Stop -ArgumentList $debugpyarglist
} finally {
popd
}
1 change: 1 addition & 0 deletions Build/debugpy-version.txt
@@ -0,0 +1 @@
1.0.0rc2
64 changes: 64 additions & 0 deletions Build/install_debugpy.py
@@ -0,0 +1,64 @@
import argparse
import io
import json
import os
import urllib.request as url_lib
import zipfile

DEBUGGER_PACKAGE = "debugpy"
DEBUGGER_PYTHON_VERSIONS = ("cp35", "cp36", "cp37", "cp38")
DEBUGGER_EXCLUDED_PLATFORMS = ("manylinux", "macosx")


def _contains(s, parts=()):
return any(p for p in parts if p in s)


def _get_package_data():
json_uri = "https://pypi.org/pypi/{0}/json".format(DEBUGGER_PACKAGE)
# Response format: https://warehouse.readthedocs.io/api-reference/json/#project
# Release metadata format: https://github.com/pypa/interoperability-peps/blob/master/pep-0426-core-metadata.rst
with url_lib.urlopen(json_uri) as response:
return json.loads(response.read())


def _get_debugger_wheel_urls(data, version):
return list(
r["url"]
for r in data["releases"][version]
if _contains(r["url"], DEBUGGER_PYTHON_VERSIONS) and not _contains(r["url"], DEBUGGER_EXCLUDED_PLATFORMS)
)


def _download_and_extract(root, url, version):
root = os.getcwd() if root is None or root == "." else root
prefix = os.path.join("debugpy-{0}.data".format(version), "purelib")
with url_lib.urlopen(url) as response:
# Extract only the contents of the purelib subfolder (parent folder of debugpy),
# since debugpy files rely on the presence of a 'debugpy' folder.
with zipfile.ZipFile(io.BytesIO(response.read()), "r") as wheel:
for zip_info in wheel.infolist():
# Ignore dist info since we are merging multiple wheels
if ".dist-info" in zip_info.filename:
continue
# Normalize path for Windows, the wheel folder structure
# uses forward slashes.
normalized = os.path.normpath(zip_info.filename)
# Flatten the folder structure.
zip_info.filename = normalized.split(prefix)[-1]
wheel.extract(zip_info, root)


def main(root, ver):
data = _get_package_data()

for url in _get_debugger_wheel_urls(data, ver):
_download_and_extract(root, url, ver)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('version', help='Version of debugpy package.')
parser.add_argument('outputdir', help='Output directory under which debugpy directory will be created.')
args = parser.parse_args()
main(args.outputdir, args.version)
13 changes: 2 additions & 11 deletions Python/Product/Debugger/Debugger.csproj
Expand Up @@ -182,19 +182,9 @@
</ProjectReference>
</ItemGroup>
<Import Project="..\ProjectAfter.settings" />
<PropertyGroup>
<BundledDebugPyVersion>1.0.0rc1</BundledDebugPyVersion>
</PropertyGroup>
<Target Name="_GatherDebugPy" BeforeTargets="_IncludeDebugPy" Condition="!Exists('$(IntermediateOutputPath)debugpy\__init__.py')">
<PropertyGroup>
<PipCommand>"$(PackagesPath)python\tools\python.exe" -m pip install debugpy==$(BundledDebugPyVersion)</PipCommand>
<PipCommand>$(PipCommand) --no-compile --upgrade --target "$(IntermediateOutputPath)</PipCommand>
</PropertyGroup>
<Exec Command="$(PipCommand)" />
</Target>
<Target Name="_IncludeDebugPy" BeforeTargets="AssignTargetPaths;GetVSIXSourceItems">
<ItemGroup>
<DebugPyFiles Include="$(IntermediateOutputPath)debugpy\**\*" />
<DebugPyFiles Include="$(PackagesPath)debugpy\**\*" />
<DebugPyFiles>
<IncludeInVSIX>true</IncludeInVSIX>
<Link>debugpy\%(RecursiveDir)%(Filename)%(Extension)</Link>
Expand All @@ -212,6 +202,7 @@
<_DebugPyVersionNewItem Include="$(IntermediateOutputPath)\DebugPyVersion.g.cs" />
</ItemGroup>
<PropertyGroup>
<BundledDebugPyVersion>$([System.IO.File]::ReadAllText('$(BuildRoot)\Build\debugpy-version.txt'))</BundledDebugPyVersion>
<OriginalDebugPyVersionText>$([System.IO.File]::ReadAllText('$(BuildRoot)\Python\Product\Debugger\DebugPyVersion.cs'))</OriginalDebugPyVersionText>
<DebugPyVersionText>$(OriginalDebugPyVersionText.Replace(` Version = "1.0.0"`, ` Version = "$(BundledDebugPyVersion)"`))</DebugPyVersionText>
</PropertyGroup>
Expand Down

0 comments on commit c3e539f

Please sign in to comment.