Skip to content

Commit

Permalink
Switch to ruff format & add VS Code devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
relud committed Jan 5, 2024
1 parent 82bcae0 commit 9ebe1ba
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 49 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/devcontainers/python:3.11-bullseye@sha256:105bf6a63ab025206f019a371a735fec6553db0be520030c7a2fd0e002947232

WORKDIR /app

# Install Debian packages
RUN apt-get update && \
apt-get install -y ripgrep tig

# Install Python dependencies
COPY requirements.txt /app/
RUN pip install -U 'pip>=20' && \
pip install --no-cache-dir --no-deps -r requirements.txt && \
pip install --no-cache-dir ipython && \
pip check --disable-pip-version-check
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Eliot",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "devcontainer",
"runServices": [
"devcontainer"
],
"shutdownAction": "none",
"workspaceFolder": "/app",
"customizations": {
"vscode": {
"settings": {
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"extensions": [
"charliermarsh.ruff"
]
}
}
}
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ help:
.docker-build:
make build

.devcontainer-build:
make devcontainerbuild

.env:
./bin/cp-env-file.sh

Expand All @@ -47,6 +50,15 @@ build: .env ## | Build docker images.
run: .env .docker-build ## | Run eliot and services.
${DC} up eliot fakesentry

.PHONY: devcontainerbuild
devcontainerbuild: .env .docker-build .devcontainer-build ## | Build VS Code development container.
${DC} build devcontainer
touch .devcontainer-build

.PHONY: devcontainer
devcontainer: .env .docker-build ## | Run VS Code development container.
${DC} up --detach devcontainer

.PHONY: stop
stop: .env ## | Stop docker containers.
${DC} stop
Expand Down
11 changes: 5 additions & 6 deletions bin/run_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ FILES="bin eliot tests"
PYTHON_VERSION=$(python --version)

if [[ $1 == "--fix" ]]; then
echo ">>> black fix (${PYTHON_VERSION})"
black $FILES
echo ">>> ruff fix (${PYTHON_VERSION})"
ruff format $FILES
ruff check --fix $FILES

else
echo ">>> ruff (${PYTHON_VERSION})"
cd /app
ruff $FILES

echo ">>> black (${PYTHON_VERSION})"
black --check $FILES
ruff check $FILES
ruff format --check $FILES

echo ">>> license check (${PYTHON_VERSION})"
if [[ -d ".git" ]]; then
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ services:
links:
- fakesentry

devcontainer:
extends:
service: test
build:
dockerfile: .devcontainer/Dockerfile
image: eliot-devcontainer
entrypoint: ["sleep", "inf"]

# https://github.com/willkg/kent
fakesentry:
build:
Expand Down
49 changes: 47 additions & 2 deletions docs/dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ All Python code files should have an MPL v2 header at the top::
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


We use `black <https://black.readthedocs.io/en/stable/>`_ to reformat Python
code.
We use `ruff <https://docs.astral.sh/ruff/>`_ to reformat Python code.


To lint all the code, do:
Expand Down Expand Up @@ -335,3 +334,49 @@ the testshell:
app@xxx:/app$ pytest tests/test_app.py
<pytest output>
How to
======

How to set up a development container for VS Code
-------------------------------------------------
The repository contains configuration files to build a
`development container <https://containers.dev/>`_ in the `.devcontainer`
directory. If you have the "Dev Containers" extension installed in VS Code, you
should be prompted whether you want to reopen the folder in a container on
startup. You can also use the "Dev containers: Reopen in container" command
from the command palette. The container has all Python requirements installed.
IntelliSense, type checking, code formatting with Ruff and running the tests
from the test browser are all set up to work without further configuration.

VS Code should automatically start the container, but it may need to be built on
first run:

.. code-block:: shell
$ make devcontainerbuild
How to change settings in your local dev environment
----------------------------------------------------
Edit the ``.env`` file and add/remove/change settings. These environment
variables are used by make and automatically included by docker compose.

If you are using a VS Code development container for other repositories such as
`tecken <https://github.com/mozilla-services/tecken>`_ or
`socorro <https://github.com/mozilla-services/socorro>`_, you may need to
change the default ports exposed by docker compose to avoid conflicts with
similar services, for example:

.. code-block:: shell
EXPOSE_ELIOT_PORT=8100
EXPOSE_SENTRY_PORT=8190
EXPOSE_STATSD_PORT=8181
If you are using a development container for VS Code, you make need to restart
the container to pick up changes:

.. code-block:: shell
$ make devcontainer
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ exclude = [
]
per-file-ignores = {}

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
Expand All @@ -30,11 +29,6 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py311"


[tool.black]
line-length = 88
target-version = ["py311"]


