Pier Angelo Vendrame pushed to branch mullvad-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser
Commits:
bd3fbfef by Pier Angelo Vendrame at 2024-12-16T18:25:32+01:00
fixup! Firefox preference overrides.
BB 43366: Do not use system accent color in inputs.
We did not manage to write a reliable proof of concept for
fingerprinting this, but I managed to get the color once (with Firefox
on Android, which is the worse case, as the system offers to use colors
from the wallpaper).
- - - - -
1 changed file:
- browser/app/profile/001-base-profile.js
Changes:
=====================================
browser/app/profile/001-base-profile.js
=====================================
@@ -463,6 +463,9 @@ pref("pdfjs.disabled", false, locked);
#endif
// Bug 40057: Ensure system colors are not used for CSS4 colors
pref("browser.display.use_system_colors", false);
+// tor-browser#43366: do not use system accent color in inputs.
+// See also https://bugzilla.mozilla.org/show_bug.cgi?id=1861362.
+pref("widget.non-native-theme.use-theme-accent", false);
// tor-browser#41943: defense-in-depth, but do not lock anymore (enabled in Firefox 119, http://bugzil.la/1851162)
pref("javascript.options.spectre.disable_for_isolated_content", false);
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/bd3…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/bd3…
You're receiving this email because of your account on gitlab.torproject.org.
Pier Angelo Vendrame pushed to branch base-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits:
fa621bc7 by Pier Angelo Vendrame at 2024-12-16T18:23:54+01:00
fixup! Firefox preference overrides.
BB 43366: Do not use system accent color in inputs.
We did not manage to write a reliable proof of concept for
fingerprinting this, but I managed to get the color once (with Firefox
on Android, which is the worse case, as the system offers to use colors
from the wallpaper).
- - - - -
1 changed file:
- browser/app/profile/001-base-profile.js
Changes:
=====================================
browser/app/profile/001-base-profile.js
=====================================
@@ -463,6 +463,9 @@ pref("pdfjs.disabled", false, locked);
#endif
// Bug 40057: Ensure system colors are not used for CSS4 colors
pref("browser.display.use_system_colors", false);
+// tor-browser#43366: do not use system accent color in inputs.
+// See also https://bugzilla.mozilla.org/show_bug.cgi?id=1861362.
+pref("widget.non-native-theme.use-theme-accent", false);
// tor-browser#41943: defense-in-depth, but do not lock anymore (enabled in Firefox 119, http://bugzil.la/1851162)
pref("javascript.options.spectre.disable_for_isolated_content", false);
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/fa621bc…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/fa621bc…
You're receiving this email because of your account on gitlab.torproject.org.
Pier Angelo Vendrame pushed to branch tor-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits:
7f8c1d43 by Pier Angelo Vendrame at 2024-12-16T18:18:53+01:00
fixup! Firefox preference overrides.
BB 43366: Do not use system accent color in inputs.
We did not manage to write a reliable proof of concept for
fingerprinting this, but I managed to get the color once (with Firefox
on Android, which is the worse case, as the system offers to use colors
from the wallpaper).
- - - - -
1 changed file:
- browser/app/profile/001-base-profile.js
Changes:
=====================================
browser/app/profile/001-base-profile.js
=====================================
@@ -463,6 +463,9 @@ pref("pdfjs.disabled", false, locked);
#endif
// Bug 40057: Ensure system colors are not used for CSS4 colors
pref("browser.display.use_system_colors", false);
+// tor-browser#43366: do not use system accent color in inputs.
+// See also https://bugzilla.mozilla.org/show_bug.cgi?id=1861362.
+pref("widget.non-native-theme.use-theme-accent", false);
// tor-browser#41943: defense-in-depth, but do not lock anymore (enabled in Firefox 119, http://bugzil.la/1851162)
pref("javascript.options.spectre.disable_for_isolated_content", false);
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/7f8c1d4…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/7f8c1d4…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch tor-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits:
00d7026f by Henry Wilkes at 2024-12-16T11:27:38+00:00
fixup! Bug 40701: Add security warning when downloading a file
Bug 43312: Ensure download panel warning uses the same width as the
mozilla downloads list.
We stop setting a `width` on the download panel because this can
conflict with the default width set for the mozilla downloads list, set
by localisers. Instead, we use the same width for our Tor Browser
warning message using a wrapper element.
We also ensure that the wrapper element has `min-width: 100%` for
scenarios where the localiser width is less than the min-width of the
ancestor panel.
- - - - -
2 changed files:
- browser/components/downloads/content/downloads.css
- browser/components/downloads/content/downloadsPanel.inc.xhtml
Changes:
=====================================
browser/components/downloads/content/downloads.css
=====================================
@@ -92,15 +92,19 @@
#downloadsPanel-mainView {
min-width: 37em;
padding: 0.62em;
- /* If we don't set a width, #downloadsPanelTorWarning will request
- * its max-content width. */
- width: 37em;
}
#downloadsPanelTorWarning {
margin-block-end: var(--arrowpanel-menuitem-padding-block);
}
+#downloadsPanelTorWarningWrapper {
+ /* The wrapper element has its `width` attribute set by mozilla localisers.
+ * We want to ensure the element occupies the available width when the
+ * localiser width is smaller. See tor-browser#43312. */
+ min-width: 100%;
+}
+
#downloadsHistory,
#downloadsFooterButtons {
margin: 0;
=====================================
browser/components/downloads/content/downloadsPanel.inc.xhtml
=====================================
@@ -104,8 +104,25 @@
disablekeynav="true">
<panelview id="downloadsPanel-mainView">
- <html:moz-message-bar id="downloadsPanelTorWarning">
- </html:moz-message-bar>
+ <!-- We add a wrapper around the #downloadsPanelTorWarning and give it the
+ - same Fluent ID as #downloadsListBox. This Fluent message allows
+ - Firefox localisers to set the width of the #downloadsListBox using
+ - the style attribute. We want the same width set for our downloads
+ - warning. Otherwise the warning will occupy its max-content width.
+ - NOTE: We require a wrapper element since #downloadsPanelTorWarning
+ - needs its own Fluent attributes.
+ - NOTE: This only works if #downloadsPanelTorWarningWrapper and
+ - #downloadsListBox share the same padding relative to their common
+ - ancestor.
+ - See tor-browser#43312. -->
+ <html:div
+ id="downloadsPanelTorWarningWrapper"
+ data-l10n-id="downloads-panel-items"
+ data-l10n-attrs="style"
+ >
+ <html:moz-message-bar id="downloadsPanelTorWarning">
+ </html:moz-message-bar>
+ </html:div>
<vbox class="panel-view-body-unscrollable">
<richlistbox id="downloadsListBox"
data-l10n-id="downloads-panel-items"
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/00d7026…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/00d7026…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch maint-14.0 at The Tor Project / Applications / tor-browser-build
Commits:
36c06687 by Nicolas Vigier at 2024-12-16T12:54:30+00:00
Bug 41311: Remove apparmor profile if abi 4.0 is not present
When abi 4.0 file not available, loading the apparmor profile is failing.
But the profile is only useful on Ubuntu 24.04 (and later), where the
abi 4.0 file is present.
We're doing something similar to:
https://github.com/CollaboraOnline/online/commit/5f7b37c7412c3e1d81d9c50a0f…
- - - - -
2 changed files:
- projects/linux-packages/config
- + projects/linux-packages/debian/postinst.in
Changes:
=====================================
projects/linux-packages/config
=====================================
@@ -171,6 +171,10 @@ input_files:
content: "[% INCLUDE 'debian/docs.in' %]"
refresh_input: 1
enable: '[% c("var/build_deb_pkg") %]'
+ - filename: debian/postinst
+ content: "[% INCLUDE 'debian/postinst.in' %]"
+ refresh_input: 1
+ enable: '[% c("var/build_deb_pkg") %]'
- filename: debian/rules
content: "[% INCLUDE 'debian/rules.in' %]"
refresh_input: 1
=====================================
projects/linux-packages/debian/postinst.in
=====================================
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+ install|upgrade|configure)
+ # If abi 4.0 is not present, then remove the apparmor profile config
+ if [ ! -e /etc/apparmor.d/abi/4.0 ]; then
+ rm -f /etc/apparmor.d/[% c("var/system_pkg/pkg_name") %]
+ fi
+ ;;
+esac
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/3…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/3…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch main at The Tor Project / Applications / tor-browser-build
Commits:
ee82c7f8 by Nicolas Vigier at 2024-12-12T12:13:31+01:00
Bug 41311: Remove apparmor profile if abi 4.0 is not present
When abi 4.0 file not available, loading the apparmor profile is failing.
But the profile is only useful on Ubuntu 24.04 (and later), where the
abi 4.0 file is present.
We're doing something similar to:
https://github.com/CollaboraOnline/online/commit/5f7b37c7412c3e1d81d9c50a0f…
- - - - -
2 changed files:
- projects/linux-packages/config
- + projects/linux-packages/debian/postinst.in
Changes:
=====================================
projects/linux-packages/config
=====================================
@@ -201,6 +201,10 @@ input_files:
content: "[% INCLUDE 'debian/docs.in' %]"
refresh_input: 1
enable: '[% c("var/build_deb_pkg") %]'
+ - filename: debian/postinst
+ content: "[% INCLUDE 'debian/postinst.in' %]"
+ refresh_input: 1
+ enable: '[% c("var/build_deb_pkg") %]'
- filename: debian/rules
content: "[% INCLUDE 'debian/rules.in' %]"
refresh_input: 1
=====================================
projects/linux-packages/debian/postinst.in
=====================================
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+case "$1" in
+ install|upgrade|configure)
+ # If abi 4.0 is not present, then remove the apparmor profile config
+ if [ ! -e /etc/apparmor.d/abi/4.0 ]; then
+ rm -f /etc/apparmor.d/[% c("var/system_pkg/pkg_name") %]
+ fi
+ ;;
+esac
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/e…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/e…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch mullvad-browser-128.5.0esr-14.0-1 at The Tor Project / Applications / Mullvad Browser
Commits:
94b5b3e9 by Filipe Laíns at 2024-12-10T18:14:53+00:00
Bug 1935621 - Fix virtual environment sysconfig path calculation r=firefox-build-system-reviewers,ahochheiden
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Differential Revision: https://phabricator.services.mozilla.com/D231480
- - - - -
1 changed file:
- python/mach/mach/site.py
Changes:
=====================================
python/mach/mach/site.py
=====================================
@@ -17,6 +17,7 @@ import subprocess
import sys
import sysconfig
import tempfile
+import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Optional
@@ -817,33 +818,75 @@ class PythonVirtualenv:
"""Calculates paths of interest for general python virtual environments"""
def __init__(self, prefix):
- if _is_windows:
- self.bin_path = os.path.join(prefix, "Scripts")
- self.python_path = os.path.join(self.bin_path, "python.exe")
- else:
- self.bin_path = os.path.join(prefix, "bin")
- self.python_path = os.path.join(self.bin_path, "python")
self.prefix = os.path.realpath(prefix)
+ self.paths = self._get_sysconfig_paths(self.prefix)
- @functools.lru_cache(maxsize=None)
- def resolve_sysconfig_packages_path(self, sysconfig_path):
- # macOS uses a different default sysconfig scheme based on whether it's using the
- # system Python or running in a virtualenv.
- # Manually define the scheme (following the implementation in
- # "sysconfig._get_default_scheme()") so that we're always following the
- # code path for a virtualenv directory structure.
- if os.name == "posix":
- scheme = "posix_prefix"
- else:
- scheme = os.name
+ # Name of the Python executable to use in virtual environments.
+ # An executable with the same name as sys.executable might not exist in
+ # virtual environments. An executable with 'python' as the steam —
+ # without version numbers or ABI flags — will always be present in
+ # virtual environments, so we use that.
+ python_exe_name = "python" + sysconfig.get_config_var("EXE")
+
+ self.bin_path = self.paths["scripts"]
+ self.python_path = os.path.join(self.bin_path, python_exe_name)
- sysconfig_paths = sysconfig.get_paths(scheme)
- data_path = Path(sysconfig_paths["data"])
- path = Path(sysconfig_paths[sysconfig_path])
- relative_path = path.relative_to(data_path)
+ @staticmethod
+ def _get_sysconfig_paths(prefix):
+ """Calculate the sysconfig paths of a virtual environment in the given prefix.
- # Path to virtualenv's "site-packages" directory for provided sysconfig path
- return os.path.normpath(os.path.normcase(Path(self.prefix) / relative_path))
+ The virtual environment MUST be using the same Python distribution as us.
+ """
+ # Determine the sysconfig scheme used in virtual environments
+ if "venv" in sysconfig.get_scheme_names():
+ # A 'venv' scheme was added in Python 3.11 to allow users to
+ # calculate the paths for a virtual environment, since the default
+ # scheme may not always be the same as used on virtual environments.
+ # Some common examples are the system Python distributed by macOS,
+ # Debian, and Fedora.
+ # For more information, see https://github.com/python/cpython/issues/89576
+ venv_scheme = "venv"
+ elif os.name == "nt":
+ # We know that before the 'venv' scheme was added, on Windows,
+ # the 'nt' scheme was used in virtual environments.
+ venv_scheme = "nt"
+ elif os.name == "posix":
+ # We know that before the 'venv' scheme was added, on POSIX,
+ # the 'posix_prefix' scheme was used in virtual environments.
+ venv_scheme = "posix_prefix"
+ else:
+ # This should never happen with upstream Python, as the 'venv'
+ # scheme should always be available on >=3.11, and no other
+ # platforms are supported by the upstream on older Python versions.
+ #
+ # Since the 'venv' scheme isn't available, and we have no knowledge
+ # of this platform/distribution, fallback to the default scheme.
+ #
+ # Hitting this will likely be the result of running a custom Python
+ # distribution targetting a platform that is not supported by the
+ # upstream.
+ # In this case, unless the Python vendor patched the Python
+ # distribution in such a way as the default scheme may not always be
+ # the same scheme, using the default scheme should be correct.
+ # If the vendor did patch Python as such, to work around this issue,
+ # I would recommend them to define a 'venv' scheme that matches
+ # the layout used on virtual environments in their Python distribution.
+ # (rec. signed Filipe Laíns — upstream sysconfig maintainer)
+ venv_scheme = sysconfig.get_default_scheme()
+ warnings.warn(
+ f"Unknown platform '{os.name}', using the default install scheme '{venv_scheme}'. "
+ "If this is incorrect, please ask your Python vendor to add a 'venv' sysconfig scheme "
+ "(see https://github.com/python/cpython/issues/89576, or check the code comment).",
+ stacklevel=2,
+ )
+ # Build the sysconfig config_vars dictionary for the virtual environment.
+ venv_vars = sysconfig.get_config_vars().copy()
+ venv_vars["base"] = venv_vars["platbase"] = prefix
+ # Get sysconfig paths for the virtual environment.
+ return sysconfig.get_paths(venv_scheme, vars=venv_vars)
+
+ def resolve_sysconfig_packages_path(self, sysconfig_path):
+ return self.paths[sysconfig_path]
def site_packages_dirs(self):
dirs = []
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/94b…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/94b…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch base-browser-128.5.0esr-14.0-1 at The Tor Project / Applications / Tor Browser
Commits:
83e5b5e2 by Filipe Laíns at 2024-12-10T18:12:04+00:00
Bug 1935621 - Fix virtual environment sysconfig path calculation r=firefox-build-system-reviewers,ahochheiden
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Differential Revision: https://phabricator.services.mozilla.com/D231480
- - - - -
1 changed file:
- python/mach/mach/site.py
Changes:
=====================================
python/mach/mach/site.py
=====================================
@@ -17,6 +17,7 @@ import subprocess
import sys
import sysconfig
import tempfile
+import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Optional
@@ -817,33 +818,75 @@ class PythonVirtualenv:
"""Calculates paths of interest for general python virtual environments"""
def __init__(self, prefix):
- if _is_windows:
- self.bin_path = os.path.join(prefix, "Scripts")
- self.python_path = os.path.join(self.bin_path, "python.exe")
- else:
- self.bin_path = os.path.join(prefix, "bin")
- self.python_path = os.path.join(self.bin_path, "python")
self.prefix = os.path.realpath(prefix)
+ self.paths = self._get_sysconfig_paths(self.prefix)
- @functools.lru_cache(maxsize=None)
- def resolve_sysconfig_packages_path(self, sysconfig_path):
- # macOS uses a different default sysconfig scheme based on whether it's using the
- # system Python or running in a virtualenv.
- # Manually define the scheme (following the implementation in
- # "sysconfig._get_default_scheme()") so that we're always following the
- # code path for a virtualenv directory structure.
- if os.name == "posix":
- scheme = "posix_prefix"
- else:
- scheme = os.name
+ # Name of the Python executable to use in virtual environments.
+ # An executable with the same name as sys.executable might not exist in
+ # virtual environments. An executable with 'python' as the steam —
+ # without version numbers or ABI flags — will always be present in
+ # virtual environments, so we use that.
+ python_exe_name = "python" + sysconfig.get_config_var("EXE")
+
+ self.bin_path = self.paths["scripts"]
+ self.python_path = os.path.join(self.bin_path, python_exe_name)
- sysconfig_paths = sysconfig.get_paths(scheme)
- data_path = Path(sysconfig_paths["data"])
- path = Path(sysconfig_paths[sysconfig_path])
- relative_path = path.relative_to(data_path)
+ @staticmethod
+ def _get_sysconfig_paths(prefix):
+ """Calculate the sysconfig paths of a virtual environment in the given prefix.
- # Path to virtualenv's "site-packages" directory for provided sysconfig path
- return os.path.normpath(os.path.normcase(Path(self.prefix) / relative_path))
+ The virtual environment MUST be using the same Python distribution as us.
+ """
+ # Determine the sysconfig scheme used in virtual environments
+ if "venv" in sysconfig.get_scheme_names():
+ # A 'venv' scheme was added in Python 3.11 to allow users to
+ # calculate the paths for a virtual environment, since the default
+ # scheme may not always be the same as used on virtual environments.
+ # Some common examples are the system Python distributed by macOS,
+ # Debian, and Fedora.
+ # For more information, see https://github.com/python/cpython/issues/89576
+ venv_scheme = "venv"
+ elif os.name == "nt":
+ # We know that before the 'venv' scheme was added, on Windows,
+ # the 'nt' scheme was used in virtual environments.
+ venv_scheme = "nt"
+ elif os.name == "posix":
+ # We know that before the 'venv' scheme was added, on POSIX,
+ # the 'posix_prefix' scheme was used in virtual environments.
+ venv_scheme = "posix_prefix"
+ else:
+ # This should never happen with upstream Python, as the 'venv'
+ # scheme should always be available on >=3.11, and no other
+ # platforms are supported by the upstream on older Python versions.
+ #
+ # Since the 'venv' scheme isn't available, and we have no knowledge
+ # of this platform/distribution, fallback to the default scheme.
+ #
+ # Hitting this will likely be the result of running a custom Python
+ # distribution targetting a platform that is not supported by the
+ # upstream.
+ # In this case, unless the Python vendor patched the Python
+ # distribution in such a way as the default scheme may not always be
+ # the same scheme, using the default scheme should be correct.
+ # If the vendor did patch Python as such, to work around this issue,
+ # I would recommend them to define a 'venv' scheme that matches
+ # the layout used on virtual environments in their Python distribution.
+ # (rec. signed Filipe Laíns — upstream sysconfig maintainer)
+ venv_scheme = sysconfig.get_default_scheme()
+ warnings.warn(
+ f"Unknown platform '{os.name}', using the default install scheme '{venv_scheme}'. "
+ "If this is incorrect, please ask your Python vendor to add a 'venv' sysconfig scheme "
+ "(see https://github.com/python/cpython/issues/89576, or check the code comment).",
+ stacklevel=2,
+ )
+ # Build the sysconfig config_vars dictionary for the virtual environment.
+ venv_vars = sysconfig.get_config_vars().copy()
+ venv_vars["base"] = venv_vars["platbase"] = prefix
+ # Get sysconfig paths for the virtual environment.
+ return sysconfig.get_paths(venv_scheme, vars=venv_vars)
+
+ def resolve_sysconfig_packages_path(self, sysconfig_path):
+ return self.paths[sysconfig_path]
def site_packages_dirs(self):
dirs = []
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/83e5b5e…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/83e5b5e…
You're receiving this email because of your account on gitlab.torproject.org.
morgan pushed to branch tor-browser-128.5.0esr-14.0-1 at The Tor Project / Applications / Tor Browser
Commits:
11bd3e17 by Filipe Laíns at 2024-12-10T18:10:46+00:00
Bug 1935621 - Fix virtual environment sysconfig path calculation r=firefox-build-system-reviewers,ahochheiden
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Differential Revision: https://phabricator.services.mozilla.com/D231480
- - - - -
1 changed file:
- python/mach/mach/site.py
Changes:
=====================================
python/mach/mach/site.py
=====================================
@@ -17,6 +17,7 @@ import subprocess
import sys
import sysconfig
import tempfile
+import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Optional
@@ -817,33 +818,75 @@ class PythonVirtualenv:
"""Calculates paths of interest for general python virtual environments"""
def __init__(self, prefix):
- if _is_windows:
- self.bin_path = os.path.join(prefix, "Scripts")
- self.python_path = os.path.join(self.bin_path, "python.exe")
- else:
- self.bin_path = os.path.join(prefix, "bin")
- self.python_path = os.path.join(self.bin_path, "python")
self.prefix = os.path.realpath(prefix)
+ self.paths = self._get_sysconfig_paths(self.prefix)
- @functools.lru_cache(maxsize=None)
- def resolve_sysconfig_packages_path(self, sysconfig_path):
- # macOS uses a different default sysconfig scheme based on whether it's using the
- # system Python or running in a virtualenv.
- # Manually define the scheme (following the implementation in
- # "sysconfig._get_default_scheme()") so that we're always following the
- # code path for a virtualenv directory structure.
- if os.name == "posix":
- scheme = "posix_prefix"
- else:
- scheme = os.name
+ # Name of the Python executable to use in virtual environments.
+ # An executable with the same name as sys.executable might not exist in
+ # virtual environments. An executable with 'python' as the steam —
+ # without version numbers or ABI flags — will always be present in
+ # virtual environments, so we use that.
+ python_exe_name = "python" + sysconfig.get_config_var("EXE")
+
+ self.bin_path = self.paths["scripts"]
+ self.python_path = os.path.join(self.bin_path, python_exe_name)
- sysconfig_paths = sysconfig.get_paths(scheme)
- data_path = Path(sysconfig_paths["data"])
- path = Path(sysconfig_paths[sysconfig_path])
- relative_path = path.relative_to(data_path)
+ @staticmethod
+ def _get_sysconfig_paths(prefix):
+ """Calculate the sysconfig paths of a virtual environment in the given prefix.
- # Path to virtualenv's "site-packages" directory for provided sysconfig path
- return os.path.normpath(os.path.normcase(Path(self.prefix) / relative_path))
+ The virtual environment MUST be using the same Python distribution as us.
+ """
+ # Determine the sysconfig scheme used in virtual environments
+ if "venv" in sysconfig.get_scheme_names():
+ # A 'venv' scheme was added in Python 3.11 to allow users to
+ # calculate the paths for a virtual environment, since the default
+ # scheme may not always be the same as used on virtual environments.
+ # Some common examples are the system Python distributed by macOS,
+ # Debian, and Fedora.
+ # For more information, see https://github.com/python/cpython/issues/89576
+ venv_scheme = "venv"
+ elif os.name == "nt":
+ # We know that before the 'venv' scheme was added, on Windows,
+ # the 'nt' scheme was used in virtual environments.
+ venv_scheme = "nt"
+ elif os.name == "posix":
+ # We know that before the 'venv' scheme was added, on POSIX,
+ # the 'posix_prefix' scheme was used in virtual environments.
+ venv_scheme = "posix_prefix"
+ else:
+ # This should never happen with upstream Python, as the 'venv'
+ # scheme should always be available on >=3.11, and no other
+ # platforms are supported by the upstream on older Python versions.
+ #
+ # Since the 'venv' scheme isn't available, and we have no knowledge
+ # of this platform/distribution, fallback to the default scheme.
+ #
+ # Hitting this will likely be the result of running a custom Python
+ # distribution targetting a platform that is not supported by the
+ # upstream.
+ # In this case, unless the Python vendor patched the Python
+ # distribution in such a way as the default scheme may not always be
+ # the same scheme, using the default scheme should be correct.
+ # If the vendor did patch Python as such, to work around this issue,
+ # I would recommend them to define a 'venv' scheme that matches
+ # the layout used on virtual environments in their Python distribution.
+ # (rec. signed Filipe Laíns — upstream sysconfig maintainer)
+ venv_scheme = sysconfig.get_default_scheme()
+ warnings.warn(
+ f"Unknown platform '{os.name}', using the default install scheme '{venv_scheme}'. "
+ "If this is incorrect, please ask your Python vendor to add a 'venv' sysconfig scheme "
+ "(see https://github.com/python/cpython/issues/89576, or check the code comment).",
+ stacklevel=2,
+ )
+ # Build the sysconfig config_vars dictionary for the virtual environment.
+ venv_vars = sysconfig.get_config_vars().copy()
+ venv_vars["base"] = venv_vars["platbase"] = prefix
+ # Get sysconfig paths for the virtual environment.
+ return sysconfig.get_paths(venv_scheme, vars=venv_vars)
+
+ def resolve_sysconfig_packages_path(self, sysconfig_path):
+ return self.paths[sysconfig_path]
def site_packages_dirs(self):
dirs = []
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/11bd3e1…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/11bd3e1…
You're receiving this email because of your account on gitlab.torproject.org.
Pier Angelo Vendrame pushed to branch base-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits:
73a4e6ad by Filipe Laíns at 2024-12-10T10:24:41+01:00
Bug 1935621 - Fix virtual environment sysconfig path calculation r=firefox-build-system-reviewers,ahochheiden
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Signed-off-by: Filipe Laíns <lains(a)riseup.net>
Differential Revision: https://phabricator.services.mozilla.com/D231480
- - - - -
1 changed file:
- python/mach/mach/site.py
Changes:
=====================================
python/mach/mach/site.py
=====================================
@@ -17,6 +17,7 @@ import subprocess
import sys
import sysconfig
import tempfile
+import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Optional
@@ -817,33 +818,75 @@ class PythonVirtualenv:
"""Calculates paths of interest for general python virtual environments"""
def __init__(self, prefix):
- if _is_windows:
- self.bin_path = os.path.join(prefix, "Scripts")
- self.python_path = os.path.join(self.bin_path, "python.exe")
- else:
- self.bin_path = os.path.join(prefix, "bin")
- self.python_path = os.path.join(self.bin_path, "python")
self.prefix = os.path.realpath(prefix)
+ self.paths = self._get_sysconfig_paths(self.prefix)
- @functools.lru_cache(maxsize=None)
- def resolve_sysconfig_packages_path(self, sysconfig_path):
- # macOS uses a different default sysconfig scheme based on whether it's using the
- # system Python or running in a virtualenv.
- # Manually define the scheme (following the implementation in
- # "sysconfig._get_default_scheme()") so that we're always following the
- # code path for a virtualenv directory structure.
- if os.name == "posix":
- scheme = "posix_prefix"
- else:
- scheme = os.name
+ # Name of the Python executable to use in virtual environments.
+ # An executable with the same name as sys.executable might not exist in
+ # virtual environments. An executable with 'python' as the steam —
+ # without version numbers or ABI flags — will always be present in
+ # virtual environments, so we use that.
+ python_exe_name = "python" + sysconfig.get_config_var("EXE")
+
+ self.bin_path = self.paths["scripts"]
+ self.python_path = os.path.join(self.bin_path, python_exe_name)
- sysconfig_paths = sysconfig.get_paths(scheme)
- data_path = Path(sysconfig_paths["data"])
- path = Path(sysconfig_paths[sysconfig_path])
- relative_path = path.relative_to(data_path)
+ @staticmethod
+ def _get_sysconfig_paths(prefix):
+ """Calculate the sysconfig paths of a virtual environment in the given prefix.
- # Path to virtualenv's "site-packages" directory for provided sysconfig path
- return os.path.normpath(os.path.normcase(Path(self.prefix) / relative_path))
+ The virtual environment MUST be using the same Python distribution as us.
+ """
+ # Determine the sysconfig scheme used in virtual environments
+ if "venv" in sysconfig.get_scheme_names():
+ # A 'venv' scheme was added in Python 3.11 to allow users to
+ # calculate the paths for a virtual environment, since the default
+ # scheme may not always be the same as used on virtual environments.
+ # Some common examples are the system Python distributed by macOS,
+ # Debian, and Fedora.
+ # For more information, see https://github.com/python/cpython/issues/89576
+ venv_scheme = "venv"
+ elif os.name == "nt":
+ # We know that before the 'venv' scheme was added, on Windows,
+ # the 'nt' scheme was used in virtual environments.
+ venv_scheme = "nt"
+ elif os.name == "posix":
+ # We know that before the 'venv' scheme was added, on POSIX,
+ # the 'posix_prefix' scheme was used in virtual environments.
+ venv_scheme = "posix_prefix"
+ else:
+ # This should never happen with upstream Python, as the 'venv'
+ # scheme should always be available on >=3.11, and no other
+ # platforms are supported by the upstream on older Python versions.
+ #
+ # Since the 'venv' scheme isn't available, and we have no knowledge
+ # of this platform/distribution, fallback to the default scheme.
+ #
+ # Hitting this will likely be the result of running a custom Python
+ # distribution targetting a platform that is not supported by the
+ # upstream.
+ # In this case, unless the Python vendor patched the Python
+ # distribution in such a way as the default scheme may not always be
+ # the same scheme, using the default scheme should be correct.
+ # If the vendor did patch Python as such, to work around this issue,
+ # I would recommend them to define a 'venv' scheme that matches
+ # the layout used on virtual environments in their Python distribution.
+ # (rec. signed Filipe Laíns — upstream sysconfig maintainer)
+ venv_scheme = sysconfig.get_default_scheme()
+ warnings.warn(
+ f"Unknown platform '{os.name}', using the default install scheme '{venv_scheme}'. "
+ "If this is incorrect, please ask your Python vendor to add a 'venv' sysconfig scheme "
+ "(see https://github.com/python/cpython/issues/89576, or check the code comment).",
+ stacklevel=2,
+ )
+ # Build the sysconfig config_vars dictionary for the virtual environment.
+ venv_vars = sysconfig.get_config_vars().copy()
+ venv_vars["base"] = venv_vars["platbase"] = prefix
+ # Get sysconfig paths for the virtual environment.
+ return sysconfig.get_paths(venv_scheme, vars=venv_vars)
+
+ def resolve_sysconfig_packages_path(self, sysconfig_path):
+ return self.paths[sysconfig_path]
def site_packages_dirs(self):
dirs = []
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/73a4e6a…
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/73a4e6a…
You're receiving this email because of your account on gitlab.torproject.org.