From f2f0313ea04f9485fa04fcee35f2f4670b69488e Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Thu, 23 Nov 2023 17:15:49 +0800 Subject: [PATCH] chore: update devcontainer config. --- .devcontainer/Dockerfile | 51 ------------------------------- .devcontainer/devcontainer.json | 53 ++++++++++++++++++++------------- Makefile | 22 ++++++++------ 3 files changed, 45 insertions(+), 81 deletions(-) delete mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index bad0d90d..00000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -FROM ubuntu:jammy - -# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux, -# this user's GID/UID must match your local user UID/GID to avoid permission issues -# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See -# https://aka.ms/vscode-remote/containers/non-root-user for details. -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=${USER_UID} - -# Avoid warnings by switching to noninteractive -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get upgrade -qy && apt-get install -qy \ - apt-utils \ - ca-certificates\ - locales \ - curl \ - git \ - make \ - python-is-python3 \ - python3 \ - python3-pip && \ - apt-get autoclean -y && \ - apt-get autoremove -y && \ - apt-get clean - -# Install poetry -RUN pip install poetry - -# Set up locale -RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ - && locale-gen -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - -# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ - # [Optional] Add sudo support for the non-root user - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ - && chmod 0440 /etc/sudoers.d/$USERNAME - -# Switch back to dialog for any ad-hoc use of apt-get -ENV DEBIAN_FRONTEND= - -USER $USERNAME - -CMD ["/bin/bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0a148479..4beb2f4d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,23 +1,34 @@ -// For format details, see https://aka.ms/vscode-remote/devcontainer.json +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python { - "name": "python dev", - "dockerFile": "Dockerfile", - "build": { - "args": {} - }, - // https://code.visualstudio.com/remote/advancedcontainers/environment-variables - "remoteEnv": { - // "PIP_INDEX_URL": "https://mirrors.ustc.edu.cn/pypi/web/simple" - }, - "runArgs": [], - "customizations": { - "vscode": { - "extensions": [ - "ms-python.python" - ] - } - }, - "postCreateCommand": "poetry install --all-extras", - "postAttachCommand": "poetry shell", - "remoteUser": "vscode" + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm", + + "remoteEnv": { + // "PIP_INDEX_URL": "https://mirrors.ustc.edu.cn/pypi/web/simple" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + }, + + // 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": "pip3 install pre-commit && pre-commit install && pip3 install poetry && poetry shell && poetry install --all-extras", + + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } diff --git a/Makefile b/Makefile index c62236a8..f33e9473 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,15 @@ XDRGEN_REPO=overcat/xdrgen XDRGEN_COMMIT=c98916346eeea7e37aaea039de03c1e5ea0a116a XDRNEXT_COMMIT=6a620d160aab22609c982d54578ff6a63bfcdc01 -UNAME := $(shell uname) + +ifeq ($(shell uname), Darwin) +SED := sed -i '' +REPLACE_KEYWORD_COMMAND := find xdr -type f -exec sed -i '' 's/from;/from_;/g' {} + +REPLACE_DOCS := sed -i '' '/stellar_sdk\.xdr/,$$d' docs/en/api.rst +else SED := sed -ifeq ($(UNAME), Darwin) - SED := sed -i '' +REPLACE_KEYWORD_COMMAND := find xdr -type f -exec sed -i 's/from;/from_;/g' {} \; +REPLACE_DOCS := sed -i '/stellar_sdk\.xdr/,$$d' docs/en/api.rst endif # default target does nothing @@ -59,13 +64,11 @@ clean: .PHONY: clean format: - autoflake --in-place --ignore-init-module-imports --remove-all-unused-imports --recursive . - isort . - black . + pre-commit run --all-file .PHONY: format replace-xdr-keywords: - find xdr -type f -exec $(SED) 's/from;/from_;/g' {} + + $(REPLACE_KEYWORD_COMMAND) .PHONY: replace-xdr-keywords xdr-generate: $(XDRS) @@ -78,7 +81,8 @@ xdr-generate: $(XDRS) --namespace stellar \ --output stellar_sdk/xdr \ $(XDRS)' - $(SED) '/stellar_sdk\.xdr/,$$d' docs/en/api.rst + pip install -e . + $(REPLACE_DOCS) python docs/gen_xdr_api.py >> docs/en/api.rst .PHONY: xdr-generate @@ -91,5 +95,5 @@ xdr-clean: rm stellar_sdk/xdr/*.py || true .PHONY: xdr-clean -xdr-update: xdr-clean xdr-generate format +xdr-update: xdr-clean xdr-generate .PHONY: xdr-update \ No newline at end of file