chilly-jackal-42262
02/07/2024, 11:38 AMpopulate_regions.py file to fill one of the tables from a csv file. Normally the Django command for this would be:
python manage.py populate_regions country_codes_and_regions.csv
Since with the other commands I've been using lines like:
NAME_SQLITE_DB=db.sqlite3 pants run src/sillion/service/modelling:manage -- migrate
I tried something similar (without a lot of hope of this working)
NAME_SQLITE_DB=db.sqlite3 pants run src/sillion/service/modelling:manage -- populate_regions country_codes_and_regions.csv
This presents an unknown commad error.
So trying to understand how the manage.py entry point works in general and how I could run commands such at that one above?
The BUILD file at project level
python_sources(
overrides = {
"settings.py": {
"dependencies": [
"3rdparty/python#django-simple-history",
"3rdparty/python#djangorestframework",
"3rdparty/python#requests-cache",
"//src/Companies",
"//src/User",
"//src/Sources",
"//src/Scenarios",
"//src/Vehicles",
]
}
}
)
pex_binary(
name="manage",
entry_point="manage.py",
layout="packed",
env={
"NAME_DB_SQLITE": "",
}
)
Also what is the significance of having those BUILD files at the app level and the top project level?
Thanks!happy-kitchen-89482
02/07/2024, 2:34 PMhappy-kitchen-89482
02/07/2024, 2:34 PMhappy-kitchen-89482
02/07/2024, 2:36 PMpython manage.py populate_regions works but pants run src/sillion/service/modelling:manage -- populate_regions doesn't then it means that when run under Pants, Django is not "seeing" the Django app that provides the custom "populate_regions" management command.happy-kitchen-89482
02/07/2024, 2:38 PMmanage binary doesn't have an explicit dependency on the python_sources target that provides the settings.pyhappy-kitchen-89482
02/07/2024, 2:38 PMhappy-kitchen-89482
02/07/2024, 2:39 PM"dependencies": [":modelling"] I thinkchilly-jackal-42262
02/07/2024, 3:39 PMpex_binary(
name="manage",
entry_point="manage.py",
dependencies=["src/Vehicles/management/commands/populate_regions.py"],
layout="packed",
env={
"NAME_DB_SQLITE": "",
}
)
So kinda had to direct right up until the .py file otherwise the command not found error persists.
after this change could run
NAME_SQLITE_DB=db.sqlite3 pants run src/sillion/service/modelling:manage -- populate_regions country_codes_and_regions.csv
The table is updated exactly as expected 🙂happy-kitchen-89482
02/07/2024, 7:31 PM