Skip to content

refactor: packages import spack.package explicitly#30404

Merged
tgamblin merged 46 commits intospack:developfrom
trws:pkgkit
May 28, 2022
Merged

refactor: packages import spack.package explicitly#30404
tgamblin merged 46 commits intospack:developfrom
trws:pkgkit

Conversation

@trws
Copy link
Copy Markdown
Contributor

@trws trws commented Apr 29, 2022

Explicitly import package utilities in all packages, and corresponding fallout. This includes:

  • rename spack.package to spack.package_base
  • rename spack.pkgkit to spack.package
  • update all packages in builtin, builtin_mock and tutorials to include from spack.package import *
  • update spack style
    • ensure packages include the import
    • automatically add the new import and remove any/all imports of spack and spack.pkgkit from packages when using --fix
    • add support for type-checking packages with mypy when SPACK_MYPY_CHECK_PACKAGES is set in the environment
  • fix all type checking errors in packages in spack upstream
  • update spack create to include the new imports
  • update spack repo to inject the new import, injection persists to allow for a deprecation period

Original message below:

As requested @adamjstewart, update all packages to use pkgkit. I ended up using isort to do this, so repro is easy:

$ isort -a 'from spack.pkgkit import *' --rm 'spack' ./var/spack/repos/builtin/packages/*/package.py
$ spack style --fix

There were several line spacing fixups caused either by space manipulation in isort or by packages that haven't been touched since we added requirements, but there are no functional changes in here.

  • add config to isort to make sure this is maintained going forward

@trws trws requested review from adamjstewart and tgamblin April 29, 2022 17:02
@adamjstewart
Copy link
Copy Markdown
Member

Thanks! Two additional things to think about:

  1. We also need to update spack create so that new packages come with this import
  2. We should consider removing the hack that automatically injects this import into all package files. We probably can't do this right away as it will break non-upstreamed packages, but we could add a spack audit test to make sure all new packages use this and remove the hack at a later date.

@tldahlgren
Copy link
Copy Markdown
Contributor

I thought importing of pkgkit was automatic as part of the Spack "magic". @tgamblin is the expert.

Where was it not getting imported?

@adamjstewart
Copy link
Copy Markdown
Member

adamjstewart commented Apr 29, 2022

It is. The purpose of this PR is to remove that magic, or at least move in a direction in which we can remove that magic in the future. Our magic doesn't work for a lot of tools like autocompletion in Jupyter Notebooks and type checks in mypy. It's also slower than simply using the import directly.

EDIT: Another reason is that our magic causes error messages to be off by one line.

@trws
Copy link
Copy Markdown
Contributor Author

trws commented Apr 29, 2022

Thanks! Two additional things to think about:

1. We also need to update `spack create` so that new packages come with this import

2. We should consider removing the hack that automatically injects this import into all package files. We probably can't do this right away as it will break non-upstreamed packages, but we could add a `spack audit` test to make sure all new packages use this and remove the hack at a later date.

Yes, I agree with all of that, though after a chat with @tgamblin, we were discussing a rename as well, and I have a feeling I should do all of that together. The preference was spack.package.util as the "package utilities" that would be grabbed everywhere. What do you think about that @adamjstewart?

@tgamblin
Copy link
Copy Markdown
Member

Basically I think spack.pkgkit is a weird name, and spack.package.util is clearer.

@adamjstewart
Copy link
Copy Markdown
Member

Personally I would rename spack.package to something else and rename spack.pkgkit to spack.package. I think we already had this discussion when we first decided on the name spack.pkgkit.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented May 2, 2022

When this goes in we can remove import boilerplate from spack.repo.

@trws
Copy link
Copy Markdown
Contributor Author

trws commented May 2, 2022

Some, but not all yet, there are some things this doesn't cover, but this gets us far enough that it helps a lot identifying what's left.

I wouldn't hate renaming package necessarily, but that will touch a lot of places. What would we rename it to, package_class, package_impl, package_internal..?

@trws
Copy link
Copy Markdown
Contributor Author

trws commented May 11, 2022

Ok, this was everything and re-updated on develop less than 10 seconds ago. It now has a conflict. Will probably have to stage this one carefully.

Anyway, I ended up moving package to package_base as we discussed, and then pkgkit is now package_defs. I know we discussed making it package, but having the ambiguity between spack.package and the package.py file in every package directory proved somewhat unfortunate. If the decision is to make it package.py, I'll change it one last time to that.

@trws
Copy link
Copy Markdown
Contributor Author

trws commented May 12, 2022

Something bad happened to the github actions here. Going to merge in develop to poke it.

trws added 2 commits May 12, 2022 09:12
…CHECK_PACKAGES env var to inform style to check packages as well as core, also basic config for pyright added to pypackage.toml, pyright tests do *NOT* pass, it is much more strict than our mypy config right now and can catch many bugs including missing imports and uninitialized variable names, currently best used on a small set of files, the full repo gives over 90,000 diagnostics with it for now
@trws trws changed the title Use pkgkit everywhere Explicitly import package prelude (now spack.package) everywhere, rename pkgkit to package and package to package_base May 25, 2022
@trws
Copy link
Copy Markdown
Contributor Author

trws commented May 26, 2022

@spackbot run pipeline

@spackbot-app
Copy link
Copy Markdown

spackbot-app bot commented May 26, 2022

I had a problem triggering the pipeline.

@tgamblin tgamblin changed the title Explicitly import package prelude (now spack.package) everywhere, rename pkgkit to package and package to package_base refactor: packages import spack.package explicitly May 26, 2022
tgamblin
tgamblin previously approved these changes May 26, 2022
@tgamblin tgamblin enabled auto-merge (squash) May 26, 2022 16:32
@tgamblin tgamblin merged commit 18c2f1a into spack:develop May 28, 2022
@trws trws deleted the pkgkit branch May 28, 2022 20:27
iarspider pushed a commit to iarspider/spack that referenced this pull request May 30, 2022
Explicitly import package utilities in all packages, and corresponding fallout.

This includes:

* rename `spack.package` to `spack.package_base`
* rename `spack.pkgkit` to `spack.package`
* update all packages in builtin, builtin_mock and tutorials to include `from spack.package import *`
* update spack style
  * ensure packages include the import
  * automatically add the new import and remove any/all imports of `spack` and `spack.pkgkit`
    from packages when using `--fix`
  * add support for type-checking packages with mypy when SPACK_MYPY_CHECK_PACKAGES
    is set in the environment
* fix all type checking errors in packages in spack upstream
* update spack create to include the new imports
* update spack repo to inject the new import, injection persists to allow for a deprecation period

Original message below:
 
As requested @adamjstewart, update all packages to use pkgkit.  I ended up using isort to do this,
so repro is easy:

```console
$ isort -a 'from spack.pkgkit import *' --rm 'spack' ./var/spack/repos/builtin/packages/*/package.py
$ spack style --fix
```

There were several line spacing fixups caused either by space manipulation in isort or by packages
that haven't been touched since we added requirements, but there are no functional changes in here.

* [x] add config to isort to make sure this is maintained going forward
alalazo added a commit to alalazo/spack that referenced this pull request Jun 4, 2022
trws pushed a commit that referenced this pull request Jun 6, 2022
@wyphan wyphan mentioned this pull request Jun 8, 2022
vvolkl added a commit to key4hep/key4hep-spack that referenced this pull request Jul 12, 2022
* fix package-base exception

* Update packages/key4hep-stack/common.py

Co-authored-by: Valentin Volkl <[email protected]>
bhatiaharsh pushed a commit to bhatiaharsh/spack that referenced this pull request Aug 8, 2022
Explicitly import package utilities in all packages, and corresponding fallout.

This includes:

* rename `spack.package` to `spack.package_base`
* rename `spack.pkgkit` to `spack.package`
* update all packages in builtin, builtin_mock and tutorials to include `from spack.package import *`
* update spack style
  * ensure packages include the import
  * automatically add the new import and remove any/all imports of `spack` and `spack.pkgkit`
    from packages when using `--fix`
  * add support for type-checking packages with mypy when SPACK_MYPY_CHECK_PACKAGES
    is set in the environment
* fix all type checking errors in packages in spack upstream
* update spack create to include the new imports
* update spack repo to inject the new import, injection persists to allow for a deprecation period

Original message below:
 
As requested @adamjstewart, update all packages to use pkgkit.  I ended up using isort to do this,
so repro is easy:

```console
$ isort -a 'from spack.pkgkit import *' --rm 'spack' ./var/spack/repos/builtin/packages/*/package.py
$ spack style --fix
```

There were several line spacing fixups caused either by space manipulation in isort or by packages
that haven't been touched since we added requirements, but there are no functional changes in here.

* [x] add config to isort to make sure this is maintained going forward
bhatiaharsh pushed a commit to bhatiaharsh/spack that referenced this pull request Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants