Hi all, I’m having some issues with running pants...
# general
d
Hi all, I’m having some issues with running pants in CI that I can’t reproduce locally. I’ve managed to reduce the issue down to something simpler, but I’m unsure how to proceed I have a file called
lib/platform/tests/test_advice_models.py
which imports from
lib.business_rules
Copy code
import lib.business_rules  # noqa


def test_thing():
    assert 1 == 1
Running this locally, everything works completely fine
Copy code
$ ./pants test --force lib/platform/tests/test_advice_models.py
15:51:25.09 [INFO] Completed: Run Pytest - lib/platform/tests/test_advice_models.py - succeeded.
Partition: platform

✓ lib/platform/tests/test_advice_models.py succeeded in 0.85s.
But running the same test in CI gives an error
Copy code
==================================== ERRORS ====================================
__________ ERROR collecting lib/platform/tests/test_advice_models.py ___________
ImportError while importing test module '/tmp/pants-sandbox-5gjBP7/lib/platform/tests/test_advice_models.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
lib/platform/tests/test_advice_models.py:1: in <module>
    import lib.business_rules  # noqa
E   ModuleNotFoundError: No module named 'lib.business_rules'
My GH action is invoking the exact test file (the same way I would run locally)
Copy code
jobs:
  build_and_test_python:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.9]
    steps:
    - uses: actions/checkout@v3
    - uses: pantsbuild/actions/init-pants@v2
    - name: Test
      run: |
        ./pants test lib/platform/tests/test_advice_models.py
      if: always()  # We want the log even on failures.
Checking the output of
Copy code
./pants dependencies --transitive lib/platform/tests/test_advice_models.py
Includes things in
lib.business_rules
so unsure why CI is unable to find this module
Copy code
lib/business_rules/__init__.py
lib/business_rules/engine.py
lib/business_rules/operators.py
It’s a long shot (apologies), but any idea how I could begin to debug what’s going on here? (I’m on pants 2.15.0rc2 )
1
c
double and tripple checked there are no files lingering locally that is not checked into git?
(I’ve made that mistake more than once 😛 )
differences in pants config when running on CI (like a pants.ci.toml file) or so?
d
That’s good advice, I’ve just double checked again. I can see the module on the branch on the remote repo. I don’t have a
pants.ci.toml
I can see this in the job
Copy code
Run if [ "${PANTS_CONFIG_FILES}" == "DEFAULT" ]; then
NOT setting PANTS_CONFIG_FILES by default
because pants.ci.toml does not exist.
Run ./pants --version
What’s interesting is I just noticed
Copy code
16:07:06.45 [WARN] Pants cannot infer owners for the following imports in the target lib/auth/tests/test_thing.py:
  * lib.business_rules (line: 1)
But I don’t see this same message when running
Copy code
./pants --no-pantsd test --force --debug lib/platform/tests/test_advice_models.py
c
perhaps
./pants peek
at various files and targets can help shed a light on what may be wrong..?
d
Copy code
$ ./pants peek lib/platform/tests/test_advice_models.py
[
  {
    "address": "lib/platform/tests/test_advice_models.py",
    "target_type": "python_test",
    "batch_compatibility_tag": "platform",
    "dependencies": [
      "lib/business_rules/__init__.py",
      "lib/platform/__init__.py",
      "lib/platform/tests/conftest.py:test_utils"
    ],
So I can see
lib/business_rules
in here 🤔 I’ll throw the same command in CI and see what happens.
e
Are you on a lovely Mac with case insensitive filesystem and lowercase in reality
build
file? CI Linux won't recognize those. They must be
BUILD
.
d
okay this is an embarrassing one 🙈
Copy code
$ git status --ignored lib/business_rules
On branch pants-migration
Your branch is up to date with 'origin/pants-migration'.

Ignored files:
  (use "git add -f <file>..." to include in what will be committed)
	lib/business_rules/.coverage
	lib/business_rules/.pytest_cache/
	lib/business_rules/BUILD
	lib/business_rules/tests/BUILD
It looks like I’d at some point gitignored the build files in
lib/business_rules
🤦‍♂️ But thanks for the pointer for checking the build files!
h
I wish I could have been a fly on the wall at every meeting where filesystem designers decided to make paths case-insensitive.
Or rather a murder hornet on the wall.
d
Indeed
lib/business_rules
had it’s own
.gitignore
file:
Copy code
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
Which was blocking the
BUILD
files 🤦‍♂️
😑 1
c
good find 👍 (and thanks for being transparent, not a fan of cliffhangers 😄 )