@@ -110,6 +110,62 @@ case ${TEST_TYPE} in
110110 ;;
111111 esac
112112 ;;
113+ import_profile)
114+ if [ -f setup.py ] || [ -f pyproject.toml ]; then
115+ echo " Creating temporary virtualenv for import profile..."
116+ python3 -m venv .venv-profiler
117+ source .venv-profiler/bin/activate
118+ python -m pip install --upgrade pip setuptools
119+
120+ PACKAGE_NAME=$( basename $( pwd) )
121+ PROFILER_TEMP_DIR=$( mktemp -d)
122+ cp ../../scripts/import_profiler/profiler.py " ${PROFILER_TEMP_DIR} /profiler.py"
123+ PROFILER_SCRIPT=" ${PROFILER_TEMP_DIR} /profiler.py"
124+ BASELINE_CSV=" ${PROFILER_TEMP_DIR} /baseline_${PACKAGE_NAME} .csv"
125+
126+ if [ -n " ${TARGET_BRANCH} " ]; then
127+ # Try upstream first (for forks), then origin
128+ BASELINE_COMMIT=$( git merge-base HEAD " upstream/${TARGET_BRANCH} " 2> /dev/null || \
129+ git merge-base HEAD " origin/${TARGET_BRANCH} " 2> /dev/null || \
130+ git merge-base HEAD " ${TARGET_BRANCH} " 2> /dev/null || true)
131+ if [ -n " ${BASELINE_COMMIT} " ]; then
132+ echo " Checking out baseline commit ${BASELINE_COMMIT} in a temporary worktree..."
133+ REPO_PREFIX=$( git rev-parse --show-prefix)
134+ WORKTREE_DIR=$( mktemp -d)
135+ rmdir " ${WORKTREE_DIR} "
136+ if git worktree add " ${WORKTREE_DIR} " " ${BASELINE_COMMIT} " 2> /dev/null; then
137+ (
138+ cd " ${WORKTREE_DIR} /${REPO_PREFIX} "
139+ if [ -f setup.py ] || [ -f pyproject.toml ]; then
140+ pip install -e .
141+ python " ${PROFILER_SCRIPT} " --package " ${PACKAGE_NAME} " --iterations 11 --csv " ${BASELINE_CSV} "
142+ fi
143+ )
144+ git worktree remove -f " ${WORKTREE_DIR} "
145+ else
146+ echo " Failed to create git worktree for baseline. Skipping baseline generation."
147+ fi
148+ else
149+ echo " Could not find baseline commit for ${TARGET_BRANCH:- main} . Skipping baseline generation."
150+ fi
151+ fi
152+
153+ pip install -e .
154+
155+ if [ -f " ${BASELINE_CSV} " ]; then
156+ python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 11 --fail-threshold 5000 --diff-baseline " ${BASELINE_CSV} " --diff-threshold 100
157+ else
158+ python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 11 --fail-threshold 5000
159+ fi
160+ retval=$?
161+ deactivate
162+ rm -rf .venv-profiler
163+ rm -rf " ${PROFILER_TEMP_DIR} "
164+ else
165+ echo " Skipping import_profile as this does not appear to be a Python package (no setup.py or pyproject.toml)."
166+ retval=0
167+ fi
168+ ;;
113169 * )
114170 nox -s ${TEST_TYPE}
115171 retval=$?
0 commit comments