1

Background

I am building a project using Django, Docker, Travis CI and Flake8. My flake8 file:

[flake8]
max-line-length = 119
exclude =
    migrations,
    __pycache__,
    manage.py,
    settings.py,
    env

When I run local flake8 tests using:

docker-compose exec app python manage.py test && flake8

I receive an ok message with no error messages. My code is good!

The problem

When I push my code to master which automatically starts Travis CI, the Travis build fails due to the following errors:

./project/settings.py:94:80: E501 line too long (91 > 79 characters)
./project/settings.py:97:80: E501 line too long (81 > 79 characters)
./project/settings.py:100:80: E501 line too long (82 > 79 characters)
./project/settings.py:103:80: E501 line too long (83 > 79 characters)
./core/models.py:7:80: E501 line too long (93 > 79 characters)
./core/models.py:13:80: E501 line too long (104 > 79 characters)
./core/migrations/0001_initial.py:18:80: E501 line too long (126 > 79 characters)
The command "docker-compose run app sh -c "python manage.py test && flake8"" exited with 1.

My flake8 file specifically states that the max line length is 119 so these errors should not be happening (like they are not when running the test on my local machine).

Does anyone know whats going on?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Toms Code
  • 1,439
  • 3
  • 15
  • 34
  • is the problem the same as your other problem? https://stackoverflow.com/questions/60865887/exclude-env-directory-from-flake8-tests – anthony sottile Mar 26 '20 at 16:25
  • No its a different problem? – Toms Code Mar 26 '20 at 17:23
  • hmmm, could you show the layout of your repository and perhaps a link to it if it's open source? – anthony sottile Mar 26 '20 at 17:25
  • if it's this one, it's because you never copy the flake8 configuration into your image: https://github.com/DevelopwithTom/simple_inventory_api/blob/master/Dockerfile (if you rebuild locally you should see the same issue) – anthony sottile Mar 26 '20 at 17:26
  • Hi Anthony, sorry for some reason I'm not getting notifications when you comment! It is that repo you're correct. I'm not getting the same issue locally I think because I've set the maximum max-line-length = 119 in the flake8 file – Toms Code Mar 26 '20 at 19:20
  • probably due to either: an out of date build, hot mounting of your current directory. your dockerfile never does `COPY . .` so your `.flake8` file is never put into the image – anthony sottile Mar 26 '20 at 19:21
  • Thats worked great. Thank you. I added COPY . . to my dockerfile instead of the mkdir command. You can make this an answer that I can accept if you like? – Toms Code Mar 26 '20 at 19:33

1 Answers1

2

there wasn't enough information in the question so I went digging into OP's github

this was their dockerfile when the question was asked:

FROM python:3.9.0a5-alpine3.10
MAINTAINER Tom Mac

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client
RUN apk add --update --no-cache --virtual .tmp-build-deps \
    gcc libc-dev linux-headers postgresql-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps

RUN mkdir /app
WORKDIR /app
COPY ./app /app

RUN adduser -D user
USER user

their flake8 configuration was at .flake8 in the root of their repository

since this file was not part of their image (nothing COPYd it in), it was not being respected while linting

adding this file into the image (the easiest way being COPY . . which adds everything) fixes this


what I suspect happened:

  • in Exclude .env directory from flake8 tests? it was pointed out that the flake8 configuration was in the wrong place
  • OP probably moved the configuration from app/.flake8 (which is in the image listed above)
  • OP then either: (1) didn't rebuild the image after doing that or (2) has some type of local mounting setup where . is mounted into the container at runtime

either way, rebuilding and adding COPY . . should fix this

anthony sottile
  • 61,815
  • 15
  • 148
  • 207