Skip to content

Commit af461cc

Browse files
twslpre-commit-ci[bot]BordaSkafteNickiakihironitta
authored
Devcontainer configuration (#621)
* First Devcontainer configuration * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix manifest missing error * Updated CHANGELOG * Set default interpreter * Add docs * Add docs support * Update devcontainer.json * drop yapf * Apply suggestions from code review Co-authored-by: Aki Nitta <[email protected]> * Add sorting * Fix pre-commit python version * Use existing configurations * Moved pip dependencies to docker image * Update tabs * Create docker_devcontainer.yml * Update .github/workflows/docker_devcontainer.yml * Apply suggestions from code review * Update .github/workflows/docker_devcontainer.yml * Create ci_docker.yml * Update ci_docker.yml * Update ci_docker.yml * Update docker_devcontainer.yml * Update ci_docker.yml * Update docker_devcontainer.yml * Update .github/workflows/ci_docker.yml Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Nicki Skafte Detlefsen <[email protected]> Co-authored-by: Aki Nitta <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Justus Schock <[email protected]>
1 parent e0588f2 commit af461cc

File tree

8 files changed

+196
-1
lines changed

8 files changed

+196
-1
lines changed

.devcontainer/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/python-3/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Python version: 3, 3.9, 3.8, 3.7, 3.6
4+
ARG VARIANT="3.9"
5+
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
6+
7+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
8+
ARG NODE_VERSION="none"
9+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
10+
11+
COPY requirements/ /tmp/pip-tmp/requirements/
12+
COPY requirements.txt /tmp/pip-tmp/
13+
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements/devel.txt -r /tmp/pip-tmp/requirements/docs.txt \
14+
&& rm -rf /tmp/pip-tmp
15+
16+
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
17+
# COPY requirements.txt /tmp/pip-tmp/
18+
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
19+
# && rm -rf /tmp/pip-tmp
20+
21+
# [Optional] Uncomment this section to install additional OS packages.
22+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
23+
# && apt-get -y install --no-install-recommends <your-package-list-here>
24+
25+
# [Optional] Uncomment this line to install global node packages.
26+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

.devcontainer/devcontainer.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"image": "pytorchlightning/metrics-dev"
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
"context": "..",
9+
"args": {
10+
// Update 'VARIANT' to pick a Python version: 3, 3.6, 3.7, 3.8, 3.9
11+
"VARIANT": "3.9",
12+
// Options
13+
"NODE_VERSION": "none"
14+
}
15+
},
16+
"runArgs": [
17+
// Enable GPU passthrough, requires WSL2 on Windows
18+
//"--gpus=all",
19+
],
20+
// Set *default* container specific settings.json values on container create.
21+
"settings": {
22+
"editor.formatOnSave": true,
23+
"editor.rulers": [
24+
120
25+
],
26+
"python.pythonPath": "/usr/local/bin/python",
27+
"python.defaultInterpreterPath": "/usr/local/bin/python",
28+
"python.languageServer": "Pylance",
29+
"python.autoComplete.addBrackets": true,
30+
"python.analysis.autoImportCompletions": true,
31+
"python.analysis.completeFunctionParens": true,
32+
"python.analysis.autoSearchPaths": true,
33+
"python.analysis.useImportHeuristic": true,
34+
"python.sortImports": true,
35+
"python.sortImports.args": [
36+
"--settings-path=${workspaceFolder}/pyproject.toml",
37+
],
38+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
39+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
40+
"python.formatting.provider": "black",
41+
"python.formatting.blackArgs": [
42+
"--config=${workspaceFolder}/pyproject.toml"
43+
],
44+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
45+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
46+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
47+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
48+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
49+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
50+
"python.linting.enabled": true,
51+
"python.linting.pylintEnabled": false,
52+
"python.linting.flake8Enabled": true,
53+
"python.linting.flake8Args": [
54+
"--config=${workspaceFolder}/setup.cfg",
55+
"--verbose"
56+
],
57+
"python.testing.pytestArgs": [
58+
"tests"
59+
],
60+
"python.testing.unittestEnabled": false,
61+
"python.testing.pytestEnabled": true,
62+
"restructuredtext.confPath": "${workspaceFolder}/docs/source",
63+
"restructuredtext.builtDocumentationPath": "${workspaceFolder}/docs/build",
64+
"restructuredtext.languageServer.disabled": false,
65+
"[python]": {
66+
"editor.codeActionsOnSave": {
67+
"source.organizeImports": true,
68+
}
69+
}
70+
},
71+
// Add the IDs of extensions you want installed when the container is created.
72+
"extensions": [
73+
"ms-python.python",
74+
"ms-python.vscode-pylance",
75+
"visualstudioexptteam.vscodeintellicode",
76+
"kevinrose.vsc-python-indent",
77+
"littlefoxteam.vscode-python-test-adapter",
78+
"hbenl.vscode-test-explorer",
79+
"medo64.render-crlf",
80+
"shardulm94.trailing-spaces",
81+
"njqdev.vscode-python-typehint",
82+
"lextudio.restructuredtext",
83+
"trond-snekvik.simple-rst",
84+
],
85+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
86+
// "forwardPorts": [],
87+
// Use 'postCreateCommand' to run commands after the container is created.
88+
"postCreateCommand": "pre-commit install",
89+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
90+
"remoteUser": "vscode"
91+
}

