Skip to content

Commit

Permalink
Merge pull request #831 from swyddfa/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
alcarney authored Jun 7, 2024
2 parents bd04453 + 22b90b4 commit 2266901
Show file tree
Hide file tree
Showing 89 changed files with 3,492 additions and 1,036 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mcr.microsoft.com/devcontainers/base:jammy

COPY tools.mk /

RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends python3-venv \
&& su vscode -c "make -f tools.mk tools" \
&& rm tools.mk
28 changes: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "ghcr.io/swyddfa/esbonio-devenv:latest",
// "build": {
// "dockerfile": "Dockerfile"
// },
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"ms-python.python",
"tamasfe.even-better-toml"
]
}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
143 changes: 143 additions & 0 deletions .devcontainer/tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
ARCH ?= $(shell arch)
BIN ?= $(HOME)/.local/bin

ifeq ($(strip $(ARCH)),)
$(error Unable to determine platform architecture)
endif

HATCH_VERSION = 1.10.0
NODE_VERSION := 18.20.2

# The versions of Python we support
PYXX_versions := 3.8 3.9 3.10 3.11 3.12
PY_INTERPRETERS =

# Hatch is not only used for building packages, but bootstrapping any missing
# interpreters
HATCH ?= $(or $(shell command -v hatch), $(BIN)/hatch)

$(HATCH):
curl -L --output /tmp/hatch.tar.gz https://github.com/pypa/hatch/releases/download/hatch-v$(HATCH_VERSION)/hatch-$(HATCH_VERSION)-$(ARCH)-unknown-linux-gnu.tar.gz
tar -xf /tmp/hatch.tar.gz -C /tmp
rm /tmp/hatch.tar.gz

test -d $(BIN) || mkdir -p $(BIN)
mv /tmp/hatch-$(HATCH_VERSION)-$(ARCH)-unknown-linux-gnu $(HATCH)

$@ --version
touch $@

# This effectively defines a function `PYXX` that takes a Python version number
# (e.g. 3.8) and expands it out into a common block of code that will ensure a
# verison of that interpreter is available to be used.
#
# The is perhaps a bit more complicated than I'd like, but it should mean that
# the project's makefiles are useful both inside and outside of a devcontainer.
#
# `PYXX` has the following behavior:
# - If possible, it will reuse the user's existing version of Python
# i.e. $(shell command -v pythonX.X)
#
# - The user may force a specific interpreter to be used by setting the
# variable when running make e.g. PYXX=/path/to/pythonX.X make ...
#
# - Otherwise, `make` will use `$(HATCH)` to install the given version of
# Python under `$(BIN)`
#
# See: https://www.gnu.org/software/make/manual/html_node/Eval-Function.html
define PYXX =

PY$(subst .,,$1) ?= $$(shell command -v python$1)

ifeq ($$(strip $$(PY$(subst .,,$1))),)

PY$(subst .,,$1) := $$(BIN)/python$1

$$(PY$(subst .,,$1)): $$(HATCH)
$$(HATCH) python find $1 || $$(HATCH) python install $1
ln -s $$$$($$(HATCH) python find $1) $$@

$$@ --version
touch $$@

endif

PY_INTERPRETERS += $$(PY$(subst .,,$1))
endef

# Uncomment the following line to see what this expands into.
#$(foreach version,$(PYXX_versions),$(info $(call PYXX,$(version))))
$(foreach version,$(PYXX_versions),$(eval $(call PYXX,$(version))))

# Set a default `python` command if there is not one already
PY ?= $(shell command -v python3)

ifeq ($(strip $(PY)),)
PY := $(BIN)/python

$(PY): $(PY312)
ln -s $< $@
$@ --version
touch $@
endif

PY_INTERPRETERS += $(PY)
#$(info $(PY_INTERPRETERS))

PIPX ?= $(shell command -v pipx)

ifeq ($(strip $(PIPX)),)
PIPX := $(BIN)/pipx
PIPX_VERSION := 1.5.0

$(PIPX):
curl -L -o $(BIN)/pipx.pyz https://github.com/pypa/pipx/releases/download/$(PIPX_VERSION)/pipx.pyz
echo '#!/bin/bash\nexec $(PY) $(BIN)/pipx.pyz "$$@"' > $(PIPX)

chmod +x $(PIPX)
$@ --version
touch $@
endif

PRE_COMMIT ?= $(shell command -v pre-commit)

