diff --git a/.devcontainer/non-root-user/Dockerfile b/.devcontainer/non-root-user/Dockerfile index 80df6d25baea0c7c2c5fd31e6727a814060cba72..647e39a5dce20fda4805c8578bceaa9e13d2bf52 100644 --- a/.devcontainer/non-root-user/Dockerfile +++ b/.devcontainer/non-root-user/Dockerfile @@ -5,11 +5,11 @@ LABEL user.name="vscode" # https://apt.llvm.org/ RUN dnf --best --assumeyes update && \ dnf -y install \ - python3.11 python3.11-pip \ + python3.11 python3.11-pip python3.11-devel \ gcc make cmake \ git \ zsh \ - which util-linux-user wget sudo passwd \ + which util-linux-user wget sudo passwd unzip \ clang lldb lld clang-tools-extra && \ dnf clean all @@ -24,25 +24,35 @@ RUN dnf -y install 'dnf-command(config-manager)' && \ dnf -y install cuda-nvcc-12-4 && \ dnf clean all -RUN useradd -ms /bin/zsh vscode && \ - usermod -aG wheel vscode - -WORKDIR /workspaces -USER vscode - -RUN python3.11 -m venv /workspaces/venv - -COPY requirements.txt /workspaces/requirements.txt -COPY requirements-dev.txt /workspaces/requirements-dev.txt - -RUN sh -c "$(curl -fsSL https://install.ohmyz.sh/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended - -RUN echo 'export PATH="/usr/local/cuda-12.4/bin${PATH:+:${PATH}}"' >>~/.zshrc && \ - echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"' >>~/.zshrc && \ - source /workspaces/venv/bin/activate && \ +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Create the user +RUN groupadd --gid $USER_GID $USERNAME && \ + useradd --uid $USER_UID --gid $USER_GID -ms /bin/zsh $USERNAME && \ + echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \ + chmod 0440 /etc/sudoers.d/$USERNAME + +USER $USERNAME + +RUN export REMOTE="https://gitee.com/mirrors/oh-my-zsh" && \ + export COMMAND="$(curl -fsSL ${REMOTE}/raw/master/tools/install.sh)" && \ + sh -c "${COMMAND}" "" --unattended && \ + echo ${REMOTE} && \ + echo ${COMMAND} && \ + echo 'export PATH="/usr/local/cuda-12.4/bin${PATH:+:${PATH}}"' >>~/.zshrc && \ + echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"' >>~/.zshrc + +RUN python3.11 -m venv ~/venv +COPY requirements.txt /home/vscode/requirements.txt +COPY requirements-dev.txt /home/vscode/requirements-dev.txt +RUN source ~/venv/bin/activate && \ + # echo 'source ~/venv/bin/activate' >> ~/.zshrc && \ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \ pip install --upgrade pip && \ - pip install -r requirements-dev.txt && \ - rm -rf /workspaces/requirements.txt /workspaces/requirements-dev.txt && \ - echo "hi" - # sudo chown vscode:vscode -R /workspaces + pip install -r ~/requirements-dev.txt && \ + rm -rf ~/requirements.txt ~/requirements-dev.txt + +RUN curl -o /home/vscode/vscode-lldb.vsix https://vadimcn.gallery.vsassets.io/_apis/public/gallery/publisher/vadimcn/extension/vscode-lldb/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage && \ + echo "find ~ -name lldb | grep -q . || code --install-extension /home/vscode/vscode-lldb.vsix" >> ~/.zshrc diff --git a/.devcontainer/non-root-user/devcontainer.json b/.devcontainer/non-root-user/devcontainer.json index 8d98e5dc7681d403f220a8e5529dc24d0518eea8..948e76fe28c38c633a034e3259795e3fc7106e23 100644 --- a/.devcontainer/non-root-user/devcontainer.json +++ b/.devcontainer/non-root-user/devcontainer.json @@ -6,18 +6,22 @@ }, "runArgs": ["--userns=keep-id"], // needed for podman "remoteUser": "vscode", - "postCreateCommand": "", "customizations": { "vscode": { "extensions": [ "llvm-vs-code-extensions.vscode-clangd", - "vadimcn.vscode-lldb", + // "vadimcn.vscode-lldb", "ms-toolsai.jupyter", "ziruiwang.nvidia-monitor", "esbenp.prettier-vscode", "ms-python.python", - "charliermarsh.ruff" - ] + "charliermarsh.ruff", + "josetr.cmake-language-support-vscode", + "tamasfe.even-better-toml" + ], + "settings": { + "python.defaultInterpreterPath": "/home/vscode/venv/bin/python" + } } } } diff --git a/.gitignore b/.gitignore index b807799e8b76248482f96673e17d5a5bdb5865a0..78e55d41ddd78a889c4e8ecccb4bc794af4b86b7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,9 @@ __pycache__/ build/ .*cache/ .venv/ +.nox/ .coverage +*.so # dev container related .dotnet/ diff --git a/.vscode/settings.json b/.vscode/settings.json index d1c34ab1da32839e1df9deb71734e95fc5725d60..931c752e0e08715de9f21bbdb4f20507ede5fa85 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "editor.rulers": [88], - "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, "[python]": { "editor.codeActionsOnSave": { @@ -15,6 +14,10 @@ }, "notebook.formatOnSave.enabled": true, "notebook.lineNumbers": "on", + "notebook.defaultFormatter": "charliermarsh.ruff", + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "[cpp]": { "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" }, @@ -38,7 +41,6 @@ "--function-arg-placeholders=false", "--compile-commands-dir=build" ], - "clangd.path": "clangd-17", "jupyter.debugJustMyCode": false, "debugpy.debugJustMyCode": false, "ruff.fixAll": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index e54ab69e60f5dcde1bf235cf2fe5bebf9220934b..e4ff384b43e32cf65f5a822bff2c4d6c81dbd22b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,6 @@ project( # set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # include(GNUInstallDirs) -add_subdirectory(cpp) +add_subdirectory(cxx) -add_subdirectory(python/myproj/simulation/_csrc) +add_subdirectory(src/myproj/simulation/_csrc) diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb index f47fc7e9cbf9685eda7389c76d4cac9c45121b98..8eb643593325242b353bf8640d708a38dc1417e4 100644 --- a/notebooks/example.ipynb +++ b/notebooks/example.ipynb @@ -7,11 +7,9 @@ "outputs": [], "source": [ "import myproj.simulation as ms\n", - "import numpy as np\n", "\n", "print(ms.add(1, 2))\n", - "print(ms.complex(1, 2))\n", - "print(np.array([1, 2, 3]))" + "print(ms.complexf(1, 2))" ] }, { @@ -94,7 +92,7 @@ ], "metadata": { "kernelspec": { - "display_name": "dingxf", + "display_name": "venv", "language": "python", "name": "python3" }, @@ -108,7 +106,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/noxfile.py b/noxfile.py index b2ced962d3aa0525fc42950da8ac5f65f9577ab0..93b3ea7878961dd51974fbee54b54a36ebc364fb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -26,27 +26,18 @@ def dev(session: nox.Session) -> None: Prepare a .venv folder. """ - library_output_dir = DIR / "python" / "myproj" / "simulation" / "_csrc" + library_output_dir = DIR / "src" / "myproj" / "simulation" / "_csrc" + print(sys.path) + session.run("which", "pip") - session.run(sys.executable, "-m", "venv", ".venv") session.run( - ".venv/bin/pip", - "install", - "scikit-build-core[pyproject]", - "pybind11", - "pip>=23", - "nox", - "pytest", - "pytest-cov", - "pre-commit", - ) - session.run( - ".venv/bin/pip", + "pip", "install", "--no-build-isolation", "--check-build-dependencies", "-ve", ".", + f"-Ccmake.define.Python_ROOT_DIR={sys.exec_prefix}", "-Ccmake.define.CMAKE_EXPORT_COMPILE_COMMANDS=1", f"-Ccmake.define.CMAKE_LIBRARY_OUTPUT_DIRECTORY={library_output_dir}", "-Cbuild-dir=build", diff --git a/pyproject.toml b/pyproject.toml index af7030298f3743e1dccc3b2d055ac42357b4bc97..a440691c30725064f9b920d15b9be9bb342bb2b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ Discussions = "https://github.com/organization/package/discussions" Changelog = "https://package.readthedocs.io/en/latest/changelog.html" [tool.scikit-build.wheel.packages] -"myproj/simulation" = "python/myproj/simulation" +"myproj/simulation" = "src/myproj/simulation" [tool.scikit-build.wheel] install-dir = "myproj/simulation" @@ -64,7 +64,7 @@ select = [ [tool.pytest.ini_options] minversion = "7" -testpaths = ["python/tests"] +testpaths = ["src/tests"] python_files = "test_*.py" python_classes = "Test*" python_functions = "test_*" diff --git a/requirements-dev.txt b/requirements-dev.txt index f7d4e4a2c4f312298656a5a1cad0be8b6b49b962..1969b76703734a2be900baec37f435b0be50c0b7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ -r requirements.txt +jupyter nox pre-commit pytest diff --git a/src/myproj/simulation/_csrc/_hello.cpython-310-x86_64-linux-gnu.so b/src/myproj/simulation/_csrc/_hello.cpython-310-x86_64-linux-gnu.so deleted file mode 100755 index 01bcd3dfac649dbc6500a2a5c2a163a864d21ba9..0000000000000000000000000000000000000000 Binary files a/src/myproj/simulation/_csrc/_hello.cpython-310-x86_64-linux-gnu.so and /dev/null differ diff --git a/src/myproj/simulation/_csrc/libcomplexf.so b/src/myproj/simulation/_csrc/libcomplexf.so deleted file mode 100755 index f12fc94e0546749c8bd06eb95d8a270e902bc11b..0000000000000000000000000000000000000000 Binary files a/src/myproj/simulation/_csrc/libcomplexf.so and /dev/null differ diff --git a/src/myproj/simulation/_csrc/libhello.so b/src/myproj/simulation/_csrc/libhello.so deleted file mode 100755 index 914f56c088e597c1a743da262b051b2aa0718cac..0000000000000000000000000000000000000000 Binary files a/src/myproj/simulation/_csrc/libhello.so and /dev/null differ