Skip to content

Commit

Permalink
Fix pyright complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Sep 26, 2023
1 parent 1fd8a80 commit e4680c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/remoting/python-remoting/nexus_remoting/_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _try_encode(value: Any, options: JsonEncoderOptions) -> Any:

# None
if value is None:
return typing.cast(T, None)
return None

# list/tuple
elif isinstance(value, list) or isinstance(value, tuple):
Expand Down Expand Up @@ -192,7 +192,7 @@ def _decode_timedelta(value: str):
seconds = int(match.group(4))
microseconds = int(match.group(5)) / 10.0 if match.group(5) else 0

return typing.cast(T, timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds))
return timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)

else:
raise Exception(f"Unable to decode {value} into value of type timedelta.")
Expand Down
13 changes: 10 additions & 3 deletions tests/Nexus.Sources.Remote.Tests/python/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@

class PythonDataSource(IDataSource):

_root: str

async def set_context(self, context, logger):

self._context: DataSourceContext = context

if (context.resource_locator is None or context.resource_locator.path is None):
raise Exception(f"No resource locator provided.")

if (context.resource_locator.scheme != "file"):
raise Exception(f"Expected 'file' URI scheme, but got '{context.resource_locator.scheme}'.")

self._root = context.resource_locator.path

logger.log(LogLevel.Information, "Logging works!")

async def get_catalog_registrations(self, path: str):
Expand Down Expand Up @@ -85,7 +92,7 @@ async def get_time_range(self, catalog_id: str):
if catalog_id != "/A/B/C":
raise Exception("Unknown catalog identifier.")

file_paths = glob.glob(url2pathname(self._context.resource_locator.path) + "/**/*.dat", recursive=True)
file_paths = glob.glob(url2pathname(self._root) + "/**/*.dat", recursive=True)
file_names = [os.path.basename(file_path) for file_path in file_paths]
date_times = sorted([datetime.strptime(fileName, '%Y-%m-%d_%H-%M-%S.dat') for fileName in file_names])
begin = date_times[0].replace(tzinfo = timezone.utc)
Expand All @@ -100,7 +107,7 @@ async def get_availability(self, catalog_id: str, begin: datetime, end: datetime

period_per_file = timedelta(minutes = 10)
max_file_count = (end - begin).total_seconds() / period_per_file.total_seconds()
file_paths = glob.glob(url2pathname(self._context.resource_locator.path) + "/**/*.dat", recursive=True)
file_paths = glob.glob(url2pathname(self._root) + "/**/*.dat", recursive=True)
file_names = [os.path.basename(file_path) for file_path in file_paths]
date_times = [datetime.strptime(fileName, '%Y-%m-%d_%H-%M-%S.dat') for fileName in file_names]
filtered_date_times = [current for current in date_times if current >= begin and current < end]
Expand Down Expand Up @@ -152,7 +159,7 @@ async def _read_local_files(
while current_begin < end:

# find files
search_pattern = url2pathname(self._context.resource_locator.path) + \
search_pattern = url2pathname(self._root) + \
f"/{current_begin.strftime('%Y-%m')}/{current_begin.strftime('%Y-%m-%d')}/*.dat"

file_paths = glob.glob(search_pattern, recursive=True)
Expand Down

0 comments on commit e4680c5

Please sign in to comment.