Skip to content

Add conditional check for git checkout in development path #417

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KJ7LNW
Copy link

@KJ7LNW KJ7LNW commented Jul 20, 2025

This PR adds a conditional check to only insert the development path into sys.path when running from a git checkout.

Changes

  • Added entire conditional block with os.path.exists() check for ../.git directory
  • Wrapped the existing sys.path.insert() call in the new conditional
  • Previously the development path was always inserted - now it only happens when running from a git repository

Benefits

  • More robust: Prevents potential import errors when script is run from installed package
  • Cleaner behavior: Only modifies sys.path when actually in a development environment
  • Production-safe: Falls back gracefully to installed package in non-git environments

Usage

When running from a git checkout:

./bin/github-backup --help

The script will detect the .git directory and use the development tree.

When running from an installed package, it will use the installed modules without attempting to modify sys.path.

Before: The sys.path.insert() was always executed
After: The sys.path.insert() only executes when ../.git exists

Only insert development path into sys.path when running from a git checkout
(when ../.git exists). This makes the script more robust by only using the
development tree when available and falling back to installed package otherwise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant