Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion sdks/python/apache_beam/typehints/typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,6 @@ def coerce_to_kv_type(element_type, label=None):
Union[tuple(t.tuple_types[1] for t in union_types)]]
else:
# TODO: Possibly handle other valid types.
print "element_type", element_type
raise ValueError(
"Input to %r must be compatible with KV[Any, Any]. "
"Found %s." % (label, element_type))
6 changes: 3 additions & 3 deletions sdks/python/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ build.dependsOn buildPython
task lint (dependsOn: 'setupTest') {
doLast {
exec {
commandLine 'tox', '-e', 'lint', '-c', 'tox.ini'
commandLine 'tox', '-e', '{py27,py3}-lint', '-c', 'tox.ini'
}
}
}
Expand All @@ -74,7 +74,7 @@ check.dependsOn lint
task testCython (dependsOn: ['setupTest', 'testPython', 'testGcp']) {
doLast {
exec {
commandLine 'tox', '-e', 'py27cython', '-c', 'tox.ini'
commandLine 'tox', '-e', 'py27-cython2', '-c', 'tox.ini'
}
}
}
Expand All @@ -83,7 +83,7 @@ test.dependsOn testCython
task testGcp (dependsOn: 'setupTest') {
doLast {
exec {
commandLine 'tox', '-e', 'py27gcp', '-c', 'tox.ini'
commandLine 'tox', '-e', 'py27-gcp', '-c', 'tox.ini'
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions sdks/python/run_tox_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This script is used to remove generated files in previous Tox runs so that
# they are not picked up by tests.

set -e

for dir in apache_beam target/build; do
if [ -d "${dir}" ]; then
for ext in pyc c so; do
find ${dir} -type f -name "*.${ext}" -delete
done
fi
done
11 changes: 5 additions & 6 deletions sdks/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ def get_version():
'futures>=3.1.1,<4.0.0',
]

REQUIRED_SETUP_PACKAGES = [
'nose>=1.0',
Copy link
Member

Choose a reason for hiding this comment

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

Is not this required by setup, because test_suite references it?

Copy link

@cclauss cclauss Mar 17, 2018

Choose a reason for hiding this comment

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

Does it make sense to raise REQUIRED_PIP_VERSION = '7.0.0' to something a closer to the current 9.0.3 or do we leave that alone for now? Alternatively, should the process do pip install --upgrade pip?

Copy link
Member Author

Choose a reason for hiding this comment

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

@aaltay setup_requires= lists packages required to run setup.py. I couldn't see why nose is required for that.
Specifying nose in the tests_require= keyword arg is sufficient.

@cclauss I would like to leave it alone in this PR, and I don't have any objection to raising the required version.
Note that creating a new virtualenv installs (at least for me) a version of pip that's newer than the system installed version (9.0.2 vs 9.0.1).

Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason for us to raise the required version?

Alternatively, should the process do pip install --upgrade pip?
Which process? As far as I know, virtualenv brings a new version of pip with it.

Copy link

Choose a reason for hiding this comment

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

Python packaging has changed a lot in the past three years especially in relation to Python 3 requirements https://pip.pypa.io/en/stable/news We want to avoid compatibility issues in the migration to https://github.com/pypa/warehouse

Copy link

@cclauss cclauss Mar 22, 2018

Choose a reason for hiding this comment

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

The virtualenv does bring a pip but it can be upgraded by pip (bootstrapping).

Copy link
Member

Choose a reason for hiding this comment

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

@cclauss Are you referring to a specific issue? REQUIRED_PIP_VERSION is just the minimum version we require, we are not force downgrading to that version. If there is a known issue in compatibility we can consider raising the minimum supported version

Copy link
Member

Choose a reason for hiding this comment

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

@udim Is it required to run python setup.py test. If not we can drop it.

]

REQUIRED_TEST_PACKAGES = [
'nose>=1.3.7',
Copy link
Member

Choose a reason for hiding this comment

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

Why are we increasing the required version for nose?

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.ini already required 1.3.7. I thought this would be a no-op.

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 also wanted to merge requirements. Now only setup.py has the nose requirement.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

'pyhamcrest>=1.9,<2.0',
]

Expand Down Expand Up @@ -177,6 +174,9 @@ def generate_common_urns():
+ '\n')
generate_common_urns()

python_requires = '>=2.7'
if os.environ.get('BEAM_EXPERIMENTAL_PY3') is None:
python_requires += ',<3.0'

setuptools.setup(
name=PACKAGE_NAME,
Expand All @@ -202,9 +202,8 @@ def generate_common_urns():
'apache_beam/utils/counters.py',
'apache_beam/utils/windowed_value.py',
]),
setup_requires=REQUIRED_SETUP_PACKAGES,
install_requires=REQUIRED_PACKAGES,
python_requires='>=2.7,<3.0',
python_requires=python_requires,
test_suite='nose.collector',
tests_require=REQUIRED_TEST_PACKAGES,
extras_require={
Expand Down
99 changes: 32 additions & 67 deletions sdks/python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,142 +17,107 @@

[tox]
# new environments will be excluded by default unless explicitly added to envlist.
# TODO (after BEAM-3671) add lint_py3 back in.
envlist = py27,py27gcp,py27cython,lint_py2,docs
envlist = py27,py27-{gcp,cython2,lint},py3-lint,docs
toxworkdir = {toxinidir}/target/.tox

[pycodestyle]
# Disable all errors and warnings except for the ones related to blank lines.
# pylint does not check the number of blank lines.
select = E3

# Shared environment options.
[testenv]
# Set [] options for pip installation of apache-beam tarball.
extras = test
# Don't warn that these commands aren't installed.
whitelist_externals =
find
time

[testenv:py27]
# autocomplete_test depends on nose when invoked directly.
deps =
nose==1.3.7
grpcio-tools==1.3.5
whitelist_externals=find
commands =
python --version
pip --version
# Clean up all previous python generated files.
- find apache_beam -type f -name '*.pyc' -delete
pip install -e .[test]
{toxinidir}/run_tox_cleanup.sh
python apache_beam/examples/complete/autocomplete_test.py
python setup.py test
passenv = TRAVIS*
{toxinidir}/run_tox_cleanup.sh

[testenv:py27cython]
# This environment will fail in Jenkins if named "py27-cython".
Copy link
Member

Choose a reason for hiding this comment

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

For my education, do you know why it fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

No bleeding clue. Since I don't have ssh access I can't really debug it.
Honestly I'm glad I got it working.

[testenv:py27-cython2]
# cython tests are only expected to work in linux (2.x and 3.x)
# If we want to add other platforms in the future, it should be:
# `platform = linux2|darwin|...`
# See https://docs.python.org/2/library/sys.html#sys.platform for platform codes
platform = linux2
# autocomplete_test depends on nose when invoked directly.
deps =
nose==1.3.7
grpcio-tools==1.3.5
cython==0.25.2
whitelist_externals=
find
time
cython==0.26.1
Copy link
Member

Choose a reason for hiding this comment

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

Curious why this version? Latest is 0.28.1.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the minimum version required by setup.py (REQUIRED_CYTHON_VERSION). I didn't want to increase the version beyond that and risk breaking things in this PR.

Side note: sdks/python/container/Dockerfile specifies 0.27.2. shrug
I wish all these pinned versions were synced to a single requirements.txt file. (see pip-compile)

Copy link

@cclauss cclauss Mar 23, 2018

Choose a reason for hiding this comment

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

+1 on a single requirements.txt file.

Copy link
Member

Choose a reason for hiding this comment

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

That is fair to not change the version in this PR. We should consider upgrading it.

It would be nice to have a single source of truth. Although I do not see how pip-compile can update the Dockerfile. It is worth filing a JIRA for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

pip-compile can generate requirements.txt from setup.py, and the docker image can pull that in.
The only problem is that we have a different set of requirements depending on the extras specified (such as [test] and [gcp]), or whether cython is used.
So the solution is probably to use a script to generate a set of requirements files, using pip-compile output as an intermediate step. setup.py will be used as the single source of truth for version pinning.

commands =
python --version
pip --version
# Clean up all previous python generated files.
- find apache_beam -type f -name '*.pyc' -delete
# Clean up all previous cython generated files.
- find apache_beam -type f -name '*.c' -delete
- find apache_beam -type f -name '*.so' -delete
- find target/build -type f -name '*.c' -delete
- find target/build -type f -name '*.so' -delete
time pip install -e .[test]
{toxinidir}/run_tox_cleanup.sh
python apache_beam/examples/complete/autocomplete_test.py
python setup.py test
# Clean up all cython generated files. Ignore if deletion fails.
- find apache_beam -type f -name '*.c' -delete
- find apache_beam -type f -name '*.so' -delete
- find target/build -type f -name '*.c' -delete
- find target/build -type f -name '*.so' -delete
passenv = TRAVIS*
{toxinidir}/run_tox_cleanup.sh

[testenv:py27gcp]
# autocomplete_test depends on nose when invoked directly.
deps =
nose==1.3.7
whitelist_externals=find
[testenv:py27-gcp]
extras = test,gcp
commands =
python --version
pip --version
pip install -e .[test,gcp]
# Clean up all previous python generated files.
- find apache_beam -type f -name '*.pyc' -delete
{toxinidir}/run_tox_cleanup.sh
python apache_beam/examples/complete/autocomplete_test.py
python setup.py test
passenv = TRAVIS*
{toxinidir}/run_tox_cleanup.sh

[testenv:lint_py2]
deps=
nose==1.3.7
[testenv:py27-lint]
deps =
pycodestyle==2.3.1
pylint==1.7.2
future==0.16.0
isort==4.2.15
flake8==3.5.0
whitelist_externals=time
commands =
python --version
pip --version
time pip install -e .[test]
time {toxinidir}/run_pylint.sh
passenv = TRAVIS*

[testenv:lint_py3]
deps=
nose==1.3.7
[testenv:py3-lint]
deps =
pycodestyle==2.3.1
pylint==1.7.2
future==0.16.0
isort==4.2.15
flake8==3.5.0
whitelist_externals=time
setenv =
BEAM_EXPERIMENTAL_PY3=1
commands =
time pip install -e .[test]
python --version
pip --version
time {toxinidir}/run_mini_py3lint.sh
passenv = TRAVIS*


[testenv:docs]
deps=
nose==1.3.7
grpcio-tools==1.3.5
extras = test,gcp,docs
deps =
Sphinx==1.6.5
sphinx_rtd_theme==0.2.4
whitelist_externals=time
commands =
python --version
pip --version
time pip install -e .[test,gcp,docs]
time {toxinidir}/generate_pydoc.sh
passenv = TRAVIS*

[testenv:cover]
# This is not included in envlist which is defined in [tox].
deps =
coverage==4.4.1
nose==1.3.7
whitelist_externals=find
commands =
python --version
pip --version
pip install -e .[test,gcp]
# Clean up all previous python generated files.
- find apache_beam -type f -name '*.pyc' -delete
{toxinidir}/run_tox_cleanup.sh
# Clean up previously collected data.
coverage erase
coverage run setup.py test
# Print coverage report to STDOUT
coverage report --skip-covered
# Generate report in xml format
coverage xml
passenv = TRAVIS*