Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions .agent/skills/python-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ Use `--requirements_file=requirements.txt` or custom containers.
## Code Quality Tools
```bash
# Linting
pylint apache_beam/
ruff check apache_beam/

# Type checking
mypy apache_beam/
pyrefly check apache_beam/

# Formatting (via yapf)
yapf -i apache_beam/file.py
Expand Down
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ repos:
sdks/python/apache_beam/portability/api/.*pb2.*.py
)$

- repo: https://github.com/pycqa/pylint
# this rev is a release tag in the repo above and corresponds with a pylint
# version. make sure this matches the version of pylint in tox.ini.
rev: v4.0.2
- repo: https://github.com/astral-sh/ruff-pre-commit
# this rev is a release tag in the repo above and corresponds with a ruff
# version. make sure this matches the version of yapf in setup.py
Comment thread
jrmccluskey marked this conversation as resolved.
Outdated
rev: v0.15.7
hooks:
- id: pylint
args: ["--rcfile=sdks/python/.pylintrc"]
files: ^sdks/python/apache_beam/
exclude: *exclude
- id: ruff-check
files: "sdks/python/apache_beam"
Comment thread
jrmccluskey marked this conversation as resolved.
Outdated
args: ["--config=sdks/python/ruff.toml"]
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

def _ts(*args, **kwargs) -> Timestamp:
"""Create a UTC datetime and return a Beam Timestamp."""
# pyrefly: ignore[bad-keyword-argument]
dt = datetime.datetime(*args, tzinfo=datetime.timezone.utc, **kwargs)
return Timestamp(dt.timestamp())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def run_inference(

# Wrap plain strings in a Content object
if isinstance(element, str):
# pyrefly: ignore[bad-instantiation]
message = genai_Content(role="user", parts=[genai_Part(text=element)])
else:
# Assume the caller has already constructed a types.Content object
Expand Down
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/typehints/typehints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ def test_type_checks_not_dict(self):

def test_type_check_collection(self):
hint = typehints.Dict[str, int]
l = collections.defaultdict(list[("blue", 2)])
element = ("blue", 2)
l = collections.defaultdict(list[element])
self.assertIsNone(hint.type_check(l))

def test_type_check_invalid_key_type(self):
Expand Down
96 changes: 96 additions & 0 deletions sdks/python/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# 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.
#

exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
"*.pxd",
"*.pyx",
"*pb2*.py",
"**/examples/**/*.py",
"**/examples/**/*.ipynb",
"**/portability/api/**/*.py",
"**/portability/api/__init__.py",
]

target-version = "py310"

src = ["apache_beam"]

[lint]
select = ["E9", "PL", "F821", "F822", "F823"]
ignore = [
# Ignored Pylint Checks
"PLC0415", # import-outside-toplevel
"PLR2004", # magic-value-comparison
"PLR0913", # too-many-arguments
"PLR0912", # too-many-branches
"PLW0108", # unnecessary-lambda
"PLW2901", # redefined-loop-name
"PLR0915", # too-many-statements
"PLR1714", # repeated-equality-comparison
"PLR0911", # too-many-return-statements
"PLR5501", # collapsible-else-if
"PLW0603", # global-statement
"PLR1730", # if-stmt-min-max
"PLW1641", # eq-without-hash
"PLW0602", # global-variable-not-assigned
"PLC1802", # len-test
"PLC3002", # unnecessary-direct-lambda-call
"PLW0642", # self-or-cls-assignment
"PLR1733", # unnecessary-dict-index-lookup
"PLR0402", # manual-from-import
"PLC0132", # type-param-name-mismatch
"PLC0206", # dict-index-missing-items
"PLC0207", # missing-maxsplit-arg
"PLR1704", # redefined-argument-from-local
"PLR1711", # useless-return
"PLW0406", # import-self
"PLW3301", # nested-min-max
"PLR2044", # empty-comment
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
7 changes: 2 additions & 5 deletions sdks/python/scripts/run_pylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ done
echo -e "Skipping lint for files:\n${FILES_TO_IGNORE}"
echo -e "Linting modules:\n${MODULE}"

echo "Running pylint..."
pylint -j8 ${MODULE} --ignore-patterns="$FILES_TO_IGNORE"
echo "Running flake8..."
flake8 ${MODULE} --count --select=E9,F821,F822,F823 --show-source --statistics \
--exclude="${FILES_TO_IGNORE}"
echo "Running ruff..."
ruff check ${MODULE} --extend-exclude="$FILES_TO_IGNORE"

echo "Running isort..."
# Skip files where isort is behaving weirdly
Expand Down
14 changes: 10 additions & 4 deletions sdks/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def normalize_path(filename):
return os.path.normcase(os.path.realpath(os.path.normpath(filename)))


class mypy(Command):
class pyrefly(Command):
user_options = []

def initialize_options(self):
Expand All @@ -71,10 +71,10 @@ def get_project_path(self):
return os.path.join(project_path, to_filename(ei_cmd.egg_name))

def run(self):
args = ['mypy', self.get_project_path()]
args = ['pyrefly', 'check', self.get_project_path()]
result = subprocess.call(args)
if result != 0:
raise DistutilsError("mypy exited with status %d" % result)
raise DistutilsError("pyrefly exited with status %d" % result)


def get_version():
Expand Down Expand Up @@ -424,6 +424,12 @@ def get_portability_package_data():
python_requires=python_requires,
# BEAM-8840: Do NOT use tests_require or setup_requires.
extras_require={
'dev': [
'isort==7.0.0',
'pyrefly==0.54.0',
'ruff==0.15.7',
'yapf==0.43.0',
],
'dill': [
# Dill doesn't have forwards-compatibility guarantees within minor
# version. Pickles created with a new version of dill may not
Expand Down Expand Up @@ -659,6 +665,6 @@ def get_portability_package_data():
license='Apache License, Version 2.0',
keywords=PACKAGE_KEYWORDS,
cmdclass={
'mypy': mypy,
'pyrefly': pyrefly,
},
)
4 changes: 2 additions & 2 deletions sdks/python/test-suites/tox/pycommon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ check.dependsOn formatter
toxTask "lint", "lint", "${posargs}"
linter.dependsOn lint

toxTask "mypy", "mypy", "${posargs}"
linter.dependsOn mypy
// toxTask "mypy", "mypy", "${posargs}"
// linter.dependsOn mypy
Comment thread
jrmccluskey marked this conversation as resolved.
Outdated
Comment thread
jrmccluskey marked this conversation as resolved.
Outdated
17 changes: 9 additions & 8 deletions sdks/python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,17 @@ commands =
[testenv:lint]
# Don't set TMPDIR to avoid "AF_UNIX path too long" errors in pylint.
setenv =
# keep the version of pylint in sync with the 'rev' in .pre-commit-config.yaml
deps =
astroid<4.1.0,>=4.0.1
pycodestyle==2.8.0
pylint==4.0.2
isort==7.0.0
flake8==4.0.1
dask==2022.01.0
distributed==2022.01.0
extras =
gcp
dev
commands =
pylint --version
ruff --version
time {toxinidir}/scripts/run_pylint.sh
pyrefly --version
time python setup.py pyrefly

[testenv:whitespacelint]
setenv =
Expand All @@ -218,7 +219,7 @@ extras =
gcp
commands =
mypy --version
python setup.py mypy
time python setup.py mypy
Comment thread
jrmccluskey marked this conversation as resolved.
Outdated


[testenv:docs]
Expand Down
Loading