Skip to content

Improve handling of hardcoded file paths/names #1261

@lrandersson

Description

@lrandersson

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

Consolidate hardcoded file and directory names used across the codebase into a central constants module. Currently, the same file names are repeated as string literals in multiple modules, making them prone to typos and harder to maintain.

Why is this needed?

  • Maintainability: Changing a file name requires finding and updating multiple locations
  • Consistency: Reduces risk of typos or inconsistent naming across modules
  • Discoverability: New contributors can understand the file structure from one place
  • Refactoring safety: Constants make it easier to rename paths without missing occurrences

What should happen?

Possibly a central location (e.g., constructor/paths.py or a section in utils.py) where we define constants for commonly used file and directory names. These constants would then be imported where needed.

Additional Context

I ran an analysis with an AI Tool of locating all of these and count the occurrences, now, with this list below I'm not saying all of these have to be replaced, but can be used for context when working on this issue. I ran this including the MSI feature branch.

Analysis of hardcoded file/directory names in the codebase:

Directory names

Name Occurrences Modules
conda-meta ~25 main.py, shar.py, preconda.py, winexe.py, header.sh, run_installation.sh
pkgs ~15 shar.py, preconda.py, winexe.py, osxpkg.py, utils.py
envs ~10 shar.py, preconda.py, winexe.py, header.sh, run_installation.sh
cache ~4 shar.py, winexe.py

Files within conda-meta/

Name Occurrences Modules
history ~12 shar.py, preconda.py, winexe.py, osx/*.sh
initial-state.explicit.txt ~10 preconda.py, winexe.py, shar.py, header.sh, run_installation.sh
frozen ~8 main.py, shar.py, preconda.py, winexe.py

Files within pkgs/

Name Occurrences Modules
urls.txt ~4 preconda.py, winexe.py
urls ~3 preconda.py, winexe.py
shortcuts.txt ~3 shar.py, preconda.py
repodata_record.json ~4 shar.py, preconda.py, winexe.py

Config files

Name Occurrences Modules
.condarc ~8 winexe.py, utils.py, osx/run_installation.sh

User-provided install scripts

Name Occurrences Modules
pre_install.bat / pre_install.sh ~8 winexe.py, shar.py, header.sh
post_install.bat / post_install.sh ~8 winexe.py, shar.py, header.sh
pre_uninstall.bat ~4 winexe.py, briefcase.py

Internal install scripts (MSI/PKG)

Name Occurrences Modules
user_pre_install.bat / user_pre_install ~5 briefcase.py, osxpkg.py, run_installation.bat
user_post_install.bat / user_post_install ~5 briefcase.py, osxpkg.py, run_installation.bat
user_pre_uninstall.bat ~3 briefcase.py, pre_uninstall.bat
run_installation.sh / run_installation.bat ~6 osxpkg.py, briefcase.py
prepare_installation.sh ~4 osxpkg.py
checks_before_install.sh ~2 osxpkg.py

Template scripts (macOS PKG)

Name Occurrences Modules
run_user_script.sh ~2 osxpkg.py
check_shortcuts.sh ~1 osxpkg.py
run_conda_init.sh ~1 osxpkg.py
clean_cache.sh ~1 osxpkg.py

Note: Shell template files (header.sh, run_installation.sh, etc.) would need these values passed as Jinja template variables rather than importing Python constants directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type::featurerequest for a new feature or capability

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions