mattdeitke commited on
Commit
96eeaba
1 Parent(s): baf1745

fix linter errors

Browse files
objaverse_xl/abstract.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from abc import ABC, abstractmethod
2
  from typing import Callable, Dict, Optional
3
 
@@ -5,6 +7,8 @@ import pandas as pd
5
 
6
 
7
  class ObjaverseSource(ABC):
 
 
8
  @abstractmethod
9
  def get_annotations(self, download_dir: str = "~/.objaverse") -> pd.DataFrame:
10
  """Loads the 3D object metadata as a Pandas DataFrame.
 
1
+ """Abstract class for Objaverse-XL sources."""
2
+
3
  from abc import ABC, abstractmethod
4
  from typing import Callable, Dict, Optional
5
 
 
7
 
8
 
9
  class ObjaverseSource(ABC):
10
+ """Abstract class for Objaverse-XL sources."""
11
+
12
  @abstractmethod
13
  def get_annotations(self, download_dir: str = "~/.objaverse") -> pd.DataFrame:
14
  """Loads the 3D object metadata as a Pandas DataFrame.
objaverse_xl/github.py CHANGED
@@ -131,7 +131,7 @@ class GitHubDownloader(ObjaverseSource):
131
  handle_missing_object: Optional[Callable],
132
  handle_new_object: Optional[Callable],
133
  commit_hash: Optional[str],
134
- ) -> Dict[str, Optional[str]]:
135
  """Process a single repo.
136
 
137
  Args:
@@ -144,8 +144,8 @@ class GitHubDownloader(ObjaverseSource):
144
  {and the rest of the args are the same as download_objects}
145
 
146
  Returns:
147
- Dict[str, Optional[str]]: A dictionary that maps from the "fileIdentifier" to the
148
- path of the downloaded object.
149
  """
150
  # NOTE: assuming that the user has already checked that the repo doesn't exist,
151
  org, repo = repo_id.split("/")
@@ -268,9 +268,8 @@ class GitHubDownloader(ObjaverseSource):
268
  shutil.rmtree(os.path.join(target_directory, ".git"))
269
 
270
  if save_repo_format is None:
271
- # remove the relative path, since it's not downloaded
272
- for file_identifier in out:
273
- out[file_identifier] = None
274
  else:
275
  logger.debug(f"Saving {org}/{repo} as {save_repo_format}")
276
  # save the repo to a zip file
@@ -302,7 +301,7 @@ class GitHubDownloader(ObjaverseSource):
302
  os.path.join(dirname, f"{repo}.{save_repo_format}"),
303
  )
304
 
305
- for file_identifier in out:
306
  out[file_identifier] = os.path.join(
307
  dirname, f"{repo}.{save_repo_format}", out[file_identifier]
308
  )
@@ -310,7 +309,7 @@ class GitHubDownloader(ObjaverseSource):
310
  # move the repo to the correct location (with put)
311
  fs.put(target_directory, dirname, recursive=True)
312
 
313
- for file_identifier in out:
314
  out[file_identifier] = os.path.join(
315
  dirname, repo, out[file_identifier]
316
  )
@@ -360,7 +359,7 @@ class GitHubDownloader(ObjaverseSource):
360
  commit_hash = result.stdout.strip().decode("utf-8")
361
  return commit_hash
362
 
363
- def _parallel_process_repo(self, args) -> Dict[str, Optional[str]]:
364
  """Helper function to process a repo in parallel.
365
 
366
  Note: This function is used to parallelize the processing of repos. It is not
@@ -370,8 +369,8 @@ class GitHubDownloader(ObjaverseSource):
370
  args (Tuple): Tuple of arguments to pass to _process_repo.
371
 
372
  Returns:
373
- Dict[str, Optional[str]]: A dictionary that maps from the "fileIdentifier"
374
- to the path of the downloaded object.
375
  """
376
 
