plain-carpet-73994
02/22/2023, 12:50 AMrequirements.txt is neptune-client so I need a module_mapping to let Pants know it gets imported as just neptune
⢠The package fails to declare its dependency on setuptools so I need to add that via a python_requirements
Somehow these two aren't playing nicely together. Here's what I have:
python_requirement(
name="setuptools",
requirements=["setuptools"],
)
python_requirement(
name="neptune-client",
requirements=["neptune-client"],
dependencies=[":setuptools"],
)
# Module mappings, etc.
python_requirements(
name='reqs',
module_mapping={
...
':neptune-client': ['neptune'],
},
)
I've tried a bunch of variations like having the python_requirement have its requirements come after the module mapping bit, having the module mapping be from neptune-client without the leading :, etc. and every combination ends up with an error, though the errors change as I blindly throw things at the wall hoping something will stick.
Guidance would be much appreciated!broad-processor-92400
02/22/2023, 12:53 AMrequirements.txt that python_requirements is loading? Does this also include neptune-client?plain-carpet-73994
02/22/2023, 12:53 AMrequirements.txtplain-carpet-73994
02/22/2023, 12:54 AM[python.resolves]
default = "3rdparty/python/default.lock"plain-carpet-73994
02/22/2023, 12:54 AMbroad-processor-92400
02/22/2023, 12:57 AMpython_requirements, and not have the separate `python_requirement`s. As it is, I think you'll be (trying) to declare duplicate dependencies, that is, have neptune-client loaded into your Pants resolve twice.
If setuptools is in the requirements.txt , you might do something what we do:
python_requirements(
name="reqs",
overrides={
"neptune-client": {"dependencies": ["reqs#setuptools"]},
},
module_mapping={
"neptune-client": ["neptune"],
},
)plain-carpet-73994
02/22/2023, 12:57 AMmodules= to the python_requirement to say that neptune-client provides the neptune module and then removed it from the module_mappings bit. I think that's working (my unit test is failing but I think now it's bad code šbroad-processor-92400
02/22/2023, 12:58 AMpython_requirement for neptune-client (the python_requirements target is a helper that generates the "real" python_requirement s from a file)plain-carpet-73994
02/22/2023, 12:59 AMpython_requirement(
name="neptune-client",
requirements=["neptune-client"],
dependencies=[":setuptools"],
modules=['neptune', 'neptune.new'],
)
python_requirements(
name='reqs',
module_mapping={
# neptune/neptune-client no longer appear in here
},
)plain-carpet-73994
02/22/2023, 1:00 AMbroad-processor-92400
02/22/2023, 1:00 AMneptune-client appear in the separate requirements.txt file that python_requirements is loading?plain-carpet-73994
02/22/2023, 1:00 AMplain-carpet-73994
02/22/2023, 1:01 AMplain-carpet-73994
02/22/2023, 1:03 AMbroad-processor-92400
02/22/2023, 1:04 AMpython_requirement , and once for the python_requirement that's automatically generated by python_requirements. This may cause problems in future.
So, options:
1. remove neptune-client from requirements.txt, so that you've only got the manual python_requirement
2. remove the manual python_requirement and use the overrides and module-mapping as I demonstrate above
Either way will appear in the Pants lockfile. I'd probably encourage option 2, so that dependencies are (mostly) in one place.
(You could even put setuptools into the requirements.txt too, and avoid the manual python_requirement for it.)plain-carpet-73994
02/22/2023, 1:05 AMplain-carpet-73994
02/22/2023, 1:08 AMbroad-processor-92400
02/22/2023, 1:09 AM./pants list path/to/targets: to see the names of the targets being generated to be able to refer to them correctly. (path/to/targets is the directory of the BUILD file with these contents. if it's the root, ./pants list //: , I think)plain-carpet-73994
02/22/2023, 1:09 AMpython_requirement(
name="setuptools",
requirements=["setuptools"],
)
python_requirements(
name='reqs',
module_mapping={
...
'neptune-client': ['neptune'],
},
overrides = {
'neptune-client': {
'dependencies': 'reqs#setuptools',
}
},
)
I get:
AddressParseException: Failed to parse address spec `#`: error at 1:2: expected a non-empty generated target name to follow a `#`.plain-carpet-73994
02/22/2023, 1:09 AMsetuptools isn't in my requirements.txt (though I'm starting to think it should be).broad-processor-92400
02/22/2023, 1:10 AM:setuptools should workbroad-processor-92400
02/22/2023, 1:10 AMplain-carpet-73994
02/22/2023, 1:11 AM:setuptools) and got:
UnsupportedWildcardError: The address `:` from the `dependencies` field from the target //:reqs#neptune-client ended in a wildcard (`:`), which is not supported.plain-carpet-73994
02/22/2023, 1:11 AMbroad-processor-92400
02/22/2023, 1:11 AMsetuptools: (: at the end); it should be :setuptools at the startplain-carpet-73994
02/22/2023, 1:13 AMbroad-processor-92400
02/22/2023, 1:13 AMplain-carpet-73994
02/22/2023, 1:14 AMMappingError: Failed to parse ./BUILD:
expression cannot contain assignment, perhaps you meant "=="? (<string>, line 9)
line 9 is:
overrides={plain-carpet-73994
02/22/2023, 1:15 AMoverrides={
'neptune-client': { 'dependencies': 'reqs#setuptools' }
}broad-processor-92400
02/22/2023, 1:15 AMbroad-processor-92400
02/22/2023, 1:16 AMplain-carpet-73994
02/22/2023, 1:16 AMpython_requirements(
name='reqs',
module_mapping={
'pyyaml': ['yaml'],
'Pillow': ['PIL'],
'imageio': ['imageio.v3'],
'neptune-client': ['neptune'],
},
overrides={
'neptune-client': { 'dependencies': 'reqs#setuptools' }
'torchmetrics': { 'dependencies': 'reqs#setuptools' },
},
type_stubs_module_mapping={
'types-PyYAML': ['yaml'],
'types-Pillow': ['PIL'],
}
)plain-carpet-73994
02/22/2023, 1:17 AM, on the next line (line 10) after the neptune-client override.plain-carpet-73994
02/22/2023, 1:18 AMplain-carpet-73994
02/22/2023, 1:22 AMAddressParseException: Failed to parse address spec `#`: error at 1:2: expected a non-empty generated target name to follow a `#`.
Full contents of `BUILD`:
python_requirements(
name='reqs',
module_mapping={
'pyyaml': ['yaml'],
'Pillow': ['PIL'],
'imageio': ['imageio.v3'],
'neptune-client': ['neptune'],
},
overrides={
'neptune-client': { 'dependencies': 'reqs#setuptools' },
},
type_stubs_module_mapping={
'types-PyYAML': ['yaml'],
'types-Pillow': ['PIL'],
}
)broad-processor-92400
02/22/2023, 1:23 AM./pants list is a good way for you to understand what's being generated: https://pantsbuild.slack.com/archives/C046T6T9U/p1677028145118729?thread_ts=1677027041.399219&cid=C046T6T9U
Let me know if you have questions about the outputbroad-processor-92400
02/22/2023, 1:24 AMplain-carpet-73994
02/22/2023, 1:24 AM$ ./pants list //:
...
//:reqs#neptune-client
...
//:reqs#setuptools
...plain-carpet-73994
02/22/2023, 1:25 AM: was bad. Maybe I need the full //: prefix. Trying that.plain-carpet-73994
02/22/2023, 1:25 AM//: either.plain-carpet-73994
02/22/2023, 1:26 AMStandard debugging technique as well: make the feedback cycle shorter. E.g. commenting out the irrelevant parts of the requirements.txt (like pytorch) should help make iterating on just this bit faster.Makes sense but I think that'd actually take longer; I have a big mono-repo with a lot of interdependencies. Figuring out what subset of those, transitively, are releant to this seems hard...
plain-carpet-73994
02/22/2023, 1:27 AM'neptune-client': { 'dependencies': '//:reqs#setuptools' },
'neptune-client': { 'dependencies': ':reqs#setuptools' },
'neptune-client': { 'dependencies': 'reqs#setuptools' },
All result in different errors. Output of pants list would seem to imply that one of those is correct.broad-processor-92400
02/22/2023, 1:28 AMneptune-client, and thus only neptune-client and setuptools are relevant. Once that's set up right, you can uncomment everything to see if test passing etc.broad-processor-92400
02/22/2023, 1:29 AMneptune-client and setuptools ?plain-carpet-73994
02/22/2023, 1:31 AMplain-carpet-73994
02/22/2023, 1:32 AMpants test fails:
$ ./pants test src/ml_logger/neptune/::
17:32:28.12 [ERROR] 1 Exception encountered:
InvalidSpecPathError: Invalid address / from the `dependencies` field from the target //:reqs#neptune-client. Cannot use absolute paths.plain-carpet-73994
02/22/2023, 1:33 AMpants test fails with all 3 variants of the address of setuptools above (no prefix, : prefix, //: prefix).plain-carpet-73994
02/22/2023, 1:34 AMreqs is referring to itself here? That is, our main dependency block is reqs but we're then using that in the overrides block in that target.plain-carpet-73994
02/22/2023, 1:35 AMplain-carpet-73994
02/22/2023, 1:41 AM./pants generate-lockfiles works fine but ./pants test does not. I'm getting those syntax errors from the latter but not the former.plain-carpet-73994
02/22/2023, 1:45 AM'neptune-client': { 'dependencies': 'reqs#setuptools' },
It needs to be:
'neptune-client': { 'dependencies': ['reqs#setuptools'] },
That is, the dependencies are a list. If not, it treats the string as an iterable and it's trying to resolve r, e, q, #, etc. But pants test does that while generate-lockfiles does not.broad-processor-92400
02/22/2023, 1:54 AMBTW: i'm guessing you're a pants employee and it's past the end of your workday. If you want to pick this up tomorrow that's totally understandable.I'm just a random person from Australia, not employed by Toolchain š
plain-carpet-73994
02/22/2023, 1:54 AMbroad-processor-92400
02/24/2023, 3:48 AMplain-carpet-73994
02/24/2023, 6:14 PM