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

Fix httpcore dependency; fix style linting #257

Merged

Conversation

c0llab0rat0r
Copy link
Contributor

@c0llab0rat0r c0llab0rat0r commented Apr 1, 2021

  1. Fix httpcore dependency by removing comment that broke pip
  2. Add scripts to run tests and typing checks with Docker against multiple versions of Python

Previous to this change, attempts to run

tox -e styleck -e typeck

..resulted in this error:

ERROR: Invalid requirement: 'httpcore (~= 0.10.2)  # Has Unix domain socket support'

The error is caused by this part of that line being present in tox.ini:

# Has Unix domain socket support

This commit does not fix the typing errors referenced in #255 but does demonstrate the typing errors now that the httpcore dependency is fixed.

@ntninja
Copy link
Contributor

ntninja commented Apr 3, 2021

Hmm… I never considered the typing and style checks to be particularily hard to run. Using docker to run them seems kinda overkill to me, but if people feel this is helpful I'll add this.

However, before we do that, could you tell me what output you are seeing when running the tox -e styleck -e typeck command directly on your system? Also what does tox --version report? (Tox has a feature where it'll provision a newer version of itself, if the host version is too old, so I'd strongly prefer using that instead if that is all there is to it.)

@c0llab0rat0r
Copy link
Contributor Author

c0llab0rat0r commented Apr 3, 2021

I didn't have tox installed at all. In the python:3.8.5 docker image its 3.7.0, and when I install tox into my venv its 3.23.0.

The tox output, both from the docker runs and with tox now installed into the venv, is two categories of errors.

Linting, such as:

./venv/lib/python3.8/site-packages/netaddr/strategy/eui48.py:267:1: WT191 (flake8-tabs) indentation contains spaces, but option indent-style=tab requires tabs

And typing, such as:

ipfshttpclient/client/base.py:212: error: Incompatible return value type (got "Callable[[VarArg(Any), KwArg(Any)], Union[None, List[R], ResponseWrapIterator[T, R]]]", expected "_returns_multiple_wrapper2_t[T, R]") 
[return-value]
    return wrapper2

@c0llab0rat0r
Copy link
Contributor Author

The primary benefit of the docker images is validating against the array of supported python versions easily with a clean build. You could check them individually with separate virtual environments, but then you have to maintain the virtual environments and dependencies could drift. Docker is a clean slate each time.

@c0llab0rat0r
Copy link
Contributor Author

I think there's a combination of a small number of legitimate issues the type and style checks are catching, and a larger number of false positives caused by a lack of ignores for checking dependencies (e.g. warnings for venv/../code.py).

I'm going to make some adjustments and push a revision.

@ntninja
Copy link
Contributor

ntninja commented Apr 3, 2021

Thank you, now I understand much better what this issue is about! I thought this was merely to workaround some issue you had with tox, but using this for cross-version checks makes much more sense. (I have a setup for this without using docker, but that is not something most people can be asked to reproduce.)

@c0llab0rat0r c0llab0rat0r force-pushed the httpcore-dependency-remove-comment branch from 314d37d to 06278d1 Compare April 3, 2021 18:38
Copy link
Contributor

@ntninja ntninja left a comment

Choose a reason for hiding this comment

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

You just dropped all the Docker-related code I tried to review. What is the plan there?

verify.sh Outdated
Comment on lines 19 to 22
validate 3.5.10
validate 3.6.13
validate 3.7.10
validate 3.8.8
Copy link
Contributor

Choose a reason for hiding this comment

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

Is is possible to use aliases like 3.5, 3.6, … here to avoid listing all these detailed versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can; it's a trade off between build consistency and being automatically on a later point release of Python.

Which would you prefer?

I think ideally it would use the same source of truth as the rest of the build and scrape the config files, but I didn't get that far.

Copy link
Contributor

@ntninja ntninja Apr 4, 2021

Choose a reason for hiding this comment

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

Consistency is probably better, you're right! It's probably best to test the supported earliest version of each Python minor release.

I think ideally it would use the same source of truth as the rest of the build and scrape the config files, but I didn't get that far.

The current “single source of truth” would be the tool.flit.metadata.requires-python key in pyproject.toml, whose value would effectively evaluate to the following Python minimum minor version configuration:

    validate 3.5.4
    validate 3.6.2
    validate 3.7.2
    validate 3.8.0

It's not straightforward at all to derive these values programmatically through. :-/

verify.sh Outdated
validate 3.7.10
validate 3.8.8
else
echo "Validating only $1..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please use ellipsis (…), instead of three dots (...) here.

verify.sh Outdated
tag=py-ipfs-http-client-verify:$python_version

