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

best-xylophone-4755

02/21/2020, 9:33 AM
Hello! I am new to using Pants build. Is there a way to execute pants build on Jenkins? I couldn't find any info for this on the internet. Thanks!
e

enough-analyst-54434

02/21/2020, 5:46 PM
We do have some guidance in https://www.pantsbuild.org/orgs.html in the
Continuous Integration
section. It may be a bit out of date. The main point though is you can run pants just like you'd run any other step in Jenkins. In the example a small bash script is used to coordinate a few pants calls. Since Jenkins can shell out to bash, you can do pretty much anything you can do on your workstation on Jenkins by encoding those steps in a bash script. There are other ways to do this, but I'm mainly pointing out pants is not special in this regard. You just run it like you'd run any other tool without a dedicated Jenkins plugin.
b

best-xylophone-4755

02/22/2020, 5:55 AM
Thanks John 🙂 I am fairly new to Jenkins as well. So once Pants is installed in the Jenkins server, I should be good to go, right?
e

enough-analyst-54434

02/23/2020, 10:01 PM
Right. Although typically Pants is installed by running the
./pants
script checked into a repo if and only if pants is not already installed, so this should work automatically. In other words, if the Jenkins job Pants command is
./pants test ...
and Pants is already installed by a prior run of
./pants
on the worker node, the tests will run. If not, Pants will be installed and then the tests run. See: https://www.pantsbuild.org/install.html
👍 1
b

best-xylophone-4755

02/24/2020, 2:17 PM
I made my sample project, and executed the generated pex file. Got the below error. I tried everything possible using google search results, but couldn't fix it. I'm using Python 3.7 obritto@blr-ml-obritto MonoRepoTest $ ./dist/reaper.hello-app/main.pex Traceback (most recent call last): File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 397, in execute File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 329, in _wrap_coverage File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 360, in _wrap_profiling File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 442, in _execute File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 540, in execute_entry File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/.bootstrap/pex/pex.py", line 547, in execute_module File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 192, in run_module fname, loader, pkg_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/Users/obritto/Documents/GitHub/MonoRepoTest/dist/reaper.hello-app/main.pex/app.py", line 1, in <module> ImportError: No module named reaper.processing
This is the Source Code
The script runs fine when I use python <script_name.py>
Thanks in advance.
e

enough-analyst-54434

02/24/2020, 3:34 PM
From my phone, but Pants is not currently friendly out of the box for typical layout Python projects. It expects python code under src/python. See the Source Roots section here: https://www.pantsbuild.org/setup_repo.html This should get you going:
Copy code
$ git log --stat -1
commit b0c937eaf48493cfe66d28c66667bfd8cd65264b (HEAD -> master)                        Author: John Sirois <john.sirois@gmail.com>                                             Date:   Mon Feb 24 07:26:04 2020 -0800                                                                                                                                              Move under src/python.                                                              
 {common => src/python/common}/BUILD                  | 0                                {common => src/python/common}/__init__.py            | 0                                {common => src/python/common}/utils.py               | 0                                {reaper => src/python/reaper}/BUILD                  | 4 ++--                           {reaper => src/python/reaper}/__init__.py            | 0                                {reaper => src/python/reaper}/app.py                 | 0
 {reaper => src/python/reaper}/processing/BUILD       | 0                                {reaper => src/python/reaper}/processing/__init__.py | 0                                {reaper => src/python/reaper}/processing/add_name.py | 0                                9 files changed, 2 insertions(+), 2 deletions(-)                                       $ git diff HEAD~1                                                                       diff --git a/common/BUILD b/src/python/common/BUILD
