handsome-sunset-98068
08/24/2022, 2:45 PM./pants run projects/appsflyer/:manage -- createsuperuser
throws:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
my settings.py file:
...
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '<database_name>',
'USER': '<database_username>',
'PASSWORD': '<password>',
'HOST': '<database_hostname_or_ip>',
'PORT': '<database_port>',
}
}
BUILD
python_sources()
resource(
name="env",
source=".env"
)
pex_binary(
name="manage",
entry_point="manage.py",
dependencies=[
"./appsflyer:appsflyer",
":env"
],
restartable=True
)
enough-analyst-54434
08/24/2022, 2:47 PMimport ...
or from ... import ...
(and some weirder cases), but it is not magic. If the settings aren't imported by your code, you may need to add a manual dependency.enough-analyst-54434
08/24/2022, 2:48 PMenough-analyst-54434
08/24/2022, 2:50 PM./pants filedeps --transitive ./appsflyer:appsflyer
show it owning the settings.py
file you expect?enough-analyst-54434
08/24/2022, 2:59 PMdjango.db.backends.postgresql
in the ENGINE valiue. That is effectively a magic import.enough-analyst-54434
08/24/2022, 2:59 PMenough-analyst-54434
08/24/2022, 3:01 PMpsycopg2
enough-analyst-54434
08/24/2022, 3:02 PMhappy-kitchen-89482
08/24/2022, 3:45 PMhappy-kitchen-89482
08/24/2022, 3:46 PMhappy-kitchen-89482
08/24/2022, 3:46 PMhandsome-sunset-98068
08/24/2022, 4:45 PM./pants filedeps --transitive ./appsflyer:appsflyer
and settings.py was not there.
I tried adding a new source in projects/appsflyer/appsflyer/BUILD (this dir has settings.py)
python_sources()
python_source(
name="settings",
source="settings.py",
)
Then added that as dependency in the projects/appsflyer/BUILD (this dir has manage.py)
python_sources()
resource(
name="env",
source=".env"
)
pex_binary(
name="manage",
entry_point="manage.py",
dependencies=[
"./appsflyer:appsflyer",
":env",
"./appsflyer:settings",
],
restartable=True
)
But this doesn't add the settings.py as filedep in the toplevel appsflyer. How to do that?refined-addition-53644
08/24/2022, 4:51 PMpython_sources
dependencies inside appsflyer
on :settings
This way you don’t need to explicitly mention it outside of the directory appsflyer
handsome-sunset-98068
08/24/2022, 4:59 PMrefined-addition-53644
08/24/2022, 5:10 PMpython_sources(dependencies=[":settings"])
python_source(
name="settings",
source="settings.py",
)
then your other projects/appsflyer/BUILD
python_sources()
resource(
name="env",
source=".env"
)
pex_binary(
name="manage",
entry_point="manage.py",
dependencies=[
"./appsflyer:appsflyer",
":env",
],
restartable=True
)
Also I don’t think you need to put an explicit dependency inside pex_binary
on ./appsflyer:appsflyer
. Pants will be able to infer the implicit dependency as long as you import the code from appsflyer somewhere inside manage.py
.handsome-sunset-98068
08/24/2022, 5:22 PM> ./pants filedeps --transitive projects/appsflyer:appsflyer
BUILD
projects/appsflyer/BUILD
projects/appsflyer/manage.py
pyproject.toml
and even without adding the :settings target dependency I get settings.py in sources.
> ./pants list projects/appsflyer/appsflyer/:
projects/appsflyer/appsflyer:appsflyer
projects/appsflyer/appsflyer/__init__.py
projects/appsflyer/appsflyer/asgi.py
projects/appsflyer/appsflyer/settings.py
projects/appsflyer/appsflyer/urls.py
projects/appsflyer/appsflyer/wsgi.py
And what does not having settings.py in filedep mean. We also don't have urls.py and wsgi.py in filedeps.refined-addition-53644
08/24/2022, 5:25 PM./pants dependencies --transitive projects/appsflyer:appsflyer
https://www.pantsbuild.org/docs/project-introspection#dependencies---find-a-targets-dependencies
filedeps
outputs all of the files belonging to a target, based on its sources
field.
I would read this a bit
https://www.pantsbuild.org/docs/project-introspectionrefined-addition-53644
08/24/2022, 5:28 PMhandsome-sunset-98068
08/24/2022, 6:00 PM> ./pants dependencies --transitive projects/appsflyer:appsflyer
//:poetry#Django
//pyproject.toml:poetry
projects/appsflyer/manage.py
btw what should I expect here?
moreover, I see settings.py here.
> ./pants filedeps --transitive projects/appsflyer:manage
BUILD
projects/appsflyer/.env
projects/appsflyer/BUILD
projects/appsflyer/appsflyer/BUILD
projects/appsflyer/appsflyer/__init__.py
projects/appsflyer/appsflyer/asgi.py
projects/appsflyer/appsflyer/settings.py. <----HERE
projects/appsflyer/appsflyer/urls.py
projects/appsflyer/appsflyer/wsgi.py
projects/appsflyer/manage.py
pyproject.toml
Since the command run is actually
./pants run projects/appsflyer/:manage -- createsuperuser
then why do we check the projects/appsflyer:appsflyer
target?
I feel like I am missing something conceptual here.refined-addition-53644
08/25/2022, 11:32 AMpex_binary
and its dependencies. Whatever I had suggested was for debugging purpose.
I also realised that the python_sources
should automatically include settings.py
inside the projects/appsflyer/appsflyer/BUILD
since it’s just a glob of all *.py
files inside the directory. So creating a settings using python_source
wasn’t needed. At the end it’s pex_binary
which figures out from the universe of all these sources and dependencies what it should package. Hence you do need to provide an explicit dependency on settings.py
based target if pex_binary
can’t figure it out itself.handsome-sunset-98068
08/25/2022, 12:16 PMpython_sources(
dependencies=[
":settings"
]
)
python_source(
name="settings",
source="settings.py",
dependencies=["//:poetry#psycopg2-binary"]
)
Since the error has not even reached the psycopg2 dependency level, it not even able to find the engine value in the first place. So it looks like that even settings.py is not avl for the binary, though the output of the following cmds is:
> ./pants dependencies --transitive projects/appsflyer:manage
//:poetry#Django
//:poetry#apig-wsgi
//:poetry#psycopg2-binary
//:poetry#python-decouple
//pyproject.toml:poetry
projects/appsflyer/appsflyer/__init__.py
projects/appsflyer/appsflyer/asgi.py
projects/appsflyer/appsflyer/settings.py
projects/appsflyer/appsflyer/urls.py
projects/appsflyer/appsflyer/wsgi.py
projects/appsflyer/appsflyer:settings <--- HERE
projects/appsflyer/manage.py
projects/appsflyer:env
> ./pants filedeps --transitive projects/appsflyer:manage
BUILD
projects/appsflyer/.env
projects/appsflyer/BUILD
projects/appsflyer/appsflyer/BUILD
projects/appsflyer/appsflyer/__init__.py
projects/appsflyer/appsflyer/asgi.py
projects/appsflyer/appsflyer/settings.py <--- HERE
projects/appsflyer/appsflyer/urls.py
projects/appsflyer/appsflyer/wsgi.py
projects/appsflyer/manage.py
pyproject.toml
refined-addition-53644
08/25/2022, 2:41 PMpex_binary
refined-addition-53644
08/25/2022, 2:44 PMfrom django.conf import settings
https://docs.djangoproject.com/en/4.0/internals/contributing/writing-code/coding-style/#use-of-django-conf-settingsenough-analyst-54434
08/25/2022, 2:57 PMenough-analyst-54434
08/25/2022, 2:57 PMenough-analyst-54434
08/25/2022, 2:58 PMenough-analyst-54434
08/25/2022, 2:59 PMenough-analyst-54434
08/25/2022, 5:16 PMhandsome-sunset-98068
08/25/2022, 6:21 PM