https://pantsbuild.org/ logo
#general
Title
# general
g

gentle-sugar-52379

09/21/2022, 12:44 PM
after some searching in the repo i was able to use
run_in_sandbox=False
in my pex_binary
Copy code
pex_binary(
    name="manage_dev",
    entry_point="manage.py",
    run_in_sandbox=False,
    restartable=True,
    dependencies=[":deps", ":reqs_dev"],
)
but its not documented i believe? https://www.pantsbuild.org/docs/reference-pex_binary
1
r

refined-addition-53644

09/21/2022, 1:06 PM
what does this option do?
g

gentle-sugar-52379

09/21/2022, 1:09 PM
b

bitter-ability-32190

09/21/2022, 1:27 PM
In the latest version, you can now run a python_source and configure a field for sandbox or not. The PEX binary is run just as a built pex
Eventually the default will likely be to run in-repo, with opt-in sandbox.
g

gentle-sugar-52379

09/21/2022, 2:45 PM
but if i use it as documented in python_sources, it does not work and throws an exception if i use it as not documented in pex_binary, it works
b

bitter-ability-32190

09/21/2022, 2:46 PM
It's helpful if you share the exception 😛 Also, it all depends on your Pants version. Your link is using 2.13.
g

gentle-sugar-52379

09/21/2022, 2:50 PM
docs for 2.14 shows no "run_in_sandbox" option. but its definetly doing the right thing: https://www.pantsbuild.org/v2.14/docs/reference-pex_binary
b

bitter-ability-32190

09/21/2022, 2:52 PM
Are you using 2.14? https://github.com/pantsbuild/pants/blob/2.14.x/src/python/pants/backend/python/target_types.py#L638 shows that in 2.14, there is no
run_in_sandbox
field on the
pex_binary
target.
g

gentle-sugar-52379

09/21/2022, 2:52 PM
and if i specify "run_goal_use_sandbox=False" in python_source we get an exception:
Copy code
InvalidFieldException: Unrecognized field `run_goal_use_sandbox=False` in target src/fings:deps. Valid fields for the target type `python_sources`: ['dependencies', 'description', 'interpreter_constraints', 'overrides', 'resolve', 'sources', 'tags'].
yes, im using 2.14
and thats the reason why i think its not documented
its in the source
and its working
you get my point?
b

bitter-ability-32190

09/21/2022, 2:53 PM
What's your exact version?
g

gentle-sugar-52379

09/21/2022, 2:53 PM
pants_version = "2.14.0.dev"
b

bitter-ability-32190

09/21/2022, 2:54 PM
https://github.com/pantsbuild/pants/pull/15849 The change was first seen in
a0
. FYI I think 2.14 is on
rc1
now: https://pypi.org/project/pantsbuild.pants/2.14.0rc1/
Also, it's good to note our reference docs are generated from the source code (minus a potential lag if we haven't generated docs in a while). So ideally, it's rare options/subsystems/targets/fields and the like go undocumented 🎉
g

gentle-sugar-52379

09/21/2022, 3:04 PM
ok, that was the missing link: x.x.x.dev != newest now its working exactly like documented 🙂
🙌 1
b

bitter-ability-32190

09/21/2022, 3:04 PM
Don't forget the global default if you wanna invert the current default's behavior: https://www.pantsbuild.org/docs/reference-python#default_run_goal_use_sandbox
g

gentle-sugar-52379

09/21/2022, 3:22 PM
but now with the 2.14.0rc1 versions
python_sources(run_goal_use_sandbox=False)
djangos makemigrations is not finding any changed models. with 2.14.0dev0 versions
pex_binary(run_in_sandbox=False)
works as expected after a change on one model
b

bitter-ability-32190

09/21/2022, 3:24 PM
Do you also have a
pex_binary
with the
entry_point
set to the
python_source
? If so, in order to not break backwards compatibility
./pants run
picks the
pex_binary
over the
python_source
. To fix this, you can either pass
--filter-target-type=python_source
or set https://www.pantsbuild.org/docs/reference-global#use_deprecated_pex_binary_run_semantics to
false
(FWIW this change also means you can potentially get rid of
pex_binary
targets that exists solely for
run
and aren't intended to be packaged)
g

gentle-sugar-52379

09/21/2022, 4:01 PM
ok, i think that was another missing link. thx a lot 🙂 if i understand everything you said this should be my solution to this django quir awesomenes 😄
Copy code
python_requirements(
    name="reqs_prod",
)

python_requirements(
    name="reqs_dev",
    source="requirements.dev.txt",
)

python_sources(
    name="src",
    dependencies=[
        "src/fings/base",
        "src/fings/app",
        "src/fings/listing",
        "src/tuhls/core",
        "src/tuhls/dashboard",
        "src/tuhls/icons",
        ":reqs_prod",
        "src/css",
    ],
)

python_source(
    name="manage_dev",
    source="manage.py",
    run_goal_use_sandbox=False,
    dependencies=[":src", ":reqs_dev"],
)

pex_binary(
    name="manage_prod",
    entry_point="manage.py",
    restartable=True,
    dependencies=[":src"],
)
im now able to run manage.py with my dev dependencies via `./pants run src/fings:manage_dev -- makemigrations`` and its working as expected
b

bitter-ability-32190

09/21/2022, 4:04 PM
Do you need to package
manage.py
? otherwise you can remove the
pex_binary
😉
g

gentle-sugar-52379

09/21/2022, 4:08 PM
atm, yes, i think so. we have to run migrations, collect the static files and so on, on application startup
b

bitter-ability-32190

09/21/2022, 4:09 PM
Just wanted to double-check 🙂