Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move to pub(crate) fn in order to detect and remove unused functions #1805

Merged
merged 3 commits into from
Aug 13, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum CurrentEnvVarBehavior {

impl Project {
/// Returns environment variables and their values that should be injected when running a command.
pub fn get_metadata_env(&self) -> HashMap<String, String> {
pub(crate) fn get_metadata_env(&self) -> HashMap<String, String> {
let mut map = HashMap::from_iter([
(
format!("{PROJECT_PREFIX}ROOT"),
Expand Down Expand Up @@ -69,7 +69,7 @@ const ENV_PREFIX: &str = "PIXI_ENVIRONMENT_";

impl Environment<'_> {
/// Returns environment variables and their values that should be injected when running a command.
pub fn get_metadata_env(&self) -> IndexMap<String, String> {
pub(crate) fn get_metadata_env(&self) -> IndexMap<String, String> {
let prompt = match self.name() {
EnvironmentName::Named(name) => {
format!("{}:{}", self.project().name(), name)
Expand All @@ -95,7 +95,7 @@ impl Environment<'_> {
/// This method will create an activator for the environment and add the activation scripts from the project.
/// The activator will be created for the current platform and the default shell.
/// The activation scripts from the environment will be checked for existence and the extension will be checked for correctness.
pub fn get_activator<'p>(
pub(crate) fn get_activator<'p>(
environment: &'p Environment<'p>,
shell: ShellEnum,
) -> Result<Activator<ShellEnum>, ActivationError> {
Expand Down Expand Up @@ -215,7 +215,7 @@ pub async fn run_activation(

/// Get the environment variables that are statically generated from the project and the environment.
/// Returns IndexMap to stay sorted, as pixi should export the metadata before exporting variables that could depend on it.
pub fn get_static_environment_variables<'p>(
pub(crate) fn get_static_environment_variables<'p>(
environment: &'p Environment<'p>,
) -> IndexMap<String, String> {
// Get environment variables from the pixi project meta data
Expand All @@ -242,7 +242,7 @@ pub fn get_static_environment_variables<'p>(

/// Get the environment variables that are set in the current shell
/// and strip them down to the minimal set required to run a command.
pub fn get_clean_environment_variables() -> HashMap<String, String> {
pub(crate) fn get_clean_environment_variables() -> HashMap<String, String> {
let env = std::env::vars().collect::<HashMap<_, _>>();

let unix_keys = if cfg!(unix) {
Expand Down
18 changes: 11 additions & 7 deletions src/cli/cli_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ pub struct ChannelsConfig {

impl ChannelsConfig {
/// Parses the channels, getting channel config and default channels from config
pub fn resolve_from_config(&self, config: &Config) -> IndexSet<Channel> {
pub(crate) fn resolve_from_config(&self, config: &Config) -> IndexSet<Channel> {
self.resolve(config.global_channel_config(), config.default_channels())
}

/// Parses the channels, getting channel config and default channels from project
pub fn resolve_from_project(&self, project: Option<&Project>) -> IndexSet<Channel> {
pub(crate) fn resolve_from_project(&self, project: Option<&Project>) -> IndexSet<Channel> {
match project {
Some(project) => {
let channels = project
Expand Down Expand Up @@ -91,7 +91,7 @@ pub struct PrefixUpdateConfig {
pub config: ConfigCli,
}
impl PrefixUpdateConfig {
pub fn lock_file_usage(&self) -> LockFileUsage {
pub(crate) fn lock_file_usage(&self) -> LockFileUsage {
if self.no_lockfile_update {
LockFileUsage::Frozen
} else {
Expand All @@ -100,7 +100,7 @@ impl PrefixUpdateConfig {
}

/// Decide whether to install or not.
pub fn no_install(&self) -> bool {
pub(crate) fn no_install(&self) -> bool {
self.no_install || self.no_lockfile_update
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ pub struct DependencyConfig {
}

impl DependencyConfig {
pub fn dependency_type(&self) -> DependencyType {
pub(crate) fn dependency_type(&self) -> DependencyType {
if self.pypi {
DependencyType::PypiDependency
} else if self.host {
Expand All @@ -146,12 +146,16 @@ impl DependencyConfig {
DependencyType::CondaDependency(SpecType::Run)
}
}
pub fn feature_name(&self) -> FeatureName {
pub(crate) fn feature_name(&self) -> FeatureName {
self.feature
.clone()
.map_or(FeatureName::Default, FeatureName::Named)
}
pub fn display_success(&self, operation: &str, implicit_constraints: HashMap<String, String>) {
pub(crate) fn display_success(
&self,
operation: &str,
implicit_constraints: HashMap<String, String>,
) {
for package in self.specs.clone() {
eprintln!(
"{}{operation} {}{}",
Expand Down
14 changes: 7 additions & 7 deletions src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod tests {
use super::*;

#[test]
pub fn test_zsh_completion() {
pub(crate) fn test_zsh_completion() {
let script = r#"
(add)
_arguments "${_arguments_options[@]}" \
Expand Down Expand Up @@ -205,7 +205,7 @@ _arguments "${_arguments_options[@]}" \
}

#[test]
pub fn test_bash_completion() {
pub(crate) fn test_bash_completion() {
// NOTE THIS IS FORMATTED BY HAND!
let script = r#"
pixi__project__help__help)
Expand Down Expand Up @@ -251,7 +251,7 @@ _arguments "${_arguments_options[@]}" \
}

#[test]
pub fn test_nushell_completion() {
pub(crate) fn test_nushell_completion() {
// NOTE THIS IS FORMATTED BY HAND!
let script = r#"
# Runs task in project
Expand All @@ -276,23 +276,23 @@ _arguments "${_arguments_options[@]}" \
}

#[test]
pub fn test_bash_completion_working_regex() {
pub(crate) fn test_bash_completion_working_regex() {
// Generate the original completion script.
let script = get_completion_script(Shell::Bash);
// Test if there was a replacement done on the clap generated completions
assert_ne!(replace_bash_completion(&script), script);
}

#[test]
pub fn test_zsh_completion_working_regex() {
pub(crate) fn test_zsh_completion_working_regex() {
// Generate the original completion script.
let script = get_completion_script(Shell::Zsh);
// Test if there was a replacement done on the clap generated completions
assert_ne!(replace_zsh_completion(&script), script);
}

#[test]
pub fn test_fish_completion_working_regex() {
pub(crate) fn test_fish_completion_working_regex() {
// Generate the original completion script.
let script = get_completion_script(Shell::Fish);
let replaced_script = replace_fish_completion(&script);
Expand All @@ -301,7 +301,7 @@ _arguments "${_arguments_options[@]}" \
}

#[test]
pub fn test_nushell_completion_working_regex() {
pub(crate) fn test_nushell_completion_working_regex() {
// Generate the original completion script.
let script = get_completion_script(Shell::Nushell);
// Test if there was a replacement done on the clap generated completions
Expand Down
4 changes: 2 additions & 2 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct EnvironmentHash {
}

impl EnvironmentHash {
pub fn from_args(args: &Args, config: &Config) -> Self {
pub(crate) fn from_args(args: &Args, config: &Config) -> Self {
Self {
command: args
.command
Expand All @@ -73,7 +73,7 @@ impl EnvironmentHash {
}

/// Returns the name of the environment.
pub fn name(&self) -> String {
pub(crate) fn name(&self) -> String {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
let hash = hasher.finish();
Expand Down
4 changes: 2 additions & 2 deletions src/cli/global/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl BinEnvDir {
/// # Returns
///
/// The global binaries directory
pub fn bin_dir() -> Option<PathBuf> {
pub(crate) fn bin_dir() -> Option<PathBuf> {
home_path().map(|path| path.join("bin"))
}

Expand All @@ -92,7 +92,7 @@ pub fn bin_dir() -> Option<PathBuf> {
/// # Returns
///
/// The global binary environments directory
pub fn bin_env_dir() -> Option<PathBuf> {
pub(crate) fn bin_env_dir() -> Option<PathBuf> {
home_path().map(|path| path.join("envs"))
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub(super) async fn create_executable_scripts(
}

/// Warn user on dangerous package installations, interactive yes no prompt
pub fn prompt_user_to_continue(
pub(crate) fn prompt_user_to_continue(
packages: &IndexMap<PackageName, MatchSpec>,
) -> miette::Result<bool> {
let dangerous_packages = HashMap::from([
Expand Down
2 changes: 1 addition & 1 deletion src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct PackageToOutput {
}

/// Get directory size
pub fn get_dir_size<P>(path: P) -> std::io::Result<u64>
pub(crate) fn get_dir_size<P>(path: P) -> std::io::Result<u64>
where
P: AsRef<std::path::Path>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/project/channel/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Args {
pub urls: bool,
}

pub fn execute(project: Project, args: Args) -> miette::Result<()> {
pub(crate) fn execute(project: Project, args: Args) -> miette::Result<()> {
let channel_config = project.channel_config();
project
.environments()
Expand Down
8 changes: 4 additions & 4 deletions src/cli/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub struct PackagesDiff {

impl PackagesDiff {
/// Returns true if the diff is empty.
pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
self.added.is_empty() && self.removed.is_empty() && self.changed.is_empty()
}
}
Expand All @@ -287,7 +287,7 @@ pub struct LockFileDiff {

impl LockFileDiff {
/// Determine the difference between two lock-files.
pub fn from_lock_files(previous: &LockFile, current: &LockFile) -> Self {
pub(crate) fn from_lock_files(previous: &LockFile, current: &LockFile) -> Self {
let mut result = Self {
environment: IndexMap::new(),
};
Expand Down Expand Up @@ -425,12 +425,12 @@ impl LockFileDiff {
}

/// Returns true if the diff is empty.
pub fn is_empty(&self) -> bool {
pub(crate) fn is_empty(&self) -> bool {
self.environment.is_empty()
}

// Format the lock-file diff.
pub fn print(&self) -> std::io::Result<()> {
pub(crate) fn print(&self) -> std::io::Result<()> {
let mut writer = TabWriter::new(stdout());
for (idx, (environment_name, environment)) in self
.environment
Expand Down
4 changes: 2 additions & 2 deletions src/conda_pypi_clobber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) struct PypiCondaClobberRegistry {
impl PypiCondaClobberRegistry {
/// Register the paths of the installed conda packages
/// to later check if they are going to be clobbered by the installation of the wheels
pub fn with_conda_packages(conda_packages: &[PrefixRecord]) -> Self {
pub(crate) fn with_conda_packages(conda_packages: &[PrefixRecord]) -> Self {
let mut registry = AHashMap::with_capacity(conda_packages.len() * 50);
for record in conda_packages {
for path in &record.paths_data.paths {
Expand All @@ -37,7 +37,7 @@ impl PypiCondaClobberRegistry {
/// this allow to warn the user about the overwriting of already installed packages
/// in case of wrong mapping data
/// or malicious packages
pub fn clobber_on_installation(
pub(crate) fn clobber_on_installation(
self,
wheels: Vec<CachedDist>,
venv: &PythonEnvironment,
Expand Down
14 changes: 8 additions & 6 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub(crate) struct EnvironmentFile {
/// Write information about the environment to a file in the environment
/// directory. This can be useful for other tools that only know the environment
/// directory to find the original project.
pub fn write_environment_file(
pub(crate) fn write_environment_file(
environment_dir: &Path,
env_file: EnvironmentFile,
) -> miette::Result<PathBuf> {
Expand Down Expand Up @@ -231,15 +231,15 @@ pub enum LockFileUsage {

impl LockFileUsage {
/// Returns true if the lock-file should be updated if it is out of date.
pub fn allows_lock_file_updates(self) -> bool {
pub(crate) fn allows_lock_file_updates(self) -> bool {
match self {
LockFileUsage::Update => true,
LockFileUsage::Locked | LockFileUsage::Frozen => false,
}
}

/// Returns true if the lock-file should be checked if it is out of date.
pub fn should_check_if_out_of_date(self) -> bool {
pub(crate) fn should_check_if_out_of_date(self) -> bool {
match self {
LockFileUsage::Update | LockFileUsage::Locked => true,
LockFileUsage::Frozen => false,
Expand Down Expand Up @@ -444,7 +444,9 @@ pub enum PythonStatus {

impl PythonStatus {
/// Determine the [`PythonStatus`] from a [`Transaction`].
pub fn from_transaction(transaction: &Transaction<PrefixRecord, RepoDataRecord>) -> Self {
pub(crate) fn from_transaction(
transaction: &Transaction<PrefixRecord, RepoDataRecord>,
) -> Self {
match (
transaction.current_python_info.as_ref(),
transaction.python_info.as_ref(),
Expand All @@ -464,7 +466,7 @@ impl PythonStatus {

/// Returns the info of the current situation (e.g. after the transaction
/// completed).
pub fn current_info(&self) -> Option<&PythonInfo> {
pub(crate) fn current_info(&self) -> Option<&PythonInfo> {
match self {
PythonStatus::Changed { new, .. }
| PythonStatus::Unchanged(new)
Expand All @@ -475,7 +477,7 @@ impl PythonStatus {

/// Returns the location of the python interpreter relative to the root of
/// the prefix.
pub fn location(&self) -> Option<&Path> {
pub(crate) fn location(&self) -> Option<&Path> {
Some(&self.current_info()?.path)
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/install_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type WheelInfo = (Vec<RecordEntry>, PathBuf);
/// (`purelib`, `platlib` or `unknown`).
///
/// This function is used to detect if Python wheels will clobber already installed Conda packages
pub fn get_wheel_info(whl: &Path, venv: &PythonEnvironment) -> miette::Result<Option<WheelInfo>> {
pub(crate) fn get_wheel_info(
whl: &Path,
venv: &PythonEnvironment,
) -> miette::Result<Option<WheelInfo>> {
let dist_info_prefix = find_dist_info(whl)?;
// Read the RECORD file.
let mut record_file =
Expand Down Expand Up @@ -63,7 +66,7 @@ fn find_dist_info(path: impl AsRef<Path>) -> miette::Result<String> {

/// Reads the record file
/// <https://www.python.org/dev/peps/pep-0376/#record>
pub fn read_record_file(record: &mut impl Read) -> miette::Result<Vec<RecordEntry>> {
pub(crate) fn read_record_file(record: &mut impl Read) -> miette::Result<Vec<RecordEntry>> {
ReaderBuilder::new()
.has_headers(false)
.escape(Some(b'"'))
Expand All @@ -80,7 +83,10 @@ pub fn read_record_file(record: &mut impl Read) -> miette::Result<Vec<RecordEntr
.collect()
}

pub fn get_wheel_kind(wheel_path: &Path, dist_info_prefix: String) -> miette::Result<LibKind> {
pub(crate) fn get_wheel_kind(
wheel_path: &Path,
dist_info_prefix: String,
) -> miette::Result<LibKind> {
// We're going step by step though
// https://packaging.python.org/en/latest/specifications/binary-distribution-format/#installing-a-wheel-distribution-1-0-py32-none-any-whl
// > 1.a Parse distribution-1.0.dist-info/WHEEL.
Expand Down
Loading
Loading