https://pantsbuild.org/ logo
c

clean-morning-70173

10/15/2021, 10:32 PM
I'm inhering a python project with pants 1.30.1. And I'm a Node.js developer... So, long story short. I want to add a new python module, I've added it in the requirements.txt, but now I don't know how to make pants "add" that module. When does that happen?
2021-10-15-17-23-03-screenshot.png
I've added a module in there, in requirements.txt
but now I get
Copy code
ResolveError: "ppretty" was not found in namespace "src/python/3rdparty/python". Did you mean one of:
I've added it into the submodule's BUILD file
Copy code
python_library(
  name='lib',
  sources=['*.py'],
  dependencies=[
    'src/python/libwarp:lib',
    'src/python/version:lib',
    'src/python/3rdparty/python:flask',
    'src/python/3rdparty/python:flask-restful',
    'src/python/3rdparty/python:singleton-decorator',
    'src/python/3rdparty/python:expiringdict',
    'src/python/3rdparty/python:gevent',
    'src/python/3rdparty/python:gevent-websocket',
    'src/python/3rdparty/python:werkzeug',
    'src/python/3rdparty/python:daemonize',
    'src/python/3rdparty/python:tinydb',
    'src/python/3rdparty/python:lz4',
    'src/python/3rdparty/python:ppretty'
  ],
  compatibility='CPython>=2.7,<3',
)
is this the way I should do it?
h

hundreds-father-404

10/15/2021, 10:35 PM
Hey Luis, welcome! That all looks right. To double check, what requirement string did you add to
requirements.txt
?
c

clean-morning-70173

10/15/2021, 10:35 PM
Copy code
ansicolors==1.0.2
mock==2.0.0
six>=1.11.0
munch>=2.3.0
pyyaml>=3.12
click>=6.7
fabric==1.14.0
paramiko==2.7.2
tzlocal==1.4
flask>=1.0.2
flask_restful>=0.3.6
singleton_decorator>=1.0.0
expiringdict>=1.1.4
requests==2.18.4
tabulate==0.8.2
gevent>=1.3.6
gevent-websocket>=0.10
werkzeug>=0.14
sshtunnel>=0.1.4
daemonize==2.4.6
progress==1.4
tinydb>=3.12.0
mypolr==1.3.10
PyQRCode==1.2.1
pypng==0.0.18
lz4==2.1.2
ppretty==1.3
The last one
h

hundreds-father-404

10/15/2021, 10:35 PM
Also pardon the verbosity of having to manually edit BUILD files...that goes away in Pants 2.0+ with dependency inference https://blog.pantsbuild.org/dependency-inference/
c

clean-morning-70173

10/15/2021, 10:36 PM
How does pants "detect" there is a new dependency? In node.js I'd run
npm install
and it would update... trying to find the "equivalent" if it's even needed
h

hundreds-father-404

10/15/2021, 10:36 PM
Hmm, can you please try again with
--no-pantsd
this time?
c

clean-morning-70173

10/15/2021, 10:36 PM
Yeah, I read about that but for now I just need to get this to work before doing a whole refactor
βž• 1
Copy code
./pants test.pytest --no-pantsd --test-pytest-fail-fast --test-pytest-level=debug src/python/libwarp:tests src/python/libwarp/helpers:tests src/python/warpdrive:tests
22:37:16 [ERROR] Unrecognized command line flag '--no-pantsd' on scope 'test.pytest'.

(Run `./pants help-advanced test.pytest` for all available options.)

(Use --print-exception-stacktrace to see more error details.)
Seems like it's an option that is not available
Copy code
./pants --version                                                                                                                                                                                                                                                        [Β±pants-update ● bc53735 Add .cache as a direct]
1.30.1
h

hundreds-father-404

10/15/2021, 10:38 PM
./pants --no-pantsd test.pytest --test-pytest-fail-fast --test-pytest-level=debug src/python/libwarp:tests src/python/libwarp/helpers:tests src/python/warpdrive:tests
i.e. with
--no-pantsd
at the front
πŸ‘ 1
c

clean-morning-70173

10/15/2021, 10:38 PM
I see! I'll try again
It's running the tests...
and now it worked! what does
pantsd
do?
(I mean, it worked that it run the test and it failed the test, but it did actually "use" my new module, thanks!)
h

hundreds-father-404

10/15/2021, 10:40 PM
(fyi that's because there is a shorthand that
./pants test --option path/to:tgt
==
./pants test --test-option path/to:tgt
. So, your original command was thinking you meant the option
--no-test-pantsd
, which doesn't exist)
Okay yay to fixing, apologies to this being an issue, though. Pantsd is the Pants daemon, which keeps the results of prior runs in-memory to make Pants a lot faster Generally, works great. A huge broken window though is that it was not correclty detecting changes to requirements.txt until pantsd was restarted. Not at all intuitive πŸ˜” You can workaround this by adding this to
GLOBAL
section in `pants.toml`:
Copy code
# Work around for <https://github.com/pantsbuild/pants/issues/7022>
pantsd_invalidation_globs.add = ["**/requirements.txt"]
c

clean-morning-70173

10/15/2021, 10:43 PM
Oh, nice πŸ™‚ I'll add that
hopefully after I make it work I'll do a refactor to 2.x
❀️ 1
and will be in a better world πŸ™‚
h

happy-kitchen-89482

10/15/2021, 10:44 PM
πŸ™‚
c

clean-morning-70173

10/15/2021, 10:46 PM
Thank you for your help! you will certainly see me around with more Noob questions
h

hundreds-father-404

10/15/2021, 10:48 PM
Feedback from newer users is some of the most valuable feedback we ever get. We are really focused on making Pants ergonomic and intuitive to use. To do that, it's super helpful hearing what newcomers think and their mental model, as they don't yet suffer from The Curse of Knowledge https://en.wikipedia.org/wiki/Curse_of_knowledge So, please do ask questions! And let us know if we can help at all with the upgrade to Pants 2.0 πŸ™‚ https://www.pantsbuild.org/v2.0/docs/how-to-upgrade-pants-2-0 has a migration guide too
πŸ’― 1
4 Views