Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Adopt pymsbuild-msix for building by zooba · Pull Request #110 · python/pymanager · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ jobs:
sys.exit(0 if sys.version_info[:5] == (3, 14, 0, 'beta', 1) else 1)"

- name: Install build dependencies
run: python -m pip install "pymsbuild>=1.2.0b1"
run: python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"

- name: 'Install test runner'
run: python -m pip install pytest pytest-cov
Expand Down
20 changes: 12 additions & 8 deletions _make_helper.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ def get_dirs():
if not _layout:
_layout = _temp / "layout"
os.environ["PYMSBUILD_LAYOUT_DIR"] = str(_layout)
out = _layout / "python-manager"

return dict(
root=root,
out=out,
out=_layout,
src=src,
dist=dist,
build=build,
temp=temp,
)


def get_msix_version(dirs):
def get_msix_version(manifest):
from io import StringIO
from xml.etree import ElementTree as ET
appx = (dirs["out"] / "appxmanifest.xml").read_text("utf-8")
appx = Path(manifest).read_text("utf-8")
NS = dict(e for _, e in ET.iterparse(StringIO(appx), events=("start-ns",)))
for k, v in NS.items():
ET.register_namespace(k, v)
Expand All@@ -110,10 +109,15 @@ def get_msix_version(dirs):
return identity.attrib['Version']


def get_output_name(dirs):
with open(dirs["out"] / "version.txt", "r", encoding="utf-8") as f:
version = f.read().strip()
return f"python-manager-{version}"
def get_output_name(layout):
with open(layout / "__state.txt", "r") as f:
for line in f:
if line == "# BEGIN FILES":
break
key, sep, value = line.partition("=")
if sep and key == "msix_name":
return value.rpartition(".")[0]
return "python-manager"


copyfile = shutil.copyfile
Expand Down
8 changes: 5 additions & 3 deletions _msbuild.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
from pymsbuild import *
from pymsbuild.dllpack import *
from pymsbuild_msix import AppxManifest, AppInstaller, ResourcesXml


DLL_NAME = "python314"
Expand All@@ -15,7 +16,7 @@ def can_embed(tag):

