Domain Discovery
In most cases, you will use the protean script to interact with your domain
over the CLI. You tell the script where to find your domain. The script then
loads and initializes the domain so it is ready for use. The --domain option
is used to specify how to load the domain.
While --domain supports a variety of options for specifying your domain,
the below typical values cover most use cases:
(nothing)
The command looks for the domain in this order:
- A
domainpackage ordomain.pyin the current directory. - A
subdomainpackage orsubdomain.pyin the current directory. src/*/domain.py, the layout thatprotean newcreates.src/*/subdomain.py.
A folder counts as a package only when it has an __init__.py.
When it finds a file under src/ in a package folder that has an
__init__.py, as protean new creates it, the command adds src to the
import path and imports the file under its package name, such as
demo.domain. A domain.py under src/ wins over a subdomain.py under
src/. When more than one src/*/domain.py matches, or more than one
src/*/subdomain.py matches and there is no src/*/domain.py, the command
stops with an error that lists every match. Pass --domain to choose one.
--domain . uses the same order.
When nothing matches and no path is given at all, not even ., the command
also tries to import a module named domain from the import path.
--domain auth
The command imports the module you name, here auth, and detects the domain
instance in it (domain or subdomain).
Note
--domain has three parts: an optional folder, a Python file or dotted
import path, and an optional variable name of the instance. The command
adds the folder to the import path. The following values demonstrate these
parts:
-
--domain src/authWhensrchas no__init__.py, addssrcto the import path and importsauth. -
--domain auth.domainAdds the current directory to the import path and importsauth.domain. -
--domain auth:ssoUses thessoProtean instance inauth.
If --domain is not set, the command looks for a domain module,
then a subdomain module, in the current directory, then for
src/*/domain.py, then for src/*/subdomain.py, as listed above.
Within the module it imports, the command looks for a domain instance
named domain or subdomain, then for any domain instance.