[tool.pytest.ini_options]
norecursedirs = [".cache", "__pycache__"]
testpaths = "tests/"
Expand Down
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
backoff==2.2.1
black==23.11.0
boltons==23.1.1
click==8.1.7
datadog==0.47.0
Expand Down
34 changes: 0 additions & 34 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ backoff==2.2.1 \
--hash=sha256:03f829f5bb1923180821643f8753b0502c3b682293992485b0eef2807afa5cba \
--hash=sha256:63579f9a0628e06278f7e47b7d7d5b6ce20dc65c5e96a6f3ca99a6adca0396e8
# via -r requirements.in
black==23.11.0 \
--hash=sha256:250d7e60f323fcfc8ea6c800d5eba12f7967400eb6c2d21ae85ad31c204fb1f4 \
--hash=sha256:2a9acad1451632021ee0d146c8765782a0c3846e0e0ea46659d7c4f89d9b212b \
--hash=sha256:412f56bab20ac85927f3a959230331de5614aecda1ede14b373083f62ec24e6f \
--hash=sha256:421f3e44aa67138ab1b9bfbc22ee3780b22fa5b291e4db8ab7eee95200726b07 \
--hash=sha256:45aa1d4675964946e53ab81aeec7a37613c1cb71647b5394779e6efb79d6d187 \
--hash=sha256:4c44b7211a3a0570cc097e81135faa5f261264f4dfaa22bd5ee2875a4e773bd6 \
--hash=sha256:4c68855825ff432d197229846f971bc4d6666ce90492e5b02013bcaca4d9ab05 \
--hash=sha256:5133f5507007ba08d8b7b263c7aa0f931af5ba88a29beacc4b2dc23fcefe9c06 \
--hash=sha256:54caaa703227c6e0c87b76326d0862184729a69b73d3b7305b6288e1d830067e \
--hash=sha256:58e5f4d08a205b11800332920e285bd25e1a75c54953e05502052738fe16b3b5 \
--hash=sha256:698c1e0d5c43354ec5d6f4d914d0d553a9ada56c85415700b81dc90125aac244 \
--hash=sha256:6c1cac07e64433f646a9a838cdc00c9768b3c362805afc3fce341af0e6a9ae9f \
--hash=sha256:760415ccc20f9e8747084169110ef75d545f3b0932ee21368f63ac0fee86b221 \
--hash=sha256:7f622b6822f02bfaf2a5cd31fdb7cd86fcf33dab6ced5185c35f5db98260b055 \
--hash=sha256:cf57719e581cfd48c4efe28543fea3d139c6b6f1238b3f0102a9c73992cbb479 \
--hash=sha256:d136ef5b418c81660ad847efe0e55c58c8208b77a57a28a503a5f345ccf01394 \
--hash=sha256:dbea0bb8575c6b6303cc65017b46351dc5953eea5c0a59d7b7e3a2d2f433a911 \
--hash=sha256:fc7f6a44d52747e65a02558e1d807c82df1d66ffa80a601862040a43ec2e3142
# via -r requirements.in
boltons==23.1.1 \
--hash=sha256:80a8cd930ff21fbf03545b9863e5799d0c3e7e0e3b2546bdaf2efccd7b3708cc \
--hash=sha256:d2cb2fa83cf2ebe791be1e284183e8a43a1031355156a968f8e0a333ad2448fc
Expand Down Expand Up @@ -118,7 +98,6 @@ click==8.1.7 \
--hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
# via
# -r requirements.in
# black
# pip-tools
datadog==0.47.0 \
--hash=sha256:47be3b2c3d709a7f5b709eb126ed4fe6cc7977d618fe5c158dd89c2a9f7d9916 \
Expand Down Expand Up @@ -325,23 +304,14 @@ msgpack==1.0.7 \
--hash=sha256:f9a7c509542db4eceed3dcf21ee5267ab565a83555c9b88a8109dcecc4709002 \
--hash=sha256:ff1d0899f104f3921d94579a5638847f783c9b04f2d5f229392ca77fba5b82fc
# via -r requirements.in
mypy-extensions==0.4.3 \
--hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \
--hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8
# via black
packaging==23.0 \
--hash=sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2 \
--hash=sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97
# via
# black
# build
# gunicorn
# pytest
# sphinx
pathspec==0.9.0 \
--hash=sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a \
--hash=sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1
# via black
pep517==0.12.0 \
--hash=sha256:931378d93d11b298cf511dd634cf5ea4cb249a28ef84160b3247ee9afb4e8ab0 \
--hash=sha256:dd884c326898e2c6e11f9e0b64940606a93eb10ea022a2e067959f3a110cf161
Expand All @@ -350,10 +320,6 @@ pip-tools==7.3.0 \
--hash=sha256:8717693288720a8c6ebd07149c93ab0be1fced0b5191df9e9decd3263e20d85e \
--hash=sha256:8e9c99127fe024c025b46a0b2d15c7bd47f18f33226cf7330d35493663fc1d1d
# via -r requirements.in
platformdirs==2.4.1 \
--hash=sha256:1d7385c7db91728b83efd0ca99a5afb296cab9d0ed8313a45ed8ba17967ecfca \
--hash=sha256:440633ddfebcc36264232365d7840a970e75e1018d15b4327d11f91909045fda
# via black
pluggy==1.0.0 \
--hash=sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159 \
--hash=sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3
Expand Down

0 comments on commit 9ebe1ba

Please sign in to comment.