Table of Contents
You can modify where new Python installations go with the _PYTHON_DIR_
environment variable or the python_dir
config entry, in that order. You
can choose shared
(~/.pythons
), isolated
, or a custom
directory.
You can modify where virtual envs are discovered with the _VENV_DIR_
environment variable or the venv_dir
config entry, in that order. You
can choose shared
(~/.virtualenvs
), isolated
, or a custom
directory.
You can disable detection by setting the environment variable
_IGNORE_VENV_
to 1
.
Hatch will always try to use the correct python/pip, however, when a virtual
env is not in use, things get a bit ambiguous. Therefore, you can set the
_DEFAULT_PYTHON_
and _DEFAULT_PIP_
environment variables to a command
name (recommended) or absolute path so the correct executable gets called. If
a virtual env is not in use and no env var is detected, the Python 3 versions
will be used on non-Windows machines.
Here is the literal implementation:
def get_proper_python():
if not venv_active():
default_python = os.environ.get('_DEFAULT_PYTHON_')
if default_python:
return default_python
elif not ON_WINDOWS:
return 'python3'
return 'python'
def get_proper_pip():
if not venv_active():
default_pip = os.environ.get('_DEFAULT_PIP_')
if default_pip:
return default_pip
elif not ON_WINDOWS:
return 'pip3'
return 'pip'
To install/uninstall/update packages globally, Hatch runs pip
with elevated
privileges. On Windows this is done with runas
, otherwise sudo -H
is used.
To change the desired name of the admin user, you can set the _DEFAULT_ADMIN_
environment variable. If this is not set, Windows will assume the user is named
Administrator
. On other systems where sudo -H
is used no user will be
specified.
Here is the literal implementation:
def get_admin_command():
if ON_WINDOWS:
return [
'runas', r'/user:{}\{}'.format(
platform.node() or os.environ.get('USERDOMAIN', ''),
os.environ.get('_DEFAULT_ADMIN_', 'Administrator')
)
]
else:
admin = os.environ.get('_DEFAULT_ADMIN_', '')
return ['sudo', '-H'] + (['--user={}'.format(admin)] if admin else [])
- shell
The shell name or command to use when activating virtual envs. Hatch currently supports custom prompts and behavior for:
fish
(recommended due to its overall awesomeness!)bash
xonsh
(also recommended)zsh
powershell
(ps
is an alias)cmd
tcsh
csh
- python_dir
- The directory to create new Python installations in. Also accepts
shared
andisolated
. - venv_dir
- The directory to create and look for virtual envs. Also accepts
shared
andisolated
. - pypaths
- Maps names to an absolute path to a Python executable.
- semver
- Maps
pre
andbuild
semver parts to a textual representation. The token to use forpre
defaults torc
(e.g.2.18.5-rc.1
) whilebuild
defaults tobuild
(e.g.2.18.4+build.1
). - pypi_username
- The username to use when uploading to PyPI.
- name
- Your name e.g. Bob Saget.
- Your email.
- basic
- If true, disables third-party services and readme badges during project creation.
- pyversions
- The default versions of Python to support. Must be in the form major.minor e.g.
3.7
. The valuespypy
andpypy3
are also accepted. - licenses
The default licenses to use. Defaults to dual MIT/Apache-2.0, which is desirable. Hatch currently supports:
mit
, which represents the MIT Licenseapache2
, which represents the Apache License, Version 2.0mpl
, which represents the Mozilla Public License 2.0cc0
, which represents the Creative Commons Zero v1.0 Universal
- readme
Mapping which helps construct your readme file. Hatch currently supports
rst
andmd
for theformat
key.Badges have the attributes
image
,target
, andalt
. Any others you add will become url parameters for theimage
. Also, if a{}
appears in theimage
ortarget
, the name of the created package will be formatted there.- vc
- The version control system to initialize when creating a project. Hatch
currently only supports
git
. - vc_url
- Your version control url e.g.
https://github.com/ofek
. - ci
- A list of third-party service files to create. Hatch currently only supports
travis
. Can be empty. - coverage
- A code coverage service to use. Hatch currently only supports
codecov
. Can be null. - extras
- A list of glob patterns to copy to new projects.