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

Allow sourcing of dev_tools/pypath from any path #4739

Merged
Merged
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions dev_tools/pypath
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,26 @@

#####
# The main file to use to setup your PYTHONPATH. It sets up all cirq modules on the path.
# The file can be sourced from any location with bash or zsh.
# Usage:
# source dev_tools/pypath
#####


#!/usr/bin/bash
if [ -n "${ZSH_VERSION}" ]; then
_PYPATH_BASE_DIR="${${(%):-%x}:a:h:h}"
else
_PYPATH_BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fi

PREFIX="$(pwd)"
CIRQ_MODULES=$(env PYTHONPATH=. python dev_tools/modules.py list --mode folder)
for m in $CIRQ_MODULES; do
PREFIX="$PREFIX:$(pwd)/$m"
done
_PYPATH_PREFIX="${_PYPATH_BASE_DIR}$(
cd "${_PYPATH_BASE_DIR}" &&
env PYTHONPATH=. python3 dev_tools/modules.py list --mode folder |
xargs printf ":${_PYPATH_BASE_DIR}/%s"
)"

[[ $PYTHONPATH == ${PREFIX}* ]] || export PYTHONPATH="$PREFIX:$PYTHONPATH"
[[ $PYTHONPATH == ${_PYPATH_PREFIX}* ]] ||
export PYTHONPATH="${_PYPATH_PREFIX}${PYTHONPATH:+:}${PYTHONPATH}"

unset _PYPATH_BASE_DIR
unset _PYPATH_PREFIX