Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode development requirements in pyproject.toml #32616

Merged
merged 5 commits into from
Nov 7, 2022

Conversation

trws
Copy link
Contributor

@trws trws commented Sep 12, 2022

Add a project block to the toml config along with development and CI dependencies and a minimal build-system block, doing basically nothing, so that spack can be bootstrapped to a full development environment with:

$ hatch shell

or for a minimal environment without hatch:

$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install --upgrade pip
$ python3 -m pip install -e '.[dev]'

This means we can re-use the requirements list throughout the workflow yaml files and otherwise maintain this list in one place rather than several disparate ones. We may be stuck with a couple more temporarily to continue supporting python2.7, but aside from that it's less places to get out of sync and a couple new bootstrap options.

@spackbot-app spackbot-app bot added the core PR affects Spack core functionality label Sep 12, 2022
Copy link
Member

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Excited to some day be able to tell people to pip install spack.

Comment on lines +32 to +38
requires = ["hatchling"]
build-backend = "hatchling.build"
Copy link
Member

Choose a reason for hiding this comment

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

Why hatchling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, because I couldn't figure out how to get setuptools to just let me do an editable install without erroring out or declaring explicit package parameters. Poetry, which is my usual weapon of choice, seems to require a good bit of extra boilerplate. This version made it "just work" so the dependencies will install with pip or hatch, or any pep-517/660 compliant tool presumably, out of the box. The hatch env stuff I just find really handy, honestly, but that isn't tied to using hatchling like this, if you know a better way to get pip install with and without -e working to set this up I'm happy to explore alternatives.

Copy link
Member

Choose a reason for hiding this comment

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

What version of setuptools were you using? I know there was a recent refactor in v64 that added support for editable installs using pyproject.toml. I have no personal preference on build backend, just curious about the decision since I'm never sure which backend I should be using in my own projects.

Copy link

Choose a reason for hiding this comment

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

Maintainer here! Hatchling is also now used as the default in the official Python packaging tutorial.

Copy link
Member

Choose a reason for hiding this comment

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

@ofek do you know how the default was chosen? I haven't yet seen an official comparison between backends and PyPA refuses to admit that "default" == "recommended".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pradyunsg it's a bit of a grey area IMO, it's things like package files, which are technically code but are most definitely not libraries or things meant to be run by users, configuration files, etc.

Choose a reason for hiding this comment

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

I'm pretty sure that you can remove the bin/spack file, since it's being replaced by the script that will be generated for project.scripts declarations. FWIW, those are what the console_scripts entry points from setuptools map to -- I'm quite pleased that we have a friendlier user-facing name for the concept.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a bit of a gray area. We would like to be able to run Spack just by cloning and running ./spack/bin/spack, but we would also like to be able to install with pip. I think the former use case will actually be more common that the latter, so we can't just get rid of the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pradyunsg Yeah, it wouldn't be installed by pip, but we need it there for the "clone and go" use-case.

On installing, the shared-data option definitely works, but splitting our directories up breaks all the relative pathing stuff so things break, really badly. I did manage to get install to produce a console_script that works, and install all the directories under site-packages/spack_root though rather than splatting them all over the place, and the resulting install can install packages and generally kinda just works.

Copy link

@pradyunsg pradyunsg Sep 21, 2022

Choose a reason for hiding this comment

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

