Skip to content
Open
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
22 changes: 6 additions & 16 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
# project build medadata that can't be used in docker
Dockerfile
.appveyor.yml
.dockerignore
.pre-commit-hooks.yaml
.travis.yml
.git*
# Ignore everything ...
*

# documentation not needed
CHANGELOG.md
LICENSE
MANIFEST.in
.undertake
example.gif
logo.png
art/
docs/
# ... except:
!isort
!pyproject.toml
!README.md
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
release:
if: github.repository_owner == 'PyCQA'
name: Release
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Check out the repository
Expand Down Expand Up @@ -55,3 +58,39 @@ jobs:
tag: ${{ steps.check-version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Build a new Docker image and push it to the GitHub Container Registry
Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I have no clue what I'm looking at here. Is there perhaps a link you can share with some example of another project that has a similar setup?

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
33 changes: 14 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
FROM python:3.13
# Build stage
FROM python:3.13-alpine AS builder

WORKDIR /isort
COPY pyproject.toml uv.lock /isort/
COPY . .

# Install uv
COPY --from=ghcr.io/astral-sh/uv:0.6.0 /uv /uvx /bin/
RUN pip install --no-cache-dir uv
Copy link
Member

Choose a reason for hiding this comment

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

Why not copy from ghcr.io? And can we take the version as defined in pyproject.toml?


# Setup as minimal a stub project as possible, simply to allow caching base dependencies
# between builds.
#
# If error is encountered in these steps, can safely be removed locally.
RUN mkdir -p /isort/isort
RUN mkdir -p /isort/tests
RUN touch /isort/isort/__init__.py
RUN touch /isort/tests/__init__.py
RUN touch /isort/README.md
COPY . /isort
RUN SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 uv sync --all-extras --frozen
RUN SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 uv build .
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a different version?


# Install latest code for actual project
RUN rm -rf /isort
# Release stage
FROM python:3.13-alpine

# Run full test suite
CMD /isort/scripts/test.sh
# Install the wheel from the build stage
COPY --from=builder /isort/dist/ /tmp/
RUN \
pip install --no-cache-dir /tmp/*.whl && \
rm /tmp/*.whl

ENTRYPOINT ["isort"]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,44 @@ pre-commit script to check Python code before committing.

[More info here.](https://pycqa.github.io/isort/docs/configuration/git_hook.html)

## Docker

isort is available as a Docker image on the GitHub Container Registry.

To sort imports and modify files:

```bash
docker run -it --rm \
-v $(pwd):/code \
-v $(pwd)/pyproject.toml:/code/pyproject.toml \
-w /code \
ghcr.io/pycqa/isort:latest \
isort
```

To check imports without modifying files:

```bash
docker run -it --rm \
-v $(pwd):/code \
-v $(pwd)/pyproject.toml:/code/pyproject.toml \
-w /code ghcr.io/pycqa/isort:latest \
--check-only --diff isort
```

To check files in GitLab Continuous Integration, add the following job to your `.gitlab-ci.yml`:

```yaml
stages:
- lint

isort:
stage: lint
image: ghcr.io/pycqa/isort:latest
script:
- isort --check-only --diff .
```

## Setuptools integration

Upon installation, isort enables a `setuptools` command that checks
Expand Down