Skip to content

Rework the automation for generating the scripts #85

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

Merged
merged 8 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Check Scripts

on:
push:
pull_request:

jobs:
correctly-generated:
name: "are correctly generated"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install nox

- run: nox -s generate
- name: Check regenerated scripts vs what is generated by automation.
run: git diff --exit-code

work-as-advertised:
name: "work as advertised"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install nox

# Install supported Python versions
- uses: actions/setup-python@v2
with:
python-version: 2.7
- uses: actions/setup-python@v2
with:
python-version: 3.5
- uses: actions/setup-python@v2
with:
python-version: 3.6
- uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions/setup-python@v2
with:
python-version: 3.9

# Check that the scripts work.
- run: nox -s check
29 changes: 0 additions & 29 deletions .github/workflows/tests.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.nox/
/venv/
__pycache__/
.web_cache/
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# get-pip.py

`get-pip.py` is a bootstrapping script that enables users to install pip,
setuptools, and wheel in Python environments that don't already have them. You
should not directly reference the files located in this repository and instead
use the versions located at <https://bootstrap.pypa.io/>.

## Usage

```console
$ curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py
```

Upon execution, `get-pip.py` will install `pip`, `setuptools` and `wheel` in
the current Python environment.

It is possible to provide additional arguments to the underlying script. These
are passed through to the underlying `pip install` command, and can thus be
used to constraint the versions of the packages, or to pass other pip options
such as `--no-index`.

```console
$ python get-pip.py "pip < 21.0" "setuptools < 50.0" "wheel < 1.0"
$ python get-pip.py --no-index --find-links=/local/copies
```

### get-pip.py options

This script also has it's own options, which control which packages it will
install.

- `--no-setuptools`: do not attempt to install `setuptools`.
- `--no-wheel`: do not attempt to install `wheel`.

## Development

You need to have a [`nox`](https://nox.readthedocs.io/) available on the CLI.

### How it works

`get-pip.py` bundles a copy of pip with a tiny amount of glue code. This glue
code comes from the `templates/` directory.

### Updating after a pip release

If you just made a pip release, run `nox -s update-for-release -- <version>`.
This session will handle all the script updates (by running `generate`), commit
the changes and tag the commit.

IMPORTANT: Check that the correct files got modified before pushing. The session
will pause to let you do this.

### Generating the scripts

Run `nox -s generate`.

## Discussion

If you run into bugs, you can file them in our [issue tracker].

You can also join `#pypa` or `#pypa-dev` on Freenode to ask questions or
get involved.

[issue tracker]: https://github.com/pypa/get-pip/issues

## Code of Conduct

Everyone interacting in the get-pip project's codebases, issue trackers, chat
rooms, and mailing lists is expected to follow the [PSF Code of Conduct].

[PSF Code of Conduct]: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md
86 changes: 0 additions & 86 deletions README.rst

This file was deleted.

93 changes: 89 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,94 @@
import os
import textwrap
from pathlib import Path

import nox

nox.options.sessions = ["check", "generate"]

@nox.session(python=['2.7', '3.7'])
def tests(session):
session.install('pytest')
session.run('pytest')

# Keep versions in sync with .github/workflows/check.yml
@nox.session(
python=["2.6", "2.7", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9"]
)
def check(session):
"""Ensure that get-pip.py for various Python versions, works on that version."""

# Find the appropriate get-pip.py file
public = Path(".")
locations = [
public / session.python / "get-pip.py",
public / "get-pip.py",
]
for location in locations:
if location.exists():
break
else: # AKA nobreak
raise RuntimeError("There is no public get-pip.py")

# Get rid of provided-by-nox pip
session.run("python", "-m", "pip", "uninstall", "pip", "--yes")
# Run the get-pip.py file
session.run("python", str(location))
# Ensure that pip is installed
session.run("python", "-m", "pip", "--version")
session.run("pip", "--version")


@nox.session
def generate(session):
"""Update the scripts, to the latest versions."""
session.install("packaging", "requests", "cachecontrol[filecache]")

session.run("python", "scripts/generate.py")


@nox.session(name="update-for-release")
def update_for_release(session):
"""Automation to run after a pip release."""
allowed_upstreams = [
"[email protected]:pypa/get-pip.git",
"https://github.com/pypa/get-pip.git",
]

if len(session.posargs) != 1:
session.error("Usage: nox -s update-for-release -- <released-pip-version>")

release_version, = session.posargs

session.install("release-helper")
session.run("release-helper", "version-check-validity", release_version)
session.run("release-helper", "git-check-tag", release_version, "--does-not-exist")
session.run("release-helper", "git-check-remote", "upstream", *allowed_upstreams)
session.run("release-helper", "git-check-branch", "master")
session.run("release-helper", "git-check-clean")

# Generate the scripts.
generate(session)

# Make the commit and present it to the user.
session.run("git", "add", ".", external=True)
session.run(
"git", "commit", "-m", f"Update to {release_version}", external=True
)
session.run("git", "show", "HEAD", "--stat")

input(textwrap.dedent(
"""\
**********************************************
* IMPORTANT: Check which files got modified. *
**********************************************

Press enter to continue. This script will generate a signed tag for this
commit and push it -- which will publish these changes.
"""
))

session.run(
# fmt: off
"git", "tag", release_version, "-m", f"Release {release_version}",
"--annotate", "--sign",
external=True,
# fmt: on
)
session.run("git", "push", "upstream", "master", release_version, external=True)
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

Loading