In thar case, I suggest removing it from the list of files being included in the wheel (python -m build && unzip -l dist/*.whl shouldn't list any sort of .scripts/spack since that would be overwritten by a launcher script that pip generates instead.)

pyproject.toml Outdated Show resolved Hide resolved
@trws
Copy link
Contributor Author

trws commented Sep 14, 2022

@adamjstewart, this update makes the pip installed spack actually work. It also reads the spack version from the canonical spack location, which unfortunately required a bit of reworking there because the pip mechanism for it uses a regex, and the original tuple isn't compatible with that.

Only the spack command is installed at the moment, but it's hooked in such that it will use the python managed by a venv or similar, and refactors the setup code so that both bin/spack and the pip generated script will use the same path setup logic. It's kinda strange, but it seems to work. I'm not sure I like using the externals like this, they really should just be pulled from packages for this probably, but this is more like how spack works when cloned so I went with it for now.

@adamjstewart
Copy link
Member

This means we can re-use the requirements list throughout the workflow yaml files and otherwise maintain this list in one place rather than several disparate ones.

Given that Spack's deps are still listed in all of the same places, this kinda feels like: https://xkcd.com/927/

@trws
Copy link
Contributor Author

trws commented Sep 14, 2022

This means we can re-use the requirements list throughout the workflow yaml files and otherwise maintain this list in one place rather than several disparate ones.

Given that Spack's deps are still listed in all of the same places, this kinda feels like: https://xkcd.com/927/

Sadly this is true, we can replace the pip commands in the workflows to reuse this at least, but it doesn't necessarily get all of them (because I'm not sure a new enough pip can run on python2.7).

@adamjstewart
Copy link
Member

There's also var/spack/repos/builtin/packages/spack/package.py lol

@trws
Copy link
Contributor Author

trws commented Sep 14, 2022

🤦

If someone were sufficiently motivated, we could write a shim build-system that actually uses spack to generate the dependency list for pip from that file, make wheels, etc. I'm not sure if it's worth it, but we could. Alternately, we could have that package reworked to have spack use pip to install spack... 🤔

At least this way we can easily generate a local venv or similar with the same deps that are used in CI, and not have to re-list the stuff in mac, and linux, and windows and so-forth. It's not everything, but it makes bootstrapping to style with pip less frustrating.

@adamjstewart
Copy link
Member

Alternately, we could have that package reworked to have spack use pip to install spack

We would still need to list the deps in the package though.

@trws
Copy link
Contributor Author

trws commented Sep 21, 2022

Ok, I've actually gone through and replaced all the pip install commands in our workflows with the exact same string, installing using the deps listed in pyproject.toml. With conditional dependencies that includes python2.7 and windows. Assuming this works, pretty happy with how many of those just went away.

@@ -25,7 +25,8 @@ jobs:
python-version: ${{inputs.python_version}}
- name: Install Python packages
run: |
pip install --upgrade pip six setuptools pytest codecov 'coverage[toml]<=6.2'
pip install --upgrade pip
pip install '.[dev,ci]' # not using -e because of python 2.7 support
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to use -e even for Python 3? It's all CI so why install in editable mode?

Copy link

Choose a reason for hiding this comment

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

coverage output is readable by default without rewrite config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, really it's to make sure that we don't accidentally run spack from the install location, for reasons like @ofek mentions. We point to the in-tree version anyway, so it should be fine, but it's one less source of confusion. If there were a way to only install the dependencies rather than the dependencies and spack that's what I would want to use, but it seems like that isn't a supported use-case in pip.

@ofek
Copy link

ofek commented Oct 4, 2022

CI flake?

@trws
Copy link
Contributor Author

trws commented Nov 1, 2022

So... I would really like to merge this, so it doesn't atrophy. Is there a remaining blocker or concern here @adamjstewart, @tgamblin? I'm rebasing to resolve the workflows right now.

@trws trws force-pushed the pyproject-project branch 2 times, most recently from a3a3d05 to afd0e88 Compare November 2, 2022 16:06
trws and others added 5 commits November 5, 2022 12:33
Add a `project` block to the toml config along with development and CI
dependencies and a minimal `build-system` block, doing basically
nothing, so that spack can be bootstrapped to a full development
environment with:

```shell
$ hatch -e dev shell
```

or for a minimal environment without hatch:

```shell
$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install --upgrade pip
$ python3 -m pip install -e '.[dev]'
```

This means we can re-use the requirements list throughout the workflow
yaml files and otherwise maintain this list in *one place* rather than
several disparate ones.  We may be stuck with a couple more temporarily
to continue supporting python2.7, but aside from that it's less places
to get out of sync and a couple new bootstrap options.
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
@trws
Copy link
Contributor Author

trws commented Nov 5, 2022

Rebased again, from the pool. Any chance of a review? This is verified to work with hatch, pip, and with a bit of adaptor code nix as well. Could certainly do with more helper commands and some thought on actually using it as an installed package, but everything is functional.

@tgamblin tgamblin merged commit 6241cdb into spack:develop Nov 7, 2022
charmoniumQ pushed a commit to charmoniumQ/spack that referenced this pull request Nov 19, 2022
Add a `project` block to the toml config along with development and CI
dependencies and a minimal `build-system` block, doing basically
nothing, so that spack can be bootstrapped to a full development
environment with:

```shell
$ hatch -e dev shell
```

or for a minimal environment without hatch:

```shell
$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install --upgrade pip
$ python3 -m pip install -e '.[dev]'
```

This means we can re-use the requirements list throughout the workflow
yaml files and otherwise maintain this list in *one place* rather than
several disparate ones.  We may be stuck with a couple more temporarily
to continue supporting python2.7, but aside from that it's less places
to get out of sync and a couple new bootstrap options.

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
amd-toolchain-support pushed a commit to amd-toolchain-support/spack that referenced this pull request Feb 16, 2023
Add a `project` block to the toml config along with development and CI
dependencies and a minimal `build-system` block, doing basically
nothing, so that spack can be bootstrapped to a full development
environment with:

```shell
$ hatch -e dev shell
```

or for a minimal environment without hatch:

```shell
$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install --upgrade pip
$ python3 -m pip install -e '.[dev]'
```

This means we can re-use the requirements list throughout the workflow
yaml files and otherwise maintain this list in *one place* rather than
several disparate ones.  We may be stuck with a couple more temporarily
to continue supporting python2.7, but aside from that it's less places
to get out of sync and a couple new bootstrap options.

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
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 workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants