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

Fix setuptool dependency #220

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ function terra_caseify()
local download_conda=0
local conda_install

: ${PYTHON_VERSION=${TERRA_PYTHON_VERSION:-3.8.16}}
: ${PIPENV_VERSION=${TERRA_PIPENV_VERSION:-2023.4.29}}
: ${VIRTUALENV_VERSION=${TERRA_VIRTUALENV_VERSION:-20.23.0}}
: ${PYTHON_VERSION=${TERRA_PYTHON_VERSION:-3.12.9}}
: ${PIPENV_VERSION=${TERRA_PIPENV_VERSION:-2024.4.1}}
: ${VIRTUALENV_VERSION=${TERRA_VIRTUALENV_VERSION:-20.29.0}}

parse_args extra_args --dir output_dir: --python python_exe: --conda conda_exe: --download download_conda --conda-install conda_install: -- ${@+"${@}"}

Expand Down
1,176 changes: 544 additions & 632 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions terra/compute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from os import environ as env
from shlex import quote
from subprocess import Popen
import distutils.spawn
import shutil

from vsi.tools.diff import dict_diff

Expand Down Expand Up @@ -201,7 +201,7 @@ def just(*args, **kwargs):
# 0, 0, os.environ, None, None) even fails.
# Microsoft probably has a special exception for the word "bash" that
# calls WSL bash on execute :(
kwargs['executable'] = distutils.spawn.find_executable('bash')
kwargs['executable'] = shutil.which('bash')
# Have to call bash for windows compatibility, no shebang support
pid = Popen(('bash', 'just') + args, env=just_env, **kwargs)
return pid
6 changes: 3 additions & 3 deletions terra/compute/virtualenv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import distutils.spawn
import shutil
import json
import os
from subprocess import Popen
Expand Down Expand Up @@ -58,8 +58,8 @@ def run_service(self, service_info):
# executable is not found on the path, possibly because Popen doesn't
# search the env's path, but this will manually search and find the right
# command
executable = distutils.spawn.find_executable(service_info.command[0],
path=env['PATH'])
executable = shutil.which(service_info.command[0],
path=env['PATH'])

# Check if the executable was found in the virtualenv_dir.
# If it wasn't, warn the user in case they made a mistake
Expand Down
5 changes: 4 additions & 1 deletion terra/executor/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ def _acquire(self, lock_file, resource_index, repeat):
# This will break Windows locks
# https://github.com/tox-dev/py-filelock/issues/15
if self.FileLock == filelock.SoftFileLock:
os.write(lock._lock_file_fd, settings.terra.uuid.encode())
try:
os.write(lock._context.lock_file_fd, settings.terra.uuid.encode())
except AttributeError:
os.write(lock._lock_file_fd, settings.terra.uuid.encode())
# If you get this far, the lock is good, so save it in the class
self._local.lock = lock
self._local.resource_id = resource_index
Expand Down
15 changes: 11 additions & 4 deletions terra/tests/test_core_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import mock
import sys

from .utils import TestCase
from terra.core.utils import (
Expand Down Expand Up @@ -51,15 +52,21 @@ def test_cached_property_reuse_different_names(self):
"""
Disallow this case because the decorated function wouldn't be cached.
"""
with self.assertRaises(RuntimeError) as cm:
with self.assertRaises((TypeError, RuntimeError)) as cm:
class ReusedCachedProperty:
@cached_property
def a(self):
pass
b = a
self.assertIn(
"Cannot assign the same cached_property to two different names",
str(cm.exception.__context__))

if sys.version_info.major > 3 or sys.version_info.minor >= 12:
self.assertIn(
"Cannot assign the same cached_property to two different names",
str(cm.exception))
else: # 3.11 and older behavior
self.assertIn(
"Cannot assign the same cached_property to two different names",
str(cm.exception.__context__))

def test_class_mockability(self):
# Test that mocking works
Expand Down
19 changes: 15 additions & 4 deletions terra/tests/test_executor_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def test_release_on_delete(self):
test.acquire()

with self.assertLogs('terra.executor.resources', level='WARNING') as cm:
filename = test._local.lock._lock_file
try:
filename = test._local.lock._lock_file
except AttributeError:
filename = test._local.lock.lock_file
self.assertExist(filename)
del test
self.assertNotExist(filename)
Expand All @@ -138,8 +141,13 @@ def test_atexit(self):
test3.acquire()
test3.acquire()

filename2 = test2._local.lock._lock_file
filename3 = test3._local.lock._lock_file
try:
filename2 = test2._local.lock._lock_file
filename3 = test3._local.lock._lock_file
except AttributeError:
filename2 = test2._local.lock.lock_file
filename3 = test3._local.lock.lock_file

self.assertExist(filename2)
self.assertExist(filename3)
atexit_resource_release()
Expand Down Expand Up @@ -437,6 +445,7 @@ def simple_acquire(name):
if name not in data:
data[name] = Resource(name, 1, 1)
rv = data[name].acquire()
data[name].release()
return rv


Expand Down Expand Up @@ -490,14 +499,16 @@ def test_multiple_executor(self):
# way that means one executor after the other will not interfere with each
# other.
data[self.name] = Resource(self.name, 1, 1)

for _ in range(2):
futures = []
with self.Executor(max_workers=1) as executor:
futures.append(executor.submit(simple_acquire, self.name))
futures.append(executor.submit(simple_acquire, self.name))

for future in as_completed(futures):
future.result()

del future, executor
# double check resource was freed
data[self.name].acquire()
data[self.name].release()
Expand Down