Hello, I'm facing an issue where I need to run Nos...
# plugins
a
Hello, I'm facing an issue where I need to run Nose instead of Pytest on a >=CPython3.10 codebase. I think I've got the plugin to a decent state, but now am encountering errors running it because it's running on 3.9. I'm guessing this has something to do with how I specify interpreter constraints. I've relaxed my own resolves to 3.9 but that leads to syntax errors, but I obviously can't lift pants-plugins resolve to 3.10 (or can I?). Any suggestions on an approach would be appreciated.
w
What's your pants.toml look like? Your plugin needs to be python3.9, but the source code should be fine as whatever
You're running nose as an in-repo plugin?
a
pants.toml
You're running nose as an in-repo plugin?
Yep
w
So, default is resolved as python3.9 and your interpreter_constraints are 3.9? So, you need those interpreter constraints (and I would guess
python-default
as py3.10, right?
a
Our codebase is a 3.10 minimum
but if I set the interpreter constraints on python-default to 3.10+ there is a generate-lockfiles error on a dependency
Is it the way I'm building the PEXes that's wrong?
w
What's the error? Do the interpreter_constraints match the resolve?
My assumption would be that everything would be 3.10+ and then, you carve out the in-repo plugin as it's own thing, targeting 3.9
a
Right that's where I started. It's something like the wheel tag that gets downloaded for one of my deps (maybe more?) doesn't include py39, which the plugin needs
I can try to re-run and paste the error in that case if it helps
w
Yeah, the error would definitely help - and the plugin is in a separate resolve, right? So, it should be in isolation more or less (and maybe you'd need to override the plugin's interpreter constraints too)
a
The plugin is in a separate resolve yes
w
Send over the error, I'm gonna try to find an inrepo plugin example and set that up to use two sets of constraints if I can
šŸ™ 1
a
Thank you - waiting on lockfile generation to finish
w
šŸ‘
a
This is the latest plugin code
w
You wouldn't happen to have an example of >3.11 syntax I can use to test with, would you?
a
Hmm not that I can think of. Our code runs on 3.10 and (to some extent I think) on 3.11 but we haven't fully
pyupgrade
-ed it (or something equivalent)
w
match
I think is 3.10 - I can try that
šŸ‘Œ 1
a
Yes we do tons of matching
w
Alright, so older version of pants, but this is what I'm doing to test:
Copy code
[python]
enable_resolves = true
interpreter_constraints = [">=3.9"]
tailor_pex_binary_targets = false

[python.resolves]
pants-plugins = "build-support/pants-plugins/lock.txt"
python-default = "build-support/python/default_lock.txt"

[python.resolves_to_interpreter_constraints]
pants-plugins = [">=3.9,<3.10"]
Copy code
pex_binary(
    name="helloworld-pex",
    entry_point="helloworld.main",
    dependencies=[":libhelloworld"],
    interpreter_constraints=[">=3.10"]
)

scie_binary(
    name="helloworld-scie",
    dependencies=[":helloworld-pex"],
    #platforms=["linux-x86_64", "macos-aarch64"]
    lift="lift.toml"
)
šŸ‘€ 1
a
Ok here we go, it wasn't on
generate-lockfiles
it was on
test
at runtime
w
Ahh, okay, let me try with that
Just to check, is pyyaml 6 supported for py3.9? I've seen pyyaml alot around my errors, and can never remember why
https://pypi.org/project/PyYAML/#files Looks like it at a glance
a
I think it does yes
w
Weird, the nose file doesn't load - rule errors
šŸ¤” 1
a
What's the error?
w
Just a bunch of rule graph stuff... I must have a typo somewhere
😬 1
a
(Stepping away for lunch but can talk on mobile)
w
šŸ‘ Typo is an understatement, I copied the wrong version of the source
šŸ˜… 1
Among other issues, I get a complaint that it can't find the module "nose", and then it still runs pytest as well šŸ™‚
a
Ah yes - I had to specify the nose dependency in my test subdirectory
w
So, I'm running into a problem with nosetests itself, it seems:
Copy code
Traceback (most recent call last):
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/failure.py", line 38, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file examples/python/helloworld/helloworld/__init__.py

======================================================================
ERROR: Failure: ImportError (No module named 'main_test')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/failure.py", line 35, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/loader.py", line 335, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/importer.py", line 157, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/importer.py", line 181, in importFromDir
    fh, filename, desc = find_module(part, path)
  File "/Users/sj/.cache/pants/named_caches/pex_root/venvs/s/d4823f06/venv/lib/python3.9/site-packages/nose/importer.py", line 90, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'main_test'
Ahh, wait a sec....
Alright, I think I have it working - albeit, in a slightly different way
TIL: Trying to write pants code without a working Python LSP is hard AF
🤣 1
Here is the updated file. This might not be the best way to do it for Tests, specifically, but this is basically how I'd do it for linters/formatters/etc... Anyways, just wanted to get something working. • Using ConsoleScript
nosetests
instead of the entrypoint, as I haven't used nose in many years and don't recall how to use it other than the command line runner. • Using a VenvPexProcess directly, instead of a few composable items along the way • Created a pynose specific lockfile (CPython10) • Only the pants-plugins code (e.g. the rules and target stuff) runs using 3.9, everything else can run using whatever interpreter I removed the MultiGets, but you can put those back in, as it's a bit more efficient
a
Sorry was in a meeting. Agreed! That's why I added
pants_requirements
and added the resolve to export so that I'd get the venv for LSP šŸ˜„
Thank you - taking a look now
(sorry was in a meeting just until now) really appreciate your time and help
w
šŸ‘
a
How did you generate the nose.lock file?
w
In the mainline repo, there is a
generate_builtin_lockfiles.py
which does it. outside, I kinda just hacked it: I created a
nosetool
resolve which pointed at the lockfile location, then created a
python_requirement(requirements=["pynose==1.5.1"], resolve="nosetool"]
and then did a regular
generate-lockfiles
pointing at the nosetool resolve
a
I see thank you. I'll do that. I would assume that the
PythonToolBase
declaration would take care of that....
w
That's just pointing to the one that needs to be there. In the pants repo, it can be generated via a script, but it's probably not something that should be automated as it's a lockfile. At some point, it looks like we changed from "maybe have a lockfile" to "must have a lockfile"
šŸ‘ 1