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-13183] [BEAM-8152] Use venv instead of virtualenv to create Python environments in Gradle scripts. #15819

Merged
merged 6 commits into from
Nov 18, 2021

Conversation

tvalentyn
Copy link
Contributor

@tvalentyn tvalentyn commented Oct 27, 2021

Remove a dependency on virtualenv, instead use venv, which is a part of Python library (https://docs.python.org/3/library/venv.html).

Use venv in gradle commands and in the website documentation.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

ValidatesRunner compliance status (on master branch)

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- Build Status Build Status Build Status Build Status ---
Java Build Status Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Python --- Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status ---
XLang Build Status Build Status Build Status Build Status Build Status ---

Examples testing status on various runners

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- --- --- --- --- --- ---
Java --- Build Status
Build Status
Build Status
--- --- --- --- ---
Python --- --- --- --- --- --- ---
XLang --- --- --- --- --- --- ---

Post-Commit SDK/Transform Integration Tests Status (on master branch)

Go Java Python
Build Status Build Status Build Status
Build Status
Build Status

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website Whitespace Typescript
Non-portable Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status Build Status Build Status
Portable --- Build Status Build Status --- --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #15819 (e87f846) into master (2335ec6) will decrease coverage by 0.02%.
The diff coverage is n/a.

❗ Current head e87f846 differs from pull request most recent head 0a5ec87. Consider uploading reports for the commit 0a5ec87 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15819      +/-   ##
==========================================
- Coverage   83.63%   83.60%   -0.03%     
==========================================
  Files         445      445              
  Lines       61371    61329      -42     
==========================================
- Hits        51326    51277      -49     
- Misses      10045    10052       +7     
Impacted Files Coverage Δ
...hon/apache_beam/runners/direct/test_stream_impl.py 94.02% <0.00%> (-2.24%) ⬇️
...pache_beam/runners/interactive/interactive_beam.py 75.60% <0.00%> (-0.98%) ⬇️
sdks/python/apache_beam/runners/direct/executor.py 96.46% <0.00%> (-0.55%) ⬇️
...runners/interactive/display/pcoll_visualization.py 85.85% <0.00%> (-0.51%) ⬇️
sdks/python/apache_beam/transforms/combiners.py 93.15% <0.00%> (-0.40%) ⬇️
...eam/runners/interactive/interactive_environment.py 91.37% <0.00%> (-0.35%) ⬇️
sdks/python/apache_beam/typehints/typehints.py 93.34% <0.00%> (-0.10%) ⬇️
sdks/python/apache_beam/coders/coders.py 88.61% <0.00%> (-0.03%) ⬇️
sdks/python/apache_beam/pipeline.py 91.73% <0.00%> (-0.02%) ⬇️
sdks/python/apache_beam/transforms/core.py 92.63% <0.00%> (-0.01%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2335ec6...0a5ec87. Read the comment docs.

@tvalentyn tvalentyn changed the title [BEAM-12000] Use venv instead of virtualenv to avoid a virtualenv dependency that can be avoided. [BEAM-8152] Use venv instead of virtualenv to avoid a virtualenv dependency that can be avoided. Oct 27, 2021
@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

1 similar comment
@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

@tvalentyn
Copy link
Contributor Author

Run PythonDocs PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

1 similar comment
@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Portable_Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run GoPortable PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Portable_Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Portable_Python PreCommit

@tvalentyn
Copy link
Contributor Author

Run Website PreCommit

@tvalentyn
Copy link
Contributor Author

Run GoPortable PreCommit

@tvalentyn
Copy link
Contributor Author

Run Java PreCommit

@tvalentyn
Copy link
Contributor Author

Run Python_PVR_Flink PreCommit

@tvalentyn
Copy link
Contributor Author

Run SQL PreCommit

@tvalentyn tvalentyn changed the title [BEAM-8152] Use venv instead of virtualenv to avoid a virtualenv dependency that can be avoided. [BEAM-8152] Use venv instead of virtualenv to create Python environments on Gradle. Nov 12, 2021
@tvalentyn tvalentyn changed the title [BEAM-8152] Use venv instead of virtualenv to create Python environments on Gradle. [BEAM-8152] Use venv instead of virtualenv to create Python environments in Gradle scripts. Nov 12, 2021
@tvalentyn
Copy link
Contributor Author

r: @ryanthompson591 @TheNeuralBit

Copy link
Member

@TheNeuralBit TheNeuralBit left a comment

Choose a reason for hiding this comment

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

This LGTM, I have a few questions though

- pip, setuptools, virtualenv, and tox installed for Python development
- Python 3.x interpreters. You will need Python interpreters for all Python versions supported by Beam.
Interpreters should be installed and available in shell via `python3.x` commands. For more information, see:
Python installation tips in [Developer Wiki](https://cwiki.apache.org/confluence/display/BEAM/Python+Tips#PythonTips-InstallingPythoninterpreters).
Copy link
Member

Choose a reason for hiding this comment

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

Consider noting the issue with venv in deadsnakes pythons, and the need to install python3.x-dev

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 added a note to the Wiki about it.

tox
docker.io


python3.6 python3.6-dev python3.6-venv python3.7 python3.7-dev python3.7-distutils python3.7-venv python3.8 python3.8-dev python3.8-distutils python3.8-venv
Copy link
Member

Choose a reason for hiding this comment

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

what is this line?

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 think there is some 'dev' environment, and this file lists all apt packages to install in that environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah looks like the line is a leftover, thanks for catching.

Copy link
Member

@TheNeuralBit TheNeuralBit Nov 17, 2021

Choose a reason for hiding this comment

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

re: dev envirornment - this file is referenced from ./local-env-setup.sh (configures current system), and ./start-build-env.sh (builds and start a development container)

@@ -33,7 +33,22 @@ openjdk-8-jdk
python3-setuptools
python3-pip
python3.6
python3.6-dev
python3.6-venv
Copy link
Member

Choose a reason for hiding this comment

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

Should we drop 3.6? (also note python is aliased to python3.6 in dev-support/docker/Dockerfile)

Copy link
Contributor Author

@tvalentyn tvalentyn Nov 18, 2021

Choose a reason for hiding this comment

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

it's to be dropped in Beam 2.36.0 (after 2.35.0 release cut)

Copy link
Member

Choose a reason for hiding this comment

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

I see, that makes sense. I thought maybe we were already dropping it because of the for ver in 3.7 3.8 3.9; do in local-env-setup.sh

@@ -66,7 +66,7 @@ RUN alias python=python3.6
###
# Install grpcio-tools mypy-protobuf for `python3 sdks/python/setup.py sdist` to work
###
RUN pip3 install grpcio-tools mypy-protobuf virtualenv
RUN pip3 install grpcio-tools mypy-protobuf

###
# Install useful tools
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can drop distilib below? It says it's installed to workaround a virtualenv issue

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 believe I tried to remove it and still ran into some issues. We can try again later.

fi
if [ ! $(type -P python$ver) > /dev/null 2>&1 ]; then
# For some python packages, brew does not add symlinks...
# TODO: use pyenv.
Copy link
Member

Choose a reason for hiding this comment

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

What exactly is the TODO here? Will pyenv make symlinks for us?

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: # TODO: Consider using pyenv to manage multiple installations of Python.

@@ -14,6 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

# TODO: Consider PEP-517/PEP-518 instead of this file (BEAM-8954).
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
# TODO: Consider PEP-517/PEP-518 instead of this file (BEAM-8954).
# TODO(BEAM-8954): Consider PEP-517/PEP-518 instead of this file.

# TODO: Consider PEP-517/PEP-518 instead of this file (BEAM-8954).

setuptools
wheel>=0.36.0
Copy link
Member

Choose a reason for hiding this comment

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

why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are common build dependencies, however wheel is not installed by default into venv, but is installed in virtualenv-created env. without this change, installing from sdist was failing on some python 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.

setuptools is still implicitly installed, keeping it explicitly so that we add them when we adopt PEP-517/518 which might require them mentioned explicitly.


python -m dependency_check.dependency_check_report_generator Java
$PYTHON -m dependency_check.dependency_check_report_generator Java
Copy link
Member

Choose a reason for hiding this comment

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

Were you able to verify this (and other .test-infra changes)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems to work, thanks.

@@ -648,7 +646,7 @@ if [[ ("$python_xlang_kafka_taxi_dataflow" = true
do
rm -rf ./beam_env_${py_version}
echo "--------------Setting up virtualenv with $py_version interpreter----------------"
virtualenv beam_env_${py_version} -p $py_version
$py_version -m venv beam_env_${py_version}
Copy link
Member

Choose a reason for hiding this comment

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

Same question about the release script changes, but fortunately you are the next release manager, so I trust you'll be able to detect and fix any issues here.

@@ -22,6 +22,7 @@ plugins {
}

applyGoNature()
applyPythonNature()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this is needed for ./license_scripts/license_script.sh. Also, why is it that we need this now, but it seemed to work ok before?

@@ -20,6 +20,9 @@
set -e
set -v

# Get currently used Python version from args or assume a default.
PYTHON=${1:-python3}
Copy link
Member

Choose a reason for hiding this comment

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

Does this work if users are using an alias/symlink?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it should work. python3 is typically a symlink.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alias probably wouldn't work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

verified that symlinks work and aliases don't

@tvalentyn
Copy link
Contributor Author

Run Seed Job

@tvalentyn
Copy link
Contributor Author

Run Inventory apache-beam-jenkins-1

@tvalentyn
Copy link
Contributor Author

Run Dependency Check

@tvalentyn tvalentyn changed the title [BEAM-8152] Use venv instead of virtualenv to create Python environments in Gradle scripts. [BEAM-13183] [BEAM-8152] Use venv instead of virtualenv to create Python environments in Gradle scripts. Nov 18, 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.

3 participants