.github/workflows/ci_docker.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI Docker
2+
3+
on: # Trigger the workflow on push or pull request, but only for the master branch
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
paths:
9+
- "requirements/*"
10+
- ".devcontainer/*"
11+
- "environment.yml"
12+
- "requirements.txt"
13+
- ".github/workflows/*docker*.yml"
14+
- "setup.py"
15+
16+
jobs:
17+
build-PL:
18+
runs-on: ubuntu-20.04
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
python_version: ["3.9"]
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Build Devcontainer Docker
28+
# publish master/release
29+
uses: docker/build-push-action@v2
30+
with:
31+
build-args: |
32+
VARIANT=${{ matrix.python_version }}
33+
file: .devcontainer/Dockerfile
34+
push: false
35+
timeout-minutes: 50
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Build & Push Docker Devcontainer"
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
build-devcontainer:
9+
runs-on: ubuntu-20.04
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python_version: ["3.9"]
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Login to DockerHub
19+
uses: docker/login-action@v1
20+
with:
21+
username: ${{ secrets.DOCKER_USERNAME }}
22+
password: ${{ secrets.DOCKER_PASSWORD }}
23+
- name: Build and Push Devcontainer
24+
# publish master/release
25+
uses: docker/build-push-action@v2
26+
with:
27+
build-args: |
28+
VARIANT=${{ matrix.python_version }}
29+
file: .devcontainer/Dockerfile
30+
push: true
31+
tags: pytorchlightning/metrics-dev
32+
timeout-minutes: 50

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
default_language_version:
16-
python: python3.8
16+
python: python3.9
1717

1818
ci:
1919
autofix_prs: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `SQuAD` ([#623](https://github.com/PyTorchLightning/metrics/pull/623))
1818
- `CHRFScore` ([#641](https://github.com/PyTorchLightning/metrics/pull/641))
1919

20+
- Add a default VS Code devcontainer configuration ([#621](https://github.com/PyTorchLightning/metrics/pull/621))
2021

2122
- Added `MinMaxMetric` to wrappers ([#556](https://github.com/PyTorchLightning/metrics/pull/556))
2223

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exclude *.yml
3939
exclude *.yaml
4040
exclude Makefile
4141

42+
prune .devcontainer
4243
prune .git
4344
prune .github
4445
prune .circleci

docs/source/pages/quickstart.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ Implementing your own metric is as easy as subclassing an :class:`torch.nn.Modul
103103
3. Implement ``compute`` method, where the final metric computations happens
104104

105105
For practical examples and more info about implementing a metric, please see this :ref:`page <implement>`.
106+
107+
108+
Development Environment
109+
~~~~~~~~~~~~~~~~~~~~~~~
110+
111+
TorchMetrics provides a `Devcontainer <https://code.visualstudio.com/docs/remote/containers>`_ configuration for `Visual Studio Code <https://code.visualstudio.com/>`_ to use a `Docker container <https://www.docker.com/>`_ as a pre-configured development environment.
112+
This avoids struggles setting up a development environment and makes them reproducible and consistent.
113+
Please follow the `installation instructions <https://code.visualstudio.com/docs/remote/containers#_installation>`_ and make yourself familiar with the `container tutorials <https://code.visualstudio.com/docs/remote/containers-tutorial>`_ if you want to use them.
114+
In order to use GPUs, you can enable them within the ``.devcontainer/devcontainer.json`` file.

0 commit comments

Comments
 (0)