377
  (
@@ -412,11 +411,8 @@ class GitHubDownloader(ObjaverseSource):
412
  handle_found_object: Optional[Callable] = None,
413
  handle_modified_object: Optional[Callable] = None,
414
  handle_missing_object: Optional[Callable] = None,
415
- *,
416
- save_repo_format: Optional[Literal["zip", "tar", "tar.gz", "files"]] = None,
417
- handle_new_object: Optional[Callable] = None,
418
  **kwargs,
419
- ) -> Dict[str, Optional[str]]:
420
  """Download the specified GitHub objects.
421
 
422
  Args:
@@ -490,9 +486,12 @@ class GitHubDownloader(ObjaverseSource):
490
  Otherwise, we don't know where to save the repo!
491
 
492
  Returns:
493
- Dict[str, Optional[str]]: A dictionary that maps from the "fileIdentifier" to the
494
- path of the downloaded object.
495
  """
 
 
 
496
  if processes is None:
497
  processes = multiprocessing.cpu_count()
498
  if download_dir is None:
 
131
  handle_missing_object: Optional[Callable],
132
  handle_new_object: Optional[Callable],
133
  commit_hash: Optional[str],
134
+ ) -> Dict[str, str]:
135
  """Process a single repo.
136
 
137
  Args:
 
144
  {and the rest of the args are the same as download_objects}
145
 
146
  Returns:
147
+ Dict[str, str]: A dictionary that maps from the "fileIdentifier" to the path
148
+ of the downloaded object.
149
  """
150
  # NOTE: assuming that the user has already checked that the repo doesn't exist,
151
  org, repo = repo_id.split("/")
 
268
  shutil.rmtree(os.path.join(target_directory, ".git"))
269
 
270
  if save_repo_format is None:
271
+ # remove the paths, since it's not downloaded
272
+ out = {}
 
273
  else:
274
  logger.debug(f"Saving {org}/{repo} as {save_repo_format}")
275
  # save the repo to a zip file
 
301
  os.path.join(dirname, f"{repo}.{save_repo_format}"),
302
  )
303
 
304
+ for file_identifier in out.copy():
305
  out[file_identifier] = os.path.join(
306
  dirname, f"{repo}.{save_repo_format}", out[file_identifier]
307
  )
 
309
  # move the repo to the correct location (with put)
310
  fs.put(target_directory, dirname, recursive=True)
311
 
312
+ for file_identifier in out.copy():
313
  out[file_identifier] = os.path.join(
314
  dirname, repo, out[file_identifier]
315
  )
 
359
  commit_hash = result.stdout.strip().decode("utf-8")
360
  return commit_hash
361
 
362
+ def _parallel_process_repo(self, args) -> Dict[str, str]:
363
  """Helper function to process a repo in parallel.
364
 
365
  Note: This function is used to parallelize the processing of repos. It is not
 
369
  args (Tuple): Tuple of arguments to pass to _process_repo.
370
 
371
  Returns:
372
+ Dict[str, str]: A dictionary that maps from the "fileIdentifier" to the path
373
+ of the downloaded object.
374
  """
375
 
376
  (
 
411
  handle_found_object: Optional[Callable] = None,
412
  handle_modified_object: Optional[Callable] = None,
413
  handle_missing_object: Optional[Callable] = None,
 
 
 
414
  **kwargs,
415
+ ) -> Dict[str, str]:
416
  """Download the specified GitHub objects.
417
 
418
  Args:
 
486
  Otherwise, we don't know where to save the repo!
487
 
488
  Returns:
489
+ Dict[str, str]: A dictionary that maps from the "fileIdentifier" to the path
490
+ of the downloaded object.
491
  """
492
+ save_repo_format = kwargs.get("save_repo_format", None)
493
+ handle_new_object = kwargs.get("handle_new_object", None)
494
+
495
  if processes is None:
496
  processes = multiprocessing.cpu_count()
497
  if download_dir is None:
objaverse_xl/objaverse_v1.py CHANGED
@@ -189,7 +189,6 @@ class SketchfabDownloader(ObjaverseSource):
189
  expected_sha256: str,
