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

[BEAM-12000] Add Python 3.9 support. #16008

Merged
merged 11 commits into from
Feb 10, 2022
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
20 changes: 3 additions & 17 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,8 @@ jobs:
{"py_ver": "3.6", "tox_env": "py36"},
{"py_ver": "3.7", "tox_env": "py37"},
{"py_ver": "3.8", "tox_env": "py38"},
{"py_ver": "3.9", "tox_env": "py39"},
]
exclude:
# TODO remove exclusion after issue with protobuf is solved
# https://github.com/protocolbuffers/protobuf/issues/7765
- os: windows-latest
params: {"py_ver": "3.8", "tox_env": "py38"}
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -140,12 +136,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.6, 3.7, 3.8]
exclude:
# TODO remove exclusion after issue with protobuf is solved
# https://github.com/protocolbuffers/protobuf/issues/7765
- os: windows-latest
python: 3.8
python: [3.6, 3.7, 3.8, 3.9]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -173,12 +164,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.6, 3.7, 3.8]
exclude:
# TODO remove exclusion after issue with protobuf is solved
# https://github.com/protocolbuffers/protobuf/issues/7765
- os: windows-latest
python: 3.8
python: [3.6, 3.7, 3.8, 3.9]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .test-infra/jenkins/PythonTestProperties.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class PythonTestProperties {
final static List<String> ALL_SUPPORTED_VERSIONS = [
'3.6',
'3.7',
'3.8'
'3.8',
'3.9'
]
final static List<String> SUPPORTED_CONTAINER_TASKS = ALL_SUPPORTED_VERSIONS.collect {
"py${it.replace('.', '')}"
Expand Down
1 change: 1 addition & 0 deletions .test-infra/jenkins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
applyGroovyNature()
applyPythonNature()

// TODO(BEAM-9980): Don't hardcode this version, take the value provided by Python nature.
pythonVersion = '3.8'

task generateMetricsReport {
Expand Down
2 changes: 1 addition & 1 deletion .test-infra/jenkins/job_PreCommit_Portable_Python.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ builder.build {
}
gradle {
rootBuildScriptDir(commonJobProperties.checkoutDir)
tasks(':sdks:python:test-suites:portable:py38:preCommitPy38')
tasks(':sdks:python:test-suites:portable:py39:preCommitPy38')
commonJobProperties.setGradleSwitches(delegate)
}
}
Expand Down
2 changes: 1 addition & 1 deletion .test-infra/jenkins/metrics_report/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
; See the License for the specific language governing permissions and
; limitations under the License.
;

; TODO(BEAM-9980): Don't hardcode Py3.8 version.
[tox]
skipsdist = True
envlist = py38-test,py38-generate-report
Expand Down
16 changes: 15 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ tasks.register("pythonPreCommit") {
dependsOn(":sdks:python:test-suites:tox:py36:preCommitPy36")
dependsOn(":sdks:python:test-suites:tox:py37:preCommitPy37")
dependsOn(":sdks:python:test-suites:tox:py38:preCommitPy38")
dependsOn(":sdks:python:test-suites:tox:py39:preCommitPy39")
dependsOn(":sdks:python:test-suites:dataflow:preCommitIT")
dependsOn(":sdks:python:test-suites:dataflow:preCommitIT_V2")
}
Expand All @@ -279,9 +280,11 @@ tasks.register("pythonDockerBuildPreCommit") {
dependsOn(":sdks:python:container:py36:docker")
dependsOn(":sdks:python:container:py37:docker")
dependsOn(":sdks:python:container:py38:docker")
dependsOn(":sdks:python:container:py39:docker")
}

tasks.register("pythonLintPreCommit") {
// TODO(BEAM-9980): Find a better way to specify lint and formatter tasks without hardcoding py version.
dependsOn(":sdks:python:test-suites:tox:py37:lint")
}

Expand Down Expand Up @@ -314,15 +317,24 @@ tasks.register("python38PostCommit") {
dependsOn(":sdks:python:test-suites:portable:py38:postCommitPy38")
}

tasks.register("python39PostCommit") {
// TODO(BEAM-12920): Enable DF suite here.
// dependsOn(":sdks:python:test-suites:dataflow:py39:postCommitIT")
dependsOn(":sdks:python:test-suites:direct:py39:postCommitIT")
dependsOn(":sdks:python:test-suites:direct:py39:hdfsIntegrationTest")
dependsOn(":sdks:python:test-suites:portable:py39:postCommitPy39")
}

tasks.register("portablePythonPreCommit") {
dependsOn(":sdks:python:test-suites:portable:py36:preCommitPy36")
dependsOn(":sdks:python:test-suites:portable:py37:preCommitPy37")
dependsOn(":sdks:python:test-suites:portable:py39:preCommitPy39")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have only py36, py39?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some test suites, the main value may be in testing the highest supported version and the lowest supported version only to save resources and reduce execution time. But, existing suite definitions not always follow this rule and sometimes test random versions. Some suites test all versions.

}

tasks.register("pythonSparkPostCommit") {
dependsOn(":sdks:python:test-suites:portable:py36:sparkValidatesRunner")
dependsOn(":sdks:python:test-suites:portable:py37:sparkValidatesRunner")
dependsOn(":sdks:python:test-suites:portable:py38:sparkValidatesRunner")
dependsOn(":sdks:python:test-suites:portable:py39:sparkValidatesRunner")
}

tasks.register("websitePreCommit") {
Expand All @@ -348,12 +360,14 @@ tasks.register("runBeamDependencyCheck") {
}

tasks.register("whitespacePreCommit") {
// TODO(BEAM-9980): Find a better way to specify the tasks without hardcoding py version.
dependsOn(":sdks:python:test-suites:tox:py38:archiveFilesToLint")
dependsOn(":sdks:python:test-suites:tox:py38:unpackFilesToLint")
dependsOn(":sdks:python:test-suites:tox:py38:whitespacelint")
}

tasks.register("typescriptPreCommit") {
// TODO(BEAM-9980): Find a better way to specify the tasks without hardcoding py version.
dependsOn(":sdks:python:test-suites:tox:py38:eslint")
dependsOn(":sdks:python:test-suites:tox:py38:jest")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,7 @@ class BeamModulePlugin implements Plugin<Project> {
// Python interpreter version for virtualenv setup and test run. This value can be
// set from commandline with -PpythonVersion, or in build script of certain project.
// If none of them applied, version set here will be used as default value.
// TODO(BEAM-12000): Move default value to Py3.9.
project.ext.pythonVersion = project.hasProperty('pythonVersion') ?
project.pythonVersion : '3.8'

Expand Down Expand Up @@ -2618,6 +2619,7 @@ class BeamModulePlugin implements Plugin<Project> {
':sdks:python:container:py36:docker',
':sdks:python:container:py37:docker',
':sdks:python:container:py38:docker',
':sdks:python:container:py39:docker',
]
doLast {
// TODO: Figure out GCS credentials and use real GCS input and output.
Expand Down
1 change: 1 addition & 0 deletions release/src/main/scripts/build_release_candidate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ if [[ $confirmation = "y" ]]; then
git clone --branch "${RC_TAG}" --depth 1 ${GIT_REPO_URL}
cd ${BEAM_ROOT_DIR}
RELEASE_COMMIT=$(git rev-list -n 1 "tags/${RC_TAG}")
# TODO(BEAM-9980): Don't hardcode py version in this file.
cd sdks/python && pip install -r build-requirements.txt && tox -e py38-docs
GENERATED_PYDOC=~/${LOCAL_WEBSITE_UPDATE_DIR}/${LOCAL_PYTHON_DOC}/${BEAM_ROOT_DIR}/sdks/python/target/docs/_build
rm -rf ${GENERATED_PYDOC}/.doctrees
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import warnings

if sys.version_info.major == 3:
if sys.version_info.minor <= 5 or sys.version_info.minor >= 9:
if sys.version_info.minor <= 5 or sys.version_info.minor >= 10:
warnings.warn(
'This version of Apache Beam has not been sufficiently tested on '
'Python %s.%s. You may encounter bugs or missing features.' %
Expand Down
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/runners/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def __init__(self,
default_arg_values = signature.process_method.defaults
self.has_windowed_inputs = (
not all(si.is_globally_windowed() for si in side_inputs) or
(core.DoFn.WindowParam in default_arg_values) or
any(core.DoFn.WindowParam == arg for arg in default_arg_values) or
signature.is_stateful_dofn())
self.user_state_context = user_state_context
self.is_splittable = signature.is_splittable_dofn()
Expand Down Expand Up @@ -592,7 +592,7 @@ class ArgPlaceholder(object):
def __init__(self, placeholder):
self.placeholder = placeholder

if core.DoFn.ElementParam not in default_arg_values:
if all(core.DoFn.ElementParam != arg for arg in default_arg_values):
# TODO(BEAM-7867): Handle cases in which len(arg_names) ==
# len(default_arg_values).
args_to_pick = len(arg_names) - len(default_arg_values) - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

_LOGGER = logging.getLogger(__name__)

_PYTHON_VERSIONS_SUPPORTED_BY_DATAFLOW = ['3.6', '3.7', '3.8']
_PYTHON_VERSIONS_SUPPORTED_BY_DATAFLOW = ['3.6', '3.7', '3.8', '3.9']


class Step(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ def test_interpreter_version_check_passes_py38(self):

@mock.patch(
'apache_beam.runners.dataflow.internal.apiclient.sys.version_info',
(3, 9, 0))
(3, 10, 0))
@mock.patch(
'apache_beam.runners.dataflow.internal.apiclient.'
'beam_version.__version__',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ def convert_to_beam_type(typ):
elif _match_is_union(typ):
raise ValueError('Unsupported Union with no arguments.')
elif _match_issubclass(typing.Generator)(typ):
raise ValueError('Unsupported Generator with no arguments.')
# Assume a simple generator.
args = (typehints.TypeVariable('T_co'), type(None), type(None))
elif _match_issubclass(typing.Dict)(typ):
args = (typehints.TypeVariable('KT'), typehints.TypeVariable('VT'))
elif (_match_issubclass(typing.Iterator)(typ) or
_match_issubclass(typing.Generator)(typ) or
_match_is_exactly_iterable(typ)):
args = (typehints.TypeVariable('T_co'), )
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ def test_convert_bare_types_fail(self):
test_cases = [
('bare union', typing.Union),
]
if sys.version_info < (3, 7):
test_cases += [
('bare generator', typing.Generator),
]
for test_case in test_cases:
description = test_case[0]
typing_type = test_case[1]
Expand Down
3 changes: 3 additions & 0 deletions sdks/python/container/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ task buildAll {
dependsOn ':sdks:python:container:py36:docker'
dependsOn ':sdks:python:container:py37:docker'
dependsOn ':sdks:python:container:py38:docker'
dependsOn ':sdks:python:container:py39:docker'
}

task pushAll {
dependsOn ':sdks:python:container:py36:dockerPush'
dependsOn ':sdks:python:container:py37:dockerPush'
dependsOn ':sdks:python:container:py38:dockerPush'
dependsOn ':sdks:python:container:py39:dockerPush'
}

task generatePythonRequirementsAll {
dependsOn ':sdks:python:container:py36:generatePythonRequirements'
dependsOn ':sdks:python:container:py37:generatePythonRequirements'
dependsOn ':sdks:python:container:py38:generatePythonRequirements'
dependsOn ':sdks:python:container:py39:generatePythonRequirements'
}

artifacts {
Expand Down
Loading