similarity index 100%                                                                   rename from common/BUILD                                                                rename to src/python/common/BUILD                                                       diff --git a/common/__init__.py b/src/python/common/__init__.py                         similarity index 100%                                                                   rename from common/__init__.py
rename to src/python/common/__init__.py                                                 diff --git a/common/utils.py b/src/python/common/utils.py                               similarity index 100%                                                                   rename from common/utils.py                                                             rename to src/python/common/utils.py                                                    diff --git a/reaper/BUILD b/src/python/reaper/BUILD                                     similarity index 59%                                                                    rename from reaper/BUILD                                                                rename to src/python/reaper/BUILD                                                       index 4539170..874338b 100644                                                           --- a/reaper/BUILD                                                                      +++ b/src/python/reaper/BUILD                                                           @@ -2,8 +2,8 @@ python_library(name='reaper')                                                                                                                                    python_binary(name='main',
   dependencies=[                                                                       -    'reaper/processing',                                                               -    'common:Common'                                                                    +    'src/python/reaper/processing',                                                    +    'src/python/common:Common'                                                            ],
   source='app.py'                                                                       )                                                                                      diff --git a/reaper/__init__.py b/src/python/reaper/__init__.py                         similarity index 100%                                                                   rename from reaper/__init__.py                                                          rename to src/python/reaper/__init__.py
diff --git a/reaper/app.py b/src/python/reaper/app.py                                   similarity index 100%                                                                   rename from reaper/app.py                                                               rename to src/python/reaper/app.py                                                      diff --git a/reaper/processing/BUILD b/src/python/reaper/processing/BUILD               similarity index 100%                                                                   rename from reaper/processing/BUILD                                                     rename to src/python/reaper/processing/BUILD                                            diff --git a/reaper/processing/__init__.py b/src/python/reaper/processing/__init__.py   similarity index 100%                                                                   rename from reaper/processing/__init__.py                                               rename to src/python/reaper/processing/__init__.py                                      diff --git a/reaper/processing/add_name.py b/src/python/reaper/processing/add_name.py   similarity index 100%                                                                   rename from reaper/processing/add_name.py                                               rename to src/python/reaper/processing/add_name.py                                      $
b

best-xylophone-4755

02/24/2020, 4:28 PM
Thanks, appreciate it!
Below is the structure we want to follow in our Monorepo, where the folder Common has common code(shared code) for folder App1, App2 etc. I'll be thankful if you could suggest something for this use case. I have spent a a month to decide on Pants after reading about - Buck, Bazel and Please. -Common -App1 |--src/python -App2 |--src/python
e

enough-analyst-54434

02/24/2020, 5:38 PM
That layout will work out of the box. Your example zip did not have the
src/python
directories under the app directories.
b

best-xylophone-4755

02/25/2020, 2:53 AM
Thanks 🙂 I will change the code to have have src/python
I still get the import error. Should there be a BUILD file for every folder (src, python,etc.)? Is there something that I'm missing? ./pants binary is creating a pex successfully. Running the pex files is throwing this error.I am running the pex file using "./dist/main.pex". When I executed the script using python /path/to/script.py, it was throwing a similar error, but setting the PYTHONPATH solved the issue, but I am unable to run the .pex file
e

enough-analyst-54434

02/25/2020, 6:37 AM
The error shows a module of
reaper.src.python.processing
which is not right. The import should be of
processing
with no prefix. Your screen shot suggests you're confused by having an incorrect source root in your IDE. You need to right click on the
reaper/src/python
directory in the left hand pane and mark it as a source root. Same for all other
**/src/python
directories.
b

best-xylophone-4755

02/26/2020, 6:40 AM
It works now 🙂
e

enough-analyst-54434

02/26/2020, 7:15 AM
Excellent.
b

best-xylophone-4755

02/26/2020, 7:17 AM
Thank you very much
Copy code
+ ./pants binary reaper/src/python/:main
[31mNo valid Python interpreter found. Pants requires Python 3.6+ to run.[0m
Build step 'Execute shell' marked build as failure
Finished: FAILURE
This is the Jenkins error that I get. How do I solve it?By running it in a docker container with Python 3.6+ installed? Is there a way out without using docker?
5 Views