ifeq ($(strip $(PRE_COMMIT)),)
PRE_COMMIT := $(BIN)/pre-commit

$(PRE_COMMIT): $(PIPX)
$(PIPX) install pre-commit
$@ --version
touch $@
endif

PY_TOOLS := $(HATCH) $(PIPX) $(PRE_COMMIT)

# Node JS
NPM ?= $(shell command -v npm)

ifeq ($(strip $(NPM)),)

NPM := $(BIN)/npm
NODE := $(BIN)/node
NODE_DIR := $(HOME)/.local/node

$(NPM):
curl -L --output /tmp/node.tar.xz https://nodejs.org/dist/v$(NODE_VERSION)/node-v$(NODE_VERSION)-linux-x64.tar.xz
tar -xJf /tmp/node.tar.xz -C /tmp
rm /tmp/node.tar.xz

[ -d $(NODE_DIR) ] || mkdir -p $(NODE_DIR)
mv /tmp/node-v$(NODE_VERSION)-linux-x64/* $(NODE_DIR)

[ -d $(BIN) ] || mkdir -p $(BIN)
ln -s $(NODE_DIR)/bin/node $(NODE)
ln -s $(NODE_DIR)/bin/npm $(NPM)

$(NODE) --version
PATH=$(BIN) $(NPM) --version

endif

# One command to bootstrap all tools and check their versions
tools: $(PY_INTERPRETERS) $(PY_TOOLS) $(NPM)
for prog in $^ ; do echo -n "$${prog}\t" ; PATH=$(BIN) $${prog} --version; done
57 changes: 57 additions & 0 deletions .github/workflows/devenv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 'Build devcontainer'
on:

workflow_dispatch:

pull_request:
branches:
- develop
paths:
- '.devcontainer/**'

push:
branches:
- develop
paths:
- '.devcontainer/**'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-devenv

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .devcontainer/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
7 changes: 2 additions & 5 deletions .github/workflows/lsp-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ jobs:

- run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade tox
python -m pip install --upgrade hatch
name: Setup Environment
- run: |
cd lib/esbonio
version=$(echo ${{ matrix.python-version }} | tr -d .)
python -m tox run -e `tox -l | grep $version | tr '\n' ','`
shell: bash
hatch test -i py=${{ matrix.python-version }}
name: Run Tests
7 changes: 2 additions & 5 deletions .github/workflows/vscode-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade hatch tox towncrier 'importlib-resources<6'
python -m pip install --upgrade hatch towncrier
name: Install Build Tools
- run: |
Expand All @@ -57,10 +57,7 @@ jobs:
# Use in-repo version of esbonio for dev builds
echo "whl=${ESBONIO_WHL}"
ESBONIO_WHL=${ESBONIO_WHL} tox run -e bundle-deps
npm ci --prefer-offline
npm run package
ESBONIO=${ESBONIO_WHL} make dist
id: assets
name: Package Extension
Expand Down
23 changes: 6 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,16 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.4.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
hooks:
- id: black
- id: ruff
args: [--fix]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
exclude: 'scripts/sphinx-app.py'
args: [--config=lib/esbonio/setup.cfg]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: [--settings-file=lib/esbonio/pyproject.toml]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.9.0'
rev: 'v1.10.0'
hooks:
- id: mypy
name: mypy (scripts)
Expand Down
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.isort",
"swyddfa.esbonio"
"tamasfe.even-better-toml"
]
}
5 changes: 1 addition & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"outFiles": [
"${workspaceRoot}/code/dist/node/**/*.js"
],
// "preLaunchTask": "${defaultBuildTask}",
"env": {
// "VSCODE_LSP_DEBUG": "true"
}
"preLaunchTask": "${defaultBuildTask}",
},
{
"name": "VSCode Web Extension",
Expand Down
19 changes: 8 additions & 11 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"label": "npm: watch",
"type": "process",
"isBackground": true,
"command": "make",
"args": [
"watch"
],
"options": {
"cwd": "${workspaceRoot}/code"
},
Expand All @@ -14,17 +18,10 @@
},
"presentation": {
"panel": "dedicated",
"reveal": "never"
"reveal": "always"
},
"problemMatcher": [
{
"base": "$tsc-watch",
"background": {
"activeOnStart": true,
"beginsPattern": "asset .*",
"endsPattern": "webpack .* compiled .*"
}
}
"$tsc-watch"
]
},
{
Expand Down
Loading

0 comments on commit 2266901

Please sign in to comment.