190
  handle_found_object: Optional[Callable] = None,
191
  handle_modified_object: Optional[Callable] = None,
192
- handle_missing_object: Optional[Callable] = None,
193
  ) -> Tuple[str, Optional[str]]:
194
  """Download the object for the given uid.
195
 
@@ -412,7 +411,7 @@ class SketchfabDownloader(ObjaverseSource):
412
  handle_missing_object(
413
  file_identifier=item["fileIdentifier"],
414
  sha256=item["sha256"],
415
- metadata=dict(),
416
  )
417
  continue
418
  objects_to_download.append(
@@ -456,7 +455,7 @@ class SketchfabDownloader(ObjaverseSource):
456
  handle_missing_object(
457
  file_identifier=item["fileIdentifier"],
458
  sha256=item["sha256"],
459
- metadata=dict(),
460
  )
461
  continue
462
  objects_to_download.append(
@@ -479,7 +478,6 @@ class SketchfabDownloader(ObjaverseSource):
479
  sha256,
480
  handle_found_object,
481
  handle_modified_object,
482
- handle_missing_object,
483
  )
484
  for file_identifier, hf_object_path, sha256 in objects_to_download
485
  ]
 
189
  expected_sha256: str,
190
  handle_found_object: Optional[Callable] = None,
191
  handle_modified_object: Optional[Callable] = None,
 
192
  ) -> Tuple[str, Optional[str]]:
193
  """Download the object for the given uid.
194
 
 
411
  handle_missing_object(
412
  file_identifier=item["fileIdentifier"],
413
  sha256=item["sha256"],
414
+ metadata={},
415
  )
416
  continue
417
  objects_to_download.append(
 
455
  handle_missing_object(
456
  file_identifier=item["fileIdentifier"],
457
  sha256=item["sha256"],
458
+ metadata={},
459
  )
460
  continue
461
  objects_to_download.append(
 
478
  sha256,
479
  handle_found_object,
480
  handle_modified_object,
 
481
  )
482
  for file_identifier, hf_object_path, sha256 in objects_to_download
483
  ]
objaverse_xl/objaverse_xl_downloader.py CHANGED
@@ -59,12 +59,12 @@ class ObjaverseXLDownloader(ObjaverseSource):
59
  objects (pd.DataFrame): Objects to download. Must have columns for
60
  the object "fileIdentifier" and "sha256". Use the `get_annotations`
61
  function to get the metadata.
62
- processes (Optional[int], optional): Number of processes to use for
63
- downloading. If None, will use the number of CPUs on the machine.
64
- Defaults to None.
65
  download_dir (str, optional): Directory to download the objects to.
66
  Supports all file systems supported by fsspec. Defaults to
67
  "~/.objaverse".
 
 
 
68
  save_repo_format (Optional[Literal["zip", "tar", "tar.gz", "files"]],
69
  optional): Format to save the repository. If None, the repository will
70
  not be saved. If "files" is specified, each file will be saved
 
59
  objects (pd.DataFrame): Objects to download. Must have columns for
60
  the object "fileIdentifier" and "sha256". Use the `get_annotations`
61
  function to get the metadata.
 
 
 
62
  download_dir (str, optional): Directory to download the objects to.
63
  Supports all file systems supported by fsspec. Defaults to
64
  "~/.objaverse".
65
+ processes (Optional[int], optional): Number of processes to use for
66
+ downloading. If None, will use the number of CPUs on the machine.
67
+ Defaults to None.
68
  save_repo_format (Optional[Literal["zip", "tar", "tar.gz", "files"]],
69
  optional): Format to save the repository. If None, the repository will
70
  not be saved. If "files" is specified, each file will be saved
