Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

pylint code checks #9

Merged
merged 34 commits into from
Aug 21, 2018
Merged

pylint code checks #9

merged 34 commits into from
Aug 21, 2018

Conversation

de-code
Copy link
Contributor

@de-code de-code commented Aug 16, 2018

@@ -2,6 +2,8 @@ ARG python_base_image_tag
FROM python:${python_base_image_tag}
RUN pip install --no-cache-dir --only-binary --upgrade pipenv

RUN apk --no-cache add linux-headers g++
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check whether that can be reduced more

project_tests.sh Outdated

set -e

pylint content_store/api/*.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be more generic (but pylint content_store doesn't work because of it not containing an __init__.py file)


[BASIC]
good-names=
id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if id is actually a good name, given that it's also a built-in function

.pylintrc Outdated
@@ -0,0 +1,14 @@
[MESSAGES CONTROL]
disable=
fixme,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might remove fixme later - we have a TODO in there; probably should not keep TODOs in the code

.pylintrc Outdated
[MESSAGES CONTROL]
disable=
fixme,
missing-docstring,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to structure the code in a read-able way and add high-level documentation

.pylintrc Outdated
disable=
fixme,
missing-docstring,
too-few-public-methods
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to separate code logically, even if one module ends up having only one public method for now

@@ -0,0 +1 @@
# for pylint
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm proposing to just add the __init__.py files rather than messing around with an untidy pylint workaround.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@de-code de-code changed the title [wip] pylint code checks pylint code checks Aug 20, 2018

# TODO : add migrations
# database setup (will use migration in the future)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworded to not require fixme pylint exception


# could move to blueprint
@app.route("/ping")
def ping():
def _ping():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the underscore pylint won't complain about the function not being used (seems to be a common pattern)

project_tests.sh Outdated
@@ -0,0 +1,6 @@
#!/bin/sh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the project_tests.sh file also directly (without docker); it's faster than waiting for the docker build and then run the tests within it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming format, want to uniform to project-tests.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed (didn't realise you did adopt the hyphen in the end)

@@ -2,6 +2,8 @@ ARG python_base_image_tag
FROM python:${python_base_image_tag}
RUN pip install --no-cache-dir --only-binary --upgrade pipenv

RUN apk --no-cache add linux-headers g++
Copy link
Member

@giorgiosironi giorgiosironi Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pylint (or one of its dependencies) requires a C++ compiler for the Python package to be installed? At least it doesn't need to be carried over to the main image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen pylint-dev/pylint#1423 for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered it in typed_ast (ast27/Parser/acceler.c). I guess it kind of makes sense that dependencies use native code to make bottlenecks faster.

project_tests.sh Outdated

set -e

pytest && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python -m pytest is usually different from pytest as it adds . to PYTHONPATH. In the container this is probably not that useful as we can set that env variable in the Dockerfile; what about on the host?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that. Where do you see that it's different? For me the script is just calling pytest.main, as seem to be the case when when running it as a module too. So not sure where it is adding it to the path.

Although I did see a difference when calling pytest without the __init__.py in tests then it failing to find content_store, but it seems to work with python -m pyest. Its working with both commands if there is a __init__.py file in tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long story at https://docs.pytest.org/en/latest/pythonpath.html but if it works, good

Copy link
Member

@giorgiosironi giorgiosironi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try this out after the schema meeting

Pipfile Outdated
@@ -5,6 +5,7 @@ name = "pypi"

[dev-packages]
pytest = "~=3.7.1"
pylint = "*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify at least the major version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, added. Even though it doesn't seem to be common practise for pipenv.

Apparently that is coming out of pipenv:

We recommend updating your Pipfile to specify the "*" version, instead.

The documentation isn't as clear about it apart from assuming that fixed versions come from the requirements.txt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock file deals with the exact version separately, but a major version here (can't see it at the moment?) should be handy as if we run an upgrade we don't want to end up with an hypothetical future Pylint 3 that has introduced backward-incompatible changes like a different format for .pylintrc, etc.

I understand that people importing a requirements.txt will end up with things like 1.2.3.4rc2_0ubuntu1 which is brittle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally put it on the wrong dependency (fixed).

I understand reasons for add a major version.

But we should be aware that it does seem to be against the advice of pipenv.

@@ -1,2 +1,3 @@
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()

DB = SQLAlchemy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, module-level constant needs to be uppercase

project-tests.sh Outdated

set -e

export PYTHONOPTIMIZE=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a comment on why it's disabled. Related to creation of .pyc/.pyo files? Strips comments that Pylint needs?

.gitignore Outdated
@@ -124,3 +124,6 @@ pip-selfcheck.json


# End of https://www.gitignore.io/api/python

# IDEs
.vscode/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be better suited to a global .gitignore

Copy link
Member

@giorgiosironi giorgiosironi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on versioning, documentation. The changes enforced by Pylint look benign so far. Needs a merge of master if not done recently.

@de-code
Copy link
Contributor Author

de-code commented Aug 21, 2018

Still up-to-date with master. Would be good to get this merged.

@@ -0,0 +1,2 @@
**/*.pyc
**/*.pyo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always have to lookup this format, it works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if they could just use the .gitignore format, and perhaps by default also use .gitignore (but I am sure there are many reasons against that idea).

Pipfile Outdated
@@ -5,6 +5,7 @@ name = "pypi"

[dev-packages]
pytest = "~=3.7.1"
pylint = "2.*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg_resources.extern.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'.*'"

I think you need to use ~=2.1 which means >= 2.1, < 3.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, should have run pipenv lock as the docker build is ignoring the file. That's fixed now as well. (also updated the lock)

Copy link
Member

@giorgiosironi giorgiosironi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only missing the correction to the pylint version, then we can merge

@giorgiosironi giorgiosironi merged commit 19dab62 into libero:master Aug 21, 2018
@de-code de-code deleted the code-checks branch August 21, 2018 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants