-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/update python project #655
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a1c771e
Update to newer Poetry.
yruslan 78fc9ca
Update Spark version.
yruslan c3c2459
Move PyTest to optional dependencies.
yruslan 2b4bd17
Fix an lint error from CI.
yruslan b6dcec7
Move Pytest to test dependencies.
yruslan 102a099
Update Poetry for lint runs as well.
yruslan 8c4117b
Revert the linter fix.
yruslan 8a87f48
Move test dependencies in a separate group.
yruslan e06c4a0
Add type ignore for one line error.
yruslan 32de8b6
Add missing setuptools.
yruslan eac4340
User explicit replacewhere=true
yruslan d83d182
Downgrading Spark to 3.5.5 to workaround this issue: https://github.c…
yruslan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
|
|
||
| [tool.black] | ||
| line-length = 79 | ||
| target-version = ["py36"] | ||
| target-version = ["py310"] | ||
|
|
||
| [tool.isort] | ||
| atomic = true | ||
|
|
@@ -84,65 +84,69 @@ minversion = "6.0.0" | |
| addopts = "-vv -s --tb=native -n auto" | ||
| testpaths = "tests/" | ||
|
|
||
| [tool.poetry] | ||
| [project] | ||
| name = "pramen-py" | ||
| version = "1.11.1" | ||
| description = "Pramen transformations written in python" | ||
| authors = [ | ||
| "Artem Zhukov <[email protected]>", | ||
| "Valerii Khalimendik <[email protected]>", | ||
| "Jiří Filip <[email protected]>" | ||
| { name = "Artem Zhukov", email = "[email protected]" }, | ||
| { name = "Valerii Khalimendik", email = "[email protected]" }, | ||
| { name = "Jiří Filip", email = "[email protected]" } | ||
| ] | ||
| maintainers = [ | ||
| "Artem Zhukov <[email protected]>", | ||
| "Valerii Khalimendik <[email protected]>", | ||
| "Jiří Filip <[email protected]>" | ||
| { name = "Artem Zhukov", email = "[email protected]" }, | ||
| { name = "Valerii Khalimendik", email = "[email protected]" }, | ||
| { name = "Jiří Filip", email = "[email protected]" } | ||
| ] | ||
| readme = "README.md" | ||
| repository = "https://github.com/AbsaOSS/pramen" | ||
| packages = [ | ||
| { include = "pramen_py", from = "src" }, | ||
| { include = "pramen_py/py.typed", from = "src" }, | ||
| { include = "transformations" }, | ||
| ] | ||
| keywords = ["paramen", "pyspark", "transformations", "metastore"] | ||
| include = [ | ||
| ".env.example", | ||
| "tests/resources/real_config.yaml", | ||
| ] | ||
|
|
||
| [tool.poetry.plugins] | ||
| [tool.poetry.plugins."pytest11"] | ||
| "pramen_py" = "pramen_py.test_utils.plugin" | ||
| requires-python = ">=3.9,<4.0" | ||
|
|
||
| dependencies = [ | ||
| "click>=8.0.3", | ||
| "attrs>=21.4.0", | ||
| "rich>=11.1.0", | ||
| "contextvars>=2.4", | ||
| "environs>=9.5.0", | ||
| "PyYAML>=6.0", | ||
| "cattrs>=1.0.0; python_version<'3.7'", | ||
| "cattrs>=22.1.0; python_version>='3.7'", | ||
| "pyspark==3.5.7", | ||
| "loguru>=0.6.0", | ||
| "typing-extensions>=4.1.1", | ||
| "pyhocon>=0.3.59" | ||
| ] | ||
|
|
||
| [tool.poetry.scripts] | ||
| [project.entry-points.pytest11] | ||
| pramen_py = "pramen_py.test_utils.plugin" | ||
|
|
||
| [project.scripts] | ||
| pramen-py = "pramen_py.app.cli:main" | ||
|
|
||
| [tool.poetry.dependencies] | ||
| python = ">=3.6.8,<4.0" | ||
| click = "^8.0.3" | ||
| attrs = "^21.4.0" | ||
| rich = "^11.1.0" | ||
| contextvars = "^2.4" | ||
| environs = "^9.5.0" | ||
| PyYAML = "^6.0" | ||
| cattrs = [ | ||
| {version="1.0.0", python = ">=3.6.8,<3.7"}, | ||
| {version="^22.1.0", python = ">=3.7,<4.0"}, | ||
| [tool.poetry] | ||
| packages = [ | ||
| { include = "pramen_py", from = "src" }, | ||
| { include = "pramen_py/py.typed", from = "src" }, | ||
| { include = "transformations" }, | ||
| ] | ||
| pyspark = "3.1.3" | ||
| loguru = "^0.6.0" | ||
| pytest = "6.2.5" | ||
| pytest-asyncio = "0.16" | ||
| pytest-cov = "2.12.1" | ||
|
|
||
| [tool.poetry.group.test.dependencies] | ||
| pytest = "^6.2.5" | ||
| pytest-asyncio = "^0.16" | ||
| pytest-cov = "^2.12.1" | ||
| types-PyYAML = "^6.0.4" | ||
| chispa = "^0.9.2" | ||
| pytest-sugar = "^0.9.4" | ||
| pytest-mock = "3.6.1" | ||
| typing-extensions = "^4.1.1" | ||
| pyhocon = "^0.3.59" | ||
| pytest-mock = "^3.6.1" | ||
| setuptools = "^67.6.1" | ||
|
|
||
| [tool.poetry.dev-dependencies] | ||
| [tool.poetry.group.dev.dependencies] | ||
| neovim = "^0.3.1" | ||
| pdbpp = "^0.10.3" | ||
| isort = "^5.10.1" | ||
|
|
@@ -154,5 +158,5 @@ pytest-xdist = "^2.5.0" | |
| pyspark-stubs = "2.3.0.post2" | ||
|
|
||
| [build-system] | ||
| requires = ["poetry>=1.2.0"] | ||
| requires = ["poetry>=2.1.3"] | ||
| build-backend = "poetry.masonry.api" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
run_until_complete()will fail if a loop is already running.If
asyncio.get_running_loop()succeeds (line 126), it means the event loop is already running. Callingloop.run_until_complete()(line 132) on an already-running loop raisesRuntimeError: This event loop is already running. This breaks the decorator when called from async contexts.The recommended fix depends on the intended use case:
Option 1: Prohibit calling from async contexts (simpler, matches typical sync-wrapper semantics):
@wraps(f) def wrapper( *args: object, **kwargs: object, ) -> OPS_RET: - try: - # Try to get the running event loop (Python 3.7+) - loop = asyncio.get_running_loop() - except RuntimeError: - # No running loop, create a new one - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - + # Ensure we're not inside a running loop + try: + asyncio.get_running_loop() + raise RuntimeError( + f"{f.__name__} cannot be called from an async context. " + "Call the async function directly instead." + ) + except RuntimeError: + pass # No running loop, proceed + + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: - return loop.run_until_complete(f(*args, **kwargs)) + return loop.run_until_complete(f(*args, **kwargs)) + finally: + loop.close()Option 2: Support both sync and async contexts (more complex):
@wraps(f) def wrapper( *args: object, **kwargs: object, ) -> OPS_RET: try: - # Try to get the running event loop (Python 3.7+) loop = asyncio.get_running_loop() + # Already in async context, schedule as task + import asyncio + task = asyncio.create_task(f(*args, **kwargs)) + # This path should ideally return a coroutine, but the signature + # doesn't allow it. Consider redesigning if this path is needed. + raise RuntimeError( + f"{f.__name__} cannot be called from an async context. " + "Call the async function directly." + ) except RuntimeError: # No running loop, create a new one loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - - return loop.run_until_complete(f(*args, **kwargs)) + try: + return loop.run_until_complete(f(*args, **kwargs)) + finally: + loop.close()Recommendation: Use Option 1 unless there's a specific requirement to support calls from async contexts. Also consider adding
loop.close()in afinallyblock to prevent resource leaks.🤖 Prompt for AI Agents