Skip to content

Commit

Permalink
fix: update for minimum of Python 3.7 (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Mar 23, 2022
1 parent 5f7170e commit 62024e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -106,7 +106,7 @@
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.7",
"Topic :: Scientific/Engineering :: Bio-Informatics",
],
)
39 changes: 14 additions & 25 deletions snakemake/common/__init__.py
Expand Up @@ -21,7 +21,7 @@
del get_versions


MIN_PY_VERSION = (3, 5)
MIN_PY_VERSION = (3, 7)
DYNAMIC_FILL = "__snakemake_dynamic__"
SNAKEMAKE_SEARCHPATH = str(Path(__file__).parent.parent.parent)
UUID_NAMESPACE = uuid.uuid5(uuid.NAMESPACE_URL, "https://snakemake.readthedocs.io")
Expand All @@ -32,30 +32,19 @@
ON_WINDOWS = platform.system() == "Windows"


if sys.version_info < (3, 7):

def async_run(coroutine):
loop = asyncio.get_event_loop()
return loop.run_until_complete(coroutine)

else:

def async_run(coroutine):
"""Attaches to running event loop or creates a new one to execute a
coroutine.
.. seealso::
https://github.com/snakemake/snakemake/issues/1105
https://stackoverflow.com/a/65696398
"""
try:
_ = asyncio.get_running_loop()
except RuntimeError:
asyncio.run(coroutine)
else:
asyncio.create_task(coroutine)
def async_run(coroutine):
"""Attaches to running event loop or creates a new one to execute a
coroutine.
.. seealso::
https://github.com/snakemake/snakemake/issues/1105
https://stackoverflow.com/a/65696398
"""
try:
_ = asyncio.get_running_loop()
except RuntimeError:
asyncio.run(coroutine)
else:
asyncio.create_task(coroutine)


# A string that prints as TBD
Expand Down
5 changes: 1 addition & 4 deletions tests/testapi.py
Expand Up @@ -53,10 +53,7 @@ async def main():
async_run(dummy_task())
test_run_script_directive()

if sys.version_info < (3, 7):
async_run(main())
else:
asyncio.run(main())
asyncio.run(main())


def test_dicts_in_config():
Expand Down

0 comments on commit 62024e2

Please sign in to comment.