I am running Pants from sources (latest checkout a...
# development
f
I am running Pants from sources (latest checkout as of today) in a local repo as per https://www.pantsbuild.org/v2.12/docs/running-pants-from-sources.
Copy code
$ ./pants_from_sources version
2.13.0.dev2
The repo is currently on
2.10.0
and has all tests/packaging workflows running fine. When I attempt to run tests using Pants built from sources, I get
Copy code
$ ./pants_from_sources test project::
16:08:14.71 [ERROR] 1 Exception encountered:

  ResolveError: 'pymysql' was not found in namespace ''. Did you mean one of:
  :my-project

FATAL: exception not rethrown
Aborted (core dumped)
I am confused by this error message.
My test target:
Copy code
python_tests(
    name="project_tests",
    dependencies=[
        ":testdata",
        ...<redacted>",
        "//:pymysql",  # Imported dynamically by sqlalchemy
    ],
    sources=[
        "project/tests/**/test_*.py",
        ...<redacted>...
    ],
)
Where the root
BUILD
is
Copy code
$ cat BUILD 
python_requirements(name="my-project",
    module_mapping={
        "PyMySQL": ["pymysql"],
        "protobuf": ["google"],
        ...<redacted>...
        "python-geohash": ["geohash"],
    },
)
I had to give the root target a name, after seeing:
Copy code
$ ./pants_from_sources test project::
15:33:47.43 [ERROR] 1 Exception encountered:

  MappingError: Failed to parse ./BUILD:
Targets in root-level BUILD files must be named explicitly.
Docs don’t mention this yet https://www.pantsbuild.org/v2.12/docs/reference-python_requirements, but the sources were helpful.
h
what version were you using before? this is probably the deprecation from "context-aware object factories" to target generators
f
2.10.0
is what we use
h
did you have
use_deprecated_python_macros
set?
f
nope
h
k so in 2.10, it defaults to still using the old macros. 2.11 changes the default to stop using it. 2.12 entirely removes the old macros so you need to handle that deprecation, ideally while you are on stable 2.10 first
you don't get a warning message in 2.10 w/ instructions? are you using
pants_ignore
? (use
--no-pantsd
to force the warning to re-render)
f
hm, so in my dependencies,
"//:pymysql"
what will this become? I still need
python_requirements
with
module_mapping
and I have already gave it a name.
perhaps I just need to address the dependency with the right path
you don’t get a warning message in 2.10 w/ instructions? are you using
pants_ignore
?
I did ignore those and have noticed now, thanks for this.
so my problem is then how to address
Copy code
ResolveError: 'pymysql' was not found in namespace ''. Did you mean one of:
  :my-project
h
so you will want to follow the instructions precisely on 2.10 and have
use_deprecated_python_macros = false
. Land that, before trying to use 2.12
follow the instructions precisely
There are a few steps involved, unfortunately. And it's an "atomic change" - in-betwen states don't work. You have to do it all in one swoop
f
gotcha! Just ran
./pants update-build-files --fix-python-macros
and it has produced about a 100 error messages for the same file, just FYI:
Copy code
* `python_requirements` in BUILD: add `name="reqs"
18:09:43.05 [ERROR] You must manually add the `name=` field to the following targets. This is not done automatically by the `update-build-files` goal.

  * `python_requirements` in BUILD: add `name="reqs"
18:09:43.06 [ERROR] You must manually add the `name=` field to the following targets. This is not done automatically by the `update-build-files` goal.

  * `python_requirements` in BUILD: add `name="reqs"
18:09:43.06 [ERROR] You must manually add the `name=` field to the following targets. This is not done automatically by the `update-build-files` goal.
But all looks good, I’ve made manual change (one file only).
h
oh oops, sorry we don't de-duplicate that
f
Do you want me to file a ticket in GitHub for this?
h
Sure, thanks
f