objaverse_xl/thingiverse.py CHANGED
@@ -239,11 +239,12 @@ class ThingiverseDownloader(ObjaverseSource):
239
  def download_objects(
240
  self,
241
  objects: pd.DataFrame,
242
- processes: Optional[int] = None,
243
  download_dir: Optional[str] = "~/.objaverse",
 
244
  handle_found_object: Optional[Callable] = None,
245
  handle_modified_object: Optional[Callable] = None,
246
  handle_missing_object: Optional[Callable] = None,
 
247
  ) -> Dict[str, str]:
248
  """Download the objects from the given list of things and files.
249
 
@@ -251,10 +252,11 @@ class ThingiverseDownloader(ObjaverseSource):
251
  objects (pd.DataFrame): Thingiverse objects to download. Must have columns
252
  for the object "fileIdentifier" and "sha256". Use the `get_annotations`
253
  function to get the metadata.
 
 
254
  processes (int, optional): The number of processes to use. If None, maps to
255
- use all available CPUs using multiprocessing.cpu_count(). Defaults to None.
256
- download_dir (str, optional): The directory to save the files to. Supports all
257
- file systems supported by fsspec. Defaults to "~/.objaverse-xl".
258
  handle_found_object (Optional[Callable], optional): Called when an object is
259
  successfully found and downloaded. Here, the object has the same sha256
260
  as the one that was downloaded with Objaverse-XL. If None, the object
 
239
  def download_objects(
240
  self,
241
  objects: pd.DataFrame,
 
242
  download_dir: Optional[str] = "~/.objaverse",
243
+ processes: Optional[int] = None,
244
  handle_found_object: Optional[Callable] = None,
245
  handle_modified_object: Optional[Callable] = None,
246
  handle_missing_object: Optional[Callable] = None,
247
+ **kwargs,
248
  ) -> Dict[str, str]:
249
  """Download the objects from the given list of things and files.
250
 
 
252
  objects (pd.DataFrame): Thingiverse objects to download. Must have columns
253
  for the object "fileIdentifier" and "sha256". Use the `get_annotations`
254
  function to get the metadata.
255
+ download_dir (str, optional): The directory to save the files to. Supports
256
+ all file systems supported by fsspec. Defaults to "~/.objaverse-xl".
257
  processes (int, optional): The number of processes to use. If None, maps to
258
+ use all available CPUs using multiprocessing.cpu_count(). Defaults to
259
+ None.
 
260
  handle_found_object (Optional[Callable], optional): Called when an object is
261
  successfully found and downloaded. Here, the object has the same sha256
262
  as the one that was downloaded with Objaverse-XL. If None, the object
tests/test_api.py CHANGED
@@ -224,7 +224,7 @@ def test_github_handle_found_object():
224
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
225
  )
226
 
227
- assert len(out) == 3
228
  assert len(found_objects) == 3
229
  assert len(missing_objects) == 0
230
  assert len(new_objects) == 0
@@ -302,7 +302,7 @@ def test_github_handle_modified_object():
302
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
303
  )
304
 
305
- assert len(out) == 3
306
  assert len(found_objects) == 2
307
  assert len(missing_objects) == 0
308
  assert len(new_objects) == 0
@@ -381,7 +381,7 @@ def test_github_handle_missing_object():
381
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
382
  )
383
 
384
- assert len(out) == 3
385
  assert len(found_objects) == 3
386
  assert len(missing_objects) == 1
387
  assert len(new_objects) == 0
 
224
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
225
  )
226
 
227
+ assert len(out) == 0
228
  assert len(found_objects) == 3
229
  assert len(missing_objects) == 0
230
  assert len(new_objects) == 0
 
302
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
303
  )
304
 
305
+ assert len(out) == 0
306
  assert len(found_objects) == 2
307
  assert len(missing_objects) == 0
308
  assert len(new_objects) == 0
 
381
  commit_hash="6928b08a2501aa7a4a4aabac1f888b66e7782056",
382
  )
383
 
384
+ assert len(out) == 0
385
  assert len(found_objects) == 3
386
  assert len(missing_objects) == 1
387
  assert len(new_objects) == 0