Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake8 and isort lint checks #46

Merged
merged 7 commits into from
Jul 16, 2019

Conversation

c24t
Copy link
Member

@c24t c24t commented Jul 10, 2019

From #42 (comment), builds on #42. Compare to @Oberon00's unit-tests branch for a sane diff: Oberon00/opentelemetry-python@unit-tests...c24t:more-pedantic-lint

This PR makes lint a bit stricter by adding flake8 and isort checks.

@c24t c24t mentioned this pull request Jul 10, 2019
@c24t c24t added the meta Related to repo itself, process, community, ... label Jul 10, 2019
tox.ini Outdated

[testenv:lint]
deps =
pylint~=2.3.1
Copy link
Member

Choose a reason for hiding this comment

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

Not directly related to this PR, do we want to put a specific version or we want to use the latest version?

Putting a specific version gives us the benefit of a more stable CI enironment (it is not perfect since even if we put a specific package version, it could introduce other package dependencies that are not fixed), in the cost that when we decide to move to a new version, we end up doing a big change (which means bigger risk) instead of doing small changes through our daily work.

Copy link
Member

Choose a reason for hiding this comment

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

We use ~= (https://www.python.org/dev/peps/pep-0440/#compatible-release) here, but in fact, I think using =2.*,>=2.3.1 or ~=2.3 instead would be better. I would definitely pin the major version though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be happy with any of these, from most- to least-conservative: ~=2.3.1, =2.*,>=2.3.1, ~=2.3, >=2.3.1.

Since this is a test dependency and should only affect devs, I think there's actually a good argument for not pinning the major version and staying up to date with the latest versions in the course of regular dev work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed these to ~=2.3.

DUMMY_TRACER = None
del os.environ[envname]
self.assertIs(type(tracer), DummyTracer)
def test_get_envvar_tracer(self):
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to capture the missing blank line here?

Copy link
Member

Choose a reason for hiding this comment

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

Actually these were intentional as the three functions are a "translation" of a single @pytest.mark.parametrize function. But you are right, in general, having a rule to enforce at least a single blank line between functions would be good.

Copy link
Member Author

Choose a reason for hiding this comment

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

tox -e lint does catch these, travis just isn't running lint.

DUMMY_TRACER = None
del os.environ[envname]
self.assertIs(type(tracer), DummyTracer)
def test_get_envvar_tracer(self):
Copy link
Member

Choose a reason for hiding this comment

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

Actually these were intentional as the three functions are a "translation" of a single @pytest.mark.parametrize function. But you are right, in general, having a rule to enforce at least a single blank line between functions would be good.

tox.ini Outdated

[testenv:lint]
deps =
pylint~=2.3.1
Copy link
Member

Choose a reason for hiding this comment

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

We use ~= (https://www.python.org/dev/peps/pep-0440/#compatible-release) here, but in fact, I think using =2.*,>=2.3.1 or ~=2.3 instead would be better. I would definitely pin the major version though.

@c24t
Copy link
Member Author

c24t commented Jul 11, 2019

Lint failures right on cue:

image

@Oberon00
Copy link
Member

I see. Why did you move the linter out from the default testenv section?

@c24t
Copy link
Member Author

c24t commented Jul 15, 2019

Why did you move the linter out from the default testenv section?

I thought it made it easier to read now that there are multiple lint commands, but I don't have any strong preferences about how the toxfile is organized.

@c24t
Copy link
Member Author

c24t commented Jul 16, 2019

Hopefully using isort means never needing to comment on import sort ordering again. In case it's useful to others, I'm using this pre-commit hook to run it automatically:

checkfiles=$(comm -12 <(git diff --name-only --cached HEAD | sort) <(find opentelemetry-*/src -type f -name "*.py" | sort))
[[ $checkfiles ]] && isort $checkfiles

@c24t c24t merged commit 3d0046a into open-telemetry:master Jul 16, 2019
@c24t c24t deleted the more-pedantic-lint branch July 16, 2019 17:34
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
* Add context-base and context-asynchooks packages

* add BaseScopeManager interface open-telemetry#46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Related to repo itself, process, community, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants