Normally PORTDIR can be used to override the main repository location. However, this doesn't work if there is no checkout of the repository yet and PORTDIR names the location where it is expected to be created. $ PORTDIR=/tmp/test emerge --syn /usr/lib64/python3.3/site-packages/portage/sync/controller.py:104: BytesWarning: str() on a bytes instance % (warn("*"), name,), level=logging.WARN, noiselevel=2) >>> Synchronization of repository 'gentoo' located in '/usr/portage'... If /tmp/test was a valid repository, it would use it instead.
The new portage.path.first_existing function can be used to handle cases like this. For example, os.access(first_existing(portdir), os.W_OK) can be used to check if portdir is writable or can be created.