METADATA = {
"Metadata-Version": "2.2",
"Name": "manage",
"Name": "python-manager",
"Version": "0.1a0",
"Author": "Python Software Foundation",
"Author-email": "steve.dower@python.org",
Expand DownExpand Up@@ -179,8 +180,8 @@ def pyshellext(ext='.exe', **props):
PACKAGE = Package('python-manager',
PyprojectTomlFile('pyproject.toml'),
# MSIX manifest
File('src/pymanager/appxmanifest.xml'),
File('src/pymanager/pymanager.appinstaller'),
AppxManifest('src/pymanager/appxmanifest.xml'),
AppInstaller('src/pymanager/pymanager.appinstaller'),
Package(
'MSIX.AppInstaller.Data',
File('src/pymanager/MSIXAppInstallerData.xml'),
Expand DownExpand Up@@ -208,6 +209,7 @@ def pyshellext(ext='.exe', **props):
),

# Directory for MSIX resources
ResourcesXml('src/pymanager/resources.xml'),
Package(
'_resources',
File('src/pymanager/_resources/*.png'),
Expand Down
2 changes: 1 addition & 1 deletion ci/release.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,7 @@ stages:
workingDirectory: $(Build.BinariesDirectory)

- powershell: |
python -m pip install "pymsbuild>=1.2.0b1"
python -m pip install "pymsbuild>=1.2.2b1" "pymsbuild-msix>=0.1.0a1"
displayName: 'Install build dependencies'

- ${{ if eq(parameters.PreTest, 'true') }}:
Expand Down
6 changes: 3 additions & 3 deletions make-msi.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,13 +12,13 @@
DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
LAYOUT = DIRS["out"]
LAYOUT = DIRS["out"] / "python-manager"
SRC = DIRS["src"]
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
NAME = get_output_name(DIRS["out"])
VERSION = get_msix_version(LAYOUT / "appxmanifest.xml")

# Package into MSI
pydllname = [p.stem for p in (LAYOUT / "runtime").glob("python*.dll")][0]
Expand Down
69 changes: 16 additions & 53 deletions make-msix.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,23 +9,11 @@
copyfile,
copytree,
get_dirs,
get_msix_version,
get_output_name,
get_sdk_bins,
rmtree,
unlink,
)

SDK_BINS = get_sdk_bins()

MAKEAPPX = SDK_BINS / "makeappx.exe"
MAKEPRI = SDK_BINS / "makepri.exe"

for tool in [MAKEAPPX, MAKEPRI]:
if not tool.is_file():
print("Unable to locate Windows Kit tool", tool.name, file=sys.stderr)
sys.exit(3)

DIRS = get_dirs()
BUILD = DIRS["build"]
TEMP = DIRS["temp"]
Expand All@@ -35,51 +23,25 @@
DIST = DIRS["dist"]

# Calculate output names (must be after building)
NAME = get_output_name(DIRS)
VERSION = get_msix_version(DIRS)
DIST_MSIX = DIST / f"{NAME}.msix"
DIST_STORE_MSIX = DIST / f"{NAME}-store.msix"
DIST_APPXSYM = DIST / f"{NAME}-store.appxsym"
DIST_MSIXUPLOAD = DIST / f"{NAME}-store.msixupload"
DIST_MSIX = DIST / get_output_name(LAYOUT)
DIST_STORE_MSIX = DIST_MSIX.with_name(f"{DIST_MSIX.stem}-store.msix")
DIST_APPXSYM = DIST_STORE_MSIX.with_suffix(".appxsym")
DIST_MSIXUPLOAD = DIST_STORE_MSIX.with_suffix(".msixupload")

unlink(DIST_MSIX, DIST_STORE_MSIX, DIST_APPXSYM, DIST_MSIXUPLOAD)

# Generate resources info in LAYOUT
if not (LAYOUT / "_resources.pri").is_file():
run([MAKEPRI, "new", "/o",
"/pr", LAYOUT,
"/cf", SRC / "pymanager/resources.xml",
"/of", LAYOUT / "_resources.pri",
"/mf", "appx"])

# Clean up non-shipping files from LAYOUT
preserved = [
*LAYOUT.glob("pyshellext*.dll"),
]

for f in preserved:
print("Preserving", f, "as", TEMP / f.name)
copyfile(f, TEMP / f.name)

unlink(
*LAYOUT.rglob("*.pdb"),
*LAYOUT.rglob("*.pyc"),
*LAYOUT.rglob("__pycache__"),
*preserved,
)

# Package into DIST
run([MAKEAPPX, "pack", "/o", "/d", LAYOUT, "/p", DIST_MSIX])
run([sys.executable, "-m", "pymsbuild", "pack", "-v"])

print("Copying appinstaller file to", DIST)
copyfile(LAYOUT / "pymanager.appinstaller", DIST / "pymanager.appinstaller")
copyfile(LAYOUT / "python-manager/pymanager.appinstaller", DIST / "pymanager.appinstaller")


if os.getenv("PYMANAGER_APPX_STORE_PUBLISHER"):
# Clone and update layout for Store build
rmtree(LAYOUT2)
copytree(LAYOUT, LAYOUT2)
unlink(*LAYOUT2.glob("*.appinstaller"))
unlink(*LAYOUT2.glob("python-manager/*.appinstaller"))

def patch_appx(source):
from xml.etree import ElementTree as ET
Expand DownExpand Up@@ -116,9 +78,16 @@ def patch_appx(source):
with open(source, "wb") as f:
xml.write(f, "utf-8")

patch_appx(LAYOUT2 / "appxmanifest.xml")
patch_appx(LAYOUT2 / "python-manager/appxmanifest.xml")

run([MAKEAPPX, "pack", "/o", "/d", LAYOUT2, "/p", DIST_STORE_MSIX])
run(
[sys.executable, "-m", "pymsbuild", "pack", "-v"],
env={
**os.environ,
"PYMSBUILD_LAYOUT_DIR": str(LAYOUT2),
"PYMSBUILD_MSIX_NAME": DIST_STORE_MSIX.name,
}
)

# Pack symbols
print("Packing symbols to", DIST_APPXSYM)
Expand All@@ -131,9 +100,3 @@ def patch_appx(source):
with zipfile.ZipFile(DIST_MSIXUPLOAD, "w") as zf:
zf.write(DIST_STORE_MSIX, arcname=DIST_STORE_MSIX.name)
zf.write(DIST_APPXSYM, arcname=DIST_APPXSYM.name)


for f in preserved:
print("Restoring", f, "from", TEMP / f.name)
copyfile(TEMP / f.name, f)
unlink(TEMP / f.name)
27 changes: 21 additions & 6 deletions make.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from pathlib import PurePath
from subprocess import check_call as run
from _make_helper import get_dirs, rmtree, unlink

Expand DownExpand Up@@ -38,13 +39,27 @@
pass

# Run main build - this fills in BUILD and LAYOUT
run([sys.executable, "-m", "pymsbuild", "wheel"],
run([sys.executable, "-m", "pymsbuild", "msix"],
cwd=DIRS["root"],
env={**os.environ, "BUILD_SOURCEBRANCH": ref})

# Bundle current latest release
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", TEMP / "bundle", "default"])
(LAYOUT / "bundled").mkdir(parents=True, exist_ok=True)
(TEMP / "bundle" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")
for f in (TEMP / "bundle").iterdir():
f.rename(LAYOUT / "bundled" / f.name)
run([LAYOUT / "py-manager.exe", "install", "-v", "-f", "--download", LAYOUT / "bundled", "default"])
(LAYOUT / "bundled" / "index.json").rename(LAYOUT / "bundled" / "fallback-index.json")

# Update package state for when we pack
new_lines = []
state_txt = LAYOUT.parent / "__state.txt"
for line in state_txt.read_text("utf-8").splitlines():
if not line or "=" in line or line.startswith("#"):
new_lines.append(line)
continue
# Exclude the in-proc shell extension from the MSIX
if PurePath(line).match("pyshellext*.dll"):
continue
new_lines.append(line)
# Include the bundled files in the MSIX
for f in LAYOUT.rglob(r"bundled\*"):
new_lines.append(str(f.relative_to(state_txt.parent)))

state_txt.write_text("\n".join(new_lines), encoding="utf-8")