Repository: astral-sh/uv
File: crates/uv/src/commands/project/run.rs (Rust)

Code before:
            // later ones.
            for interpreter in [requirements_env.interpreter(), &base_interpreter] {
                // Copy each entrypoint from the base environments to the ephemeral environment.
                for entry in fs_err::read_dir(interpreter.scripts())? {
                    let entry = entry?;

                    if !entry.file_type()?.is_file() {
                        continue;
                    }

                    copy_entrypoint(
                        &entry.path(),
                        &ephemeral_env.scripts().join(entry.file_name()),
                        interpreter.sys_executable(),
                        ephemeral_env.sys_executable(),
                    )?;
                }

                // Link common data directories from the base environment to the ephemeral
                // environment. This is critical for Jupyter Lab, which cannot operate without the
                // files it writes to `<prefix>/share`.
                //
                // We only perform a shallow merge here, so `<prefix>/share/<name>` will only be
                // written once and contents beyond the first level, e.g.,
                // `<prefix>/share/<name>/foo` will not be merged across parent interpreters.
                for dir in &["etc", "share"] {
                    let entries = match fs_err::read_dir(interpreter.sys_prefix().join(dir)) {
                        Ok(entries) => entries,
                        // Skip missing directories
                        Err(err) if err.kind() == std::io::ErrorKind::NotFound => continue,
                        Err(err) => return Err(err.into()),
                    };
                    fs_err::create_dir_all(ephemeral_env.sys_prefix().join(dir))?;
                    for entry in entries {
                        let entry = entry?;
                        let target = ephemeral_env.sys_prefix().join(dir).join(entry.file_name());

                        if entry.file_type()?.is_file() {
                            match symlink_or_copy_file(entry.path(), &target) {
                                Ok(()) => trace!(
                                    "Created link for {} -> {}",
                                    target.user_display(),
                                    entry.path().user_display()
                                ),
                                Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => {}
                                Err(err) => return Err(err.into()),
                            }
                        } else if entry.file_type()?.is_dir() {
                            match create_symlink(entry.path(), &target) {
                                Ok(()) => trace!(
                                    "Created link for {} -> {}",

Review comment (suggestion):
Since this is just for Jupyter right now, we could narrow this to just apply to the `share/jupyter` directory if we wanted 🤔 

Code after:
            // N.B. The order here matters — earlier interpreters take precedence over the
            // later ones.
            for interpreter in [requirements_env.interpreter(), &base_interpreter] {
                // Copy each entrypoint from the base environments to the ephemeral environment,
                // updating the Python executable target to ensure they run in the ephemeral
                // environment.
                for entry in fs_err::read_dir(interpreter.scripts())? {
                    let entry = entry?;
                    if !entry.file_type()?.is_file() {
                        continue;
                    }
                    match copy_entrypoint(
                        &entry.path(),
                        &ephemeral_env.scripts().join(entry.file_name()),
                        interpreter.sys_executable(),
                        ephemeral_env.sys_executable(),
                    ) {
                        Ok(()) => {}
                        // If the entrypoint already exists, skip it.
                        Err(CopyEntrypointError::Io(err))
                            if err.kind() == std::io::ErrorKind::AlreadyExists =>
                        {
                            trace!(
                                "Skipping copy of entrypoint `{}`: already exists",
                                &entry.path().display()
                            );
                        }
                        Err(err) => return Err(err.into()),
                    }
                }

                // Link data directories from the base environment to the ephemeral environment.
                //
                // This is critical for Jupyter Lab, which cannot operate without the files it
                // writes to `<prefix>/share/jupyter`.
                //
                // See https://github.com/jupyterlab/jupyterlab/issues/17716
                for dir in &["etc/jupyter", "share/jupyter"] {
                    let source = interpreter.sys_prefix().join(dir);
                    if !matches!(source.try_exists(), Ok(true)) {
                        continue;
                    }
                    if !source.is_dir() {
                        continue;
                    }
                    let target = ephemeral_env.sys_prefix().join(dir);
                    if let Some(parent) = target.parent() {
                        fs_err::create_dir_all(parent)?;
                    }
                    match create_symlink(&source, &target) {
                        Ok(()) => trace!(