Make lib iteration platform-specific (#5406)

This commit is contained in:
Charlie Marsh 2023-06-28 09:52:20 -04:00 committed by GitHub
parent 6587fb844a
commit 979049b2a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View file

@ -5,3 +5,16 @@ pub(crate) enum PythonPlatform {
Linux,
Windows,
}
impl PythonPlatform {
/// Returns the platform-specific library names. These are the candidate names for the top-level
/// subdirectory within a virtual environment that contains the `site-packages` directory
/// (with a `pythonX.Y` directory in-between).
pub(crate) fn lib_names(&self) -> &[&'static str] {
match self {
PythonPlatform::Darwin => &["lib"],
PythonPlatform::Linux => &["lib", "lib64"],
PythonPlatform::Windows => &["Lib"],
}
}
}

View file

@ -140,7 +140,7 @@ fn find_python_search_paths<Host: host::Host>(config: &Config, host: &Host) -> V
if let Some(venv) = config.venv.as_ref() {
let mut found_paths = vec![];
for lib_name in ["lib", "Lib", "lib64"] {
for lib_name in host.python_platform().lib_names() {
let lib_path = venv_path.join(venv).join(lib_name);
if let Some(site_packages_path) = find_site_packages_path(&lib_path, None) {
// Add paths from any `.pth` files in each of the `site-packages` directories.

View file

@ -11,11 +11,11 @@ ImportResult {
is_stub_package: false,
import_type: ThirdParty,
resolved_paths: [
"./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy/__init__.py",
"./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy/orm/__init__.py",
"./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy/__init__.py",
"./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy/orm/__init__.py",
],
search_path: Some(
"./resources/test/airflow/venv/Lib/python3.11/site-packages",
"./resources/test/airflow/venv/lib/python3.11/site-packages",
),
is_stub_file: false,
is_native_lib: false,
@ -27,21 +27,21 @@ ImportResult {
is_stub_file: false,
is_native_lib: false,
name: "base",
path: "./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy/orm/base.py",
path: "./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy/orm/base.py",
py_typed: None,
},
"dependency": ImplicitImport {
is_stub_file: false,
is_native_lib: false,
name: "dependency",
path: "./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy/orm/dependency.py",
path: "./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy/orm/dependency.py",
py_typed: None,
},
"query": ImplicitImport {
is_stub_file: false,
is_native_lib: false,
name: "query",
path: "./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy/orm/query.py",
path: "./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy/orm/query.py",
py_typed: None,
},
},
@ -49,6 +49,6 @@ ImportResult {
non_stub_import_result: None,
py_typed_info: None,
package_directory: Some(
"./resources/test/airflow/venv/Lib/python3.11/site-packages/sqlalchemy",
"./resources/test/airflow/venv/lib/python3.11/site-packages/sqlalchemy",
),
}