Skip to content

Move python glue logic again#50616

Merged
scheibelp merged 15 commits intospack:developfrom
scheibelp:move-python-glue-logic-again
May 30, 2025
Merged

Move python glue logic again#50616
scheibelp merged 15 commits intospack:developfrom
scheibelp:move-python-glue-logic-again

Conversation

@scheibelp
Copy link
Copy Markdown
Member

@scheibelp scheibelp commented May 22, 2025

Redo of #50605

Now with fixes

Right now it should fail, because this doesn't add anything to the changes. Once I can reproduce the failure, I think I know how to fix it

@spackbot-app spackbot-app bot added core PR affects Spack core functionality gitlab Issues related to gitlab integration labels May 22, 2025
@spackbot-app spackbot-app bot added the tests General test capability(ies) label May 23, 2025
@scheibelp
Copy link
Copy Markdown
Member Author

I see in e46a9f2 that the spec this was trying to attach python to was llvm: llvm extends python (in this case) but is not a PythonPackage, so it's implementation of _update_external_dependencies (inherited from PackageBase) is a noop (i.e. no attempt to call detection.by_path).

As noted in #50616 (comment), envs that use concretize_separately (i.e. those w/ unify:false) will fail on develop if they contain external py- packages (with no corresponding python external). So the latest commit experiments with using a SequentialExecutor to detect Python (so that can occur in the context of concretize_separately).

It's probably also worth excluding some/most (non-py-) packages from this check: the logic was added specifically for PythonPackages because they refer to self["python"] outside of phase methods, so that should be ok. I presume we don't want to check isinstance(PythonPackage). llvm is kind of a special case in that it will be commonly referenced as an external (because it is a compiler) and it extends python, so perhaps excluding compiler packages would be a good compromise.

@tgamblin
Copy link
Copy Markdown
Member

LLVM actually references spec["python"]:

            if "python" in spec:  # lit's Python needs to be set with this variable
                cmake_args.append(define("python_executable", spec["python"].command.path))

Note that it's guarded, so I guess things won't fail if you exclude LLVM, but I think it's worth figuring out why LLVM was special here and why running this check on it failed.

@tgamblin
Copy link
Copy Markdown
Member

I presume we don't want to check isinstance(PythonPackage)

Probably not, as we don't want the import coupling between core and builtin, but for this very special case I think this would be ok and would avoid that problem while doing no harm:

any([c.__name__ == "PythonPackage" for c in cls.__mro__])

It would at least exclude the things that would've been excluded before, and would allow us to fix this better later (which is the intent).

@scheibelp
Copy link
Copy Markdown
Member Author

LLVM actually references spec["python"]

Yes, but inside of a function used by a phase (so when LLVM is external, none of its references to self["python"] will be "tripped").

but for this very special case I think this would be ok and would avoid that problem while doing no harm:

In terms of LLVM, that has the same behavior as 2c52cf9 (which is fine, given the above) but I think it is preferable because it achieves exactly the same inclusion/exclusion as before.

--config-scope "${SPACK_CI_CONFIG_ROOT}/${SPACK_TARGET_PLATFORM}/${SPACK_TARGET_ARCH}"
config blame > "${CI_PROJECT_DIR}/jobs_scratch_dir/spack.yaml.blame"
- spack -v --color=always
- spack -d -v --color=always
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's worth running all spack commands in CI with -d, so I left this here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was something that slipped through, but I see it is not. I'm against this change, for this reason:

The output is not readable, and is truncated because it exceeds limits. I'll submit a PR to revert that, and point to these comments for reference.

@scheibelp scheibelp changed the title [WIP] Move python glue logic again Move python glue logic again May 28, 2025
@scheibelp scheibelp requested a review from tgamblin May 28, 2025 05:30
@scheibelp

This comment was marked as resolved.

@spackbot-app

This comment was marked as resolved.

@scheibelp scheibelp merged commit 69cbd4d into spack:develop May 30, 2025
36 checks passed
tgamblin pushed a commit that referenced this pull request Jun 6, 2025
#50616 moved some logic that connects external python extensions to an instance of python;
it attempted to do this in a way that matched prior behavior exactly but accidentally applied
this for PythonPackage instead of PythonExtension (a superclass of the former) which meant
that some packages that this applied to before (e.g. py-pip) were now omitted.

Updates the test
kshea21 pushed a commit to kshea21/spack that referenced this pull request Jun 18, 2025
Redo of spack#50605 (Move external python glue logic into core) 

This concerns logic that attaches a `python` dependency to some external
packages (because they expect an instance of `python` in their DAG).
spack#50605 was intended to be a simple relocation of logic from the package
repo to the core.

That PR caused a failure because it was attempting to attach python to a
bigger set of dependents: originally this logic only ran for packages
that were a subclass of `PythonPackage`, and that PR made it run for all
packages that `extends(python)`; notably that included LLVM, and in
particular this occurred inside of an environment that set `unify: false`;
attaching Python can involve looking for an instance of Python on the
system, and normal external detection runs with a process pool, which is
prohibited in the context of `concretize_separately` (which itself uses a
process pool with daemon processes).

This PR reapplies the logic from spack#50605 with two additional changes:

* Match the previous inclusion/exclusion semantics by only attaching
  Python to external packages that are a subclass of `PythonPackage`
* Update external Python search to run within the current process
  (so that it can run as part of `concretize_separately`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR affects Spack core functionality gitlab Issues related to gitlab integration tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants