PyLint Doesn't work on GitLab (Python 3.X) - python-3.x

I'm having a problem with Pylint on gitlab. For some reason, it crashes on the middle of the process of analysing the code..
But doesn't say nothing to me, only crashes..
Here are some log:
core/db/sql/pgsql/__init__.py:162:8: E1101: Instance of 'Session' has no 'close' member (no-member)
/core/db/sql/pgsql/__init__.py:165:4: C0116: Missing function or method docstring (missing-function-docstring)
/core/db/sql/pgsql/__init__.py:166:8: E1101: Instance of 'Session' has no 'commit' member (no-member)
/core/db/sql/pgsql/__init__.py:168:4: C0116: Missing function or method docstring (missing-function-docstring)
/core/db/sql/pgsql/__init__.py:169:8: E1101: Instance of 'Session' has no 'rollback' member (no-member)
/core/db/sql/pgsql/__init__.py:171:4: C0116: Missing function or method docstring (missing-function-docstring)
/core/db/sql/pgsql/__init__.py:174:4: C0116: Missing function or method docstring (missing-function-docstring)/bin/bash: line 98: 43 Segmentation fault (core dumped) pylint /
44 Done | tee ./pylint/pylint.log
The following messages were raised:
- fatal message issued
- error message issued
- refactor message issued
Fatal messages detected. Failing...
Running after_script
00:02
196
Uploading artifacts for failed job
00:02
198 ERROR: Job failed: exit code 1
Here are the .gitlab-cy.yml configuration file:
image: "python:3.8.5"
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
cache:
paths:
- .cache/pip
- venv/
before_script:
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install -r requirements.txt
stages:
- Static Analysis
- Test
flake8:
stage: Static Analysis
script:
- flake8 project/
pylint:
stage: Static Analysis
script:
- mkdir ./pylint
- pylint project/ | tee ./pylint/pylint.log || pylint-exit $?
- PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
- anybadge --label=Pylint --file=pylint/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green
- echo "Pylint score is $PYLINT_SCORE"
artifacts:
paths:
- ./pylint/
coverage:
stage: Test
script:
- coverage erase
- $(coverage run -m unittest discover -s tests | tee cov.log || exit 0)
- coverage report -m
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
artifacts:
paths:
- ./pylint/
when: always
With this erros codes, I didn't find nothing on web..
And I have others projects on gitlab with the same configuration, and they run without any problem.
Does anyone already seen this?
Thanks!!

I do not see how are you executing the pylint. Please provide your gitlab-ci.yml file. But I had the very similar problem and I solved it by adding pylint-exit library:
pylint --disable=W0611,C0411,C0301 tests > ./pylint/tests.log || pylint-exit $?

Related

.gitlab-ci.yml extends Keyword does not Include Earlier Section

I am trying to use the extends keyword in the .gitlab-ci.yml of a GitLab Python project. It's not working, and I can't figure out why not.
I am using GitLab's CI/CD framework to test my Python project. The project has unit tests written with pytest and the following Dockerfile.
# syntax=docker/dockerfile:1
FROM python:3.9
WORKDIR /install
COPY . .
RUN pip install --no-cache-dir --upgrade .
EXPOSE 8000
CMD ["uvicorn", "sample_api.api:app"]
When I have the following .gitlab-ci.yml, GitLab's CI/CD system starts the python:3.9.16-slim-buster image and successfully runs the test job.
include:
- template: Auto-DevOps.gitlab-ci.yml
test:
stage: test
image: python:3.9.16-slim-buster
before_script:
- pip install .
script:
- pytest tests/unit
services: []
However, the test job fails when I change it to use the extends keyword like so.
include:
- template: Auto-DevOps.gitlab-ci.yml
.tests:
stage: test
image: python:3.9.16-slim-buster
before_script:
- pip install .
services: []
test:
extends: .tests
script:
- pytest tests/unit
The log of the failed test job looks like this.
...
Preparing the "docker" executor
00:11
Using Docker executor with image gliderlabs/herokuish:latest ...
...
Executing "step_script" stage of the job script
00:03
Using docker image sha256:686c154e24a2373406bdf9c8f44904b5dbe5cd36060c61d3da137086389d18d3 for gliderlabs/herokuish:latest with digest gliderlabs/herokuish#sha256:5d5914135908a234c20eec80daaa6a386bfa74293310bc0c79148fe7a7e4a926 ...
$ pip install .
/bin/bash: line 154: pip: command not found
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1
It is failing because the default herokuish:latest image is being used instead of python:3.9.16-slim-buster. It appears that the .tests section is never used.
I assume there's something wrong with my syntax, but it seems so simple and I can't figure out what it is.

Gitlab Pipeline: lftp runs into a timeout

I received a notification a few days ago from my gitlab runner about a failed pipeline.
The Pipeline was working normally and nothing got changed, which makes everything a bit harder to investigate.
The specific command which causes the timeout of 1 hour is the following:
lftp -e "set ftp:ssl-allow no; mirror -R dist/ ./; quit;" -u $USER_TEST,$PASSWORD_TEST $HOST_TEST
This was working fine. I tried to troubleshoot this problem. There are a plenty of reasons out there why the timeout happens. However none of it was solving my problem.
A short brief of what the git pipeline does:
building an angular app (the dist folder's size is about 750kB)
deploying it on a server using ftp credentials
I manually went through the pipeline steps, hoping to replicate the bug, but it was working fine.
.gitlab-ci.yml:
image: node:14.15.3-alpine
cache:
paths:
- node_modules/
stages:
- build
- deploy
#DEV Stage
build_stage_dev:
stage: build
only:
refs:
- develop
cache:
paths:
- dist/
script:
- npm install --legacy-peer-deps
- npm install -g #angular/cli#11.0.5
- ng build --build-optimizer
deploy_stage_dev:
stage: deploy
environment: develop
only:
refs:
- develop
script:
- apk update && apk add openssh-client && apk add sshpass
- export SSHPASS=$PASSWORD_DEV
#command to remove all files first
#- sshpass -e ssh -o stricthostkeychecking=no $USER_DEV#$HOST_DEV rm -r /var/www/app/*
- sshpass -e scp -o stricthostkeychecking=no -r dist/* $USER_DEV#$HOST_DEV:/var/www/app
#TEST Stage
build_stage_test:
stage: build
only:
refs:
- test
cache:
paths:
- dist/
script:
- npm install --legacy-peer-deps
- npm install -g #angular/cli#11.0.5
- ng build --build-optimizer
deploy_stage_test:
stage: deploy
environment: test
only:
refs:
- test
script:
- apk update && apk add lftp
- lftp -e "set ftp:ssl-allow no; mirror -R dist/ ./; quit;" -u $USER_TEST,$PASSWORD_TEST $HOST_TEST
The DEV Stage (deploying with the ssh) is working fine. Only the test stage throws an error after 1 hour.
This is the error I receive on Gitlab: ERROR: Job failed: execution took longer than 1h0m0s seconds
Maybe any of you have experienced the same? or did "lftp" got an update and I am running into an enndless job?
Also I checked whether files are getting updated at all, the answer is no. I thought it could be an issue with "quit". But appearently nothing is getting transferred at all.

Gitlab CI empty script

I'm trying to setup a simple CI/CD environment on gitlab. My code is a python app that needs an external service for testing. The service is a container that does not require any script to be run. My gitlab-ci.yml file is:
stages:
- dynamodb
- testing
build_dynamo:
stage: dynamodb
image: amazon/dynamodb-local:latest
unit_tests:
stage: testing
image: python:3.10.3
before_script:
- pip install -r requirements_tests.txt
- export PYTHONPATH="${PYTHONPATH}:./src"
script:
- python -m unittest discover -s ./tests -p '*test*.py'
For this config I get an error
Found errors in your .gitlab-ci.yml: jobs build_dynamo config should
implement a script: or a trigger: keyword
Hiow can I solve this or implement the setup I need?
Using service solved this
unit_tests:
image: python:3.10.3-slim-buster
services:
- name: amazon/dynamodb-local:latest
before_script:
- pip install -r requirements_tests.txt
- export PYTHONPATH="${PYTHONPATH}:./src"
script:
- python -m unittest discover -s ./tests -p '*test*.py'
endpoint for the service is amazon-dynamo-local:8000 since "/" are changed to "-".
Reference: https://docs.gitlab.com/ee/ci/services/#accessing-the-services

Gitlab CI exit code 1 using with flake8

I don't understand why Job finished with exit code 1 in gitlab CI. If I don't use flake8 (f.ex run script line echo "hello world" > $FOLDER_NAME/my_test.txt) all good.
But I see that flake8 found errors in directory:
...
$ mkdir -p $FOLDER_NAME
$ flake8 --max-line-length=120 --ignore=W605,W504 --tee --output-file=$FOLDER_NAME/$LOG_NAME $CHECKING_FOLDER
./framework/tests/test_5_helper.py:30:30: W292 no newline at end of file
./framework/tests/test_1_start.py:2:1: F401 'pprint.pprint' imported but unused
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1
yml-file:
stages:
- check
pep8_check:
stage: check
image: python:3.8-alpine
variables:
FOLDER_NAME: 'logs'
LOG_NAME: 'linter.log'
CHECKING_FOLDER: './framework/tests'
when: always
before_script:
- python -m pip install --upgrade pip
- pip install flake8
- export
- mkdir -p $FOLDER_NAME
script:
- flake8 --max-line-length=120 --ignore=W605,W504 --tee --output-file=$FOLDER_NAME/$LOG_NAME $CHECKING_FOLDER
artifacts:
expire_in: 7 days
paths:
- $FOLDER_NAME/
Flake8 finds 2 errors so exits with 1, this makes the GitLab pipeline fail.
You have a few options:
if you want GitLab to ignore any error flake8 may find, then you can just add the parameter --exit-zero, this will make flake8 exit with 0 which makes the GitLab pipeline successful
if you want to ignore those specific errors from your output:
./framework/tests/test_5_helper.py:30:30: W292 no newline at end of file
./framework/tests/test_1_start.py:2:1: F401 'pprint.pprint' imported but unused
then you just have to add those to the ignore list like you did for others:
change this --ignore=W605,W504 to this --ignore=W605,W504,W292,F401
you can also go and "fix/amend/change" your code so flake8 stops flagging those lines when parsing your source code
In any case reading the help with flake8 --help may give some more ideas on how to tackle these corner cases depending on what you want to achieve.
Also see here the lists of error/warning/violation codes E***, W***, F***:
https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
https://flake8.pycqa.org/en/latest/user/error-codes.html

Pandoc can't get Locale/Encoding right with Hakyll and Gitlab CI

I'm trying to use Gitlab Pages to automatically deploy my Hakyll blog, but I keep having problems with file encoding.
When building the pages, I get the following error:
[ERROR] /builds/jmite/hakyll/.stack/snapshots/x86_64-linux/lts-8.14/8.0.2/share/x86_64-linux-ghc-8.0.2/pandoc-citeproc-0.10.4.1/locales/locales-C-.xml: openBinaryFile: does not exist (No such file or directory)
My .gitlab-ci.yaml looks like this:
image: fpco/stack-build:lts-8.14
before_script:
- LC_ALL=en_CA.UTF-8
- LANG=en_CA.UTF-8
- apt-get update && apt-get install xz-utils make
- export STACK_ROOT=`pwd`/.stack
- stack setup
- stack install --only-dependencies
- stack build
build:
cache:
paths:
- _cache
- .stack
script:
- stack exec site build
except:
- master
pages:
cache:
paths:
- _cache
- .stack
script:
- stack exec site build
artifacts:
paths:
- public
only:
- master
I've tried adding locale information to my config:
- LC_ALL=en_CA.UTF-8
- LANG=en_CA.UTF-8
But then I get the following error:
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_CA.UTF-8)
[ERROR] ./templates/default.html: hGetContents: invalid argument (invalid byte sequence)
How can I fix this? Is there a way to (1) change the encoding on mo local machine, and push to GitLab, so that the files will match whatever Pandoc is expecting, or (2) to configure the GitLab CI to work with them how they're encoded now?
When I open the files in vscode it says they are UTF-8. Are there ways to get more information about the encoding that might be causing problems?

Resources