docker build --build-arg PYTHON_VERSION=$python_version -t $tag .
docker run -it -v $(pwd):/source:ro -w /usr/src/app $tag tox -e styleck -e typeck
Copy link
Contributor

Choose a reason for hiding this comment

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

Use docker run --rm to ensure the used image doesn't stick around needlessly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You just dropped all the Docker-related code I tried to review. What is the plan there?

I thought I was getting some push back on it so I decided to pare down the PR to changes to the library. I can add it back if you like, with changes per the comments you added.

FYI - the linting step of the Travis build now passes. I don't have fixes for the remaining type checks since I'm not familiar enough with protocols to address it.

Do you want me to add the Docker scripts back into this PR, or open a new PR for it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please open a new PR for the Docker stuff. The current PR is indeed useful as is, so no need to clutter it further.

Dockerfile Outdated
Comment on lines 3 to 5
FROM python:${PYTHON_VERSION}

RUN apt-get update -y && apt-get install -y apt-utils tox
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be OK to use the Python -alpine images here for smaller image download size?

Install command would be apk update && apk add --no-cache py3-tox in this case.

verify.sh Outdated
}

if [ -z "$1" ]; then
echo "Validating supported versions..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please use ellipsis (…), instead of three dots (...) here.

entrypoint.sh Outdated
Comment on lines 1 to 6
#!/usr/bin/env bash

cp -r /source/* /usr/src/app/

exec $@

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this script be inlined into the Dockerfile (less clutter)? Also #!/bin/sh is sufficient here.

verify.sh Outdated
Comment on lines 6 to 13
python_version=$1

echo "Validating version $python_version..."

tag=py-ipfs-http-client-verify:$python_version

docker build --build-arg PYTHON_VERSION=$python_version -t $tag .
docker run -it -v $(pwd):/source:ro -w /usr/src/app $tag tox -e styleck -e typeck
Copy link
Contributor

Choose a reason for hiding this comment

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

Please always add double-quotes (") around variable/process substitutions (ie: $tag"${tag}") unless you explicitly intend to invoke shell word splitting. Figuring out whitespace issues with shell is a huge PITA otherwise.

"# Exclude lines specific to some other Python version from coverage",
"exclude_lines =",
), map(lambda s: "\t" + s, exclusions))))
(
Copy link
Contributor

Choose a reason for hiding this comment

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

It will behave better here if you move the opening parenthese to the line above. The way it's currently written was actually a workaround to a bug in an older version of the checker. 😉

Copy link
Contributor

@ntninja ntninja Apr 4, 2021

Choose a reason for hiding this comment

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

It will behave better here if you move the opening parenthese to the line above. The way it's currently written was actually a workaround to a bug in an older version of the checker. wink

^ Do this.

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 had tried simply moving the parenthesis on line 180 up earlier but it didn't like that. The latest change flattens that entire section and passes the linter.

@ntninja
Copy link
Contributor

ntninja commented Apr 3, 2021

As a more general note on the Docker thing: It is not really necessary to run the type and style checks in different Python versions. CI only checks the latest version and this is on purpose.

For typing, lot's of workarounds were required for pre-3.8 versions type hints, so the hints are provided on a best-effort basis there. The reason for running the type check at all is to ensure our typings are non-contradictionary and this property should not change depending on the 3.8+ Python version run (many mypy bugs permitting), so checking more than one Python version isn't all that helpful.

For flake8 the Python version is pretty much totally irrelevant, except that the version needs to be new enough to understand all the syntax used in the project's source code (ast and tokenize modules). Again, this is the case for any Python version since 3.6, so no need to run the check on more than one version.

@c0llab0rat0r
Copy link
Contributor Author

Linting step for 3.8 build is passing now.

Copy link
Contributor

@ntninja ntninja left a comment

Choose a reason for hiding this comment

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

Just some minor stuff now.

ipfshttpclient/encoding.py Outdated Show resolved Hide resolved
ipfshttpclient/filescanner.py Outdated Show resolved Hide resolved
"# Exclude lines specific to some other Python version from coverage",
"exclude_lines =",
), map(lambda s: "\t" + s, exclusions))))
(
Copy link
Contributor

@ntninja ntninja Apr 4, 2021

Choose a reason for hiding this comment

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

It will behave better here if you move the opening parenthese to the line above. The way it's currently written was actually a workaround to a bug in an older version of the checker. wink

^ Do this.

Copy link
Contributor

@ntninja ntninja left a comment

Choose a reason for hiding this comment

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

Thank you!

@c0llab0rat0r c0llab0rat0r changed the title Fix httpcore dependency; add scripts demonstrating its fixed Fix httpcore dependency; fix style linting Apr 4, 2021
@ntninja ntninja merged commit ce535f3 into ipfs-shipyard:master Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants