Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Sources.py: quick wins, split into a package, and API unification

Đang mở
#150 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
opencv, python
Lĩnh vực
api, backend, computer-vision

Hướng nghiên cứu

Start with the ordered quick wins in src/machinevisiontoolbox/Sources.py; each is scoped as a separate small PR, and the file itself is the entry point. For the package split, first land the quick wins, then move the classes into the named modules and preserve public exports and private availability flags. Verify imports and run tests/test_image_sources.py and tests/test_ros.py (the latter needs the ros extra); the API unification items need discussion before work starts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

help wanted tech-debt

src/machinevisiontoolbox/Sources.py is about 4250 lines and holds every image source class: VideoFile, VideoCamera, WebCam, EarthView, FileCollection, FileArchive, ImageSequence, TensorStack, PointCloudSequence, LabelMeReader, and the ROS classes (ROSTopic, SyncROSStreams, ROSBag). The ROS code alone is roughly 40% of the file, and depends one-way on the rest. This issue collects the work to tidy it up. Contributions are welcome: items are ordered, and the first group needs no design decisions.

The RealSense ROSBag decoding bug is tracked separately (#151), because it is a user-facing defect and can be fixed independently.

1. Quick wins (no API change, one small PR each is fine)

  • VideoFile: raise a clear error when the file cannot be opened, instead of failing later with AttributeError on a None capture.
  • LabelMeReader: raise on bad input instead of return None.
  • ImageSource: the hasattr(self, "__len__") checks (in __init__ and the iteration setup) are dead code, since the class defines the attribute; replace them with a real test.
  • Add timeouts to urllib.request.urlretrieve / urlopen (ROSBag URL download, LabelMeReader) and to the Event.wait() calls in ROSTopic, so a stalled connection cannot hang forever.
  • Delete the unused _PC2_DTYPE table and the if __name__ == "__main__": block at the bottom.
  • Fix docstring errors: prop/property in the camera-property methods, the duplicated show_allowed entry in ROSBag.print, tol/tolerance, and the "coolumn" typo.
  • docs/source/sources.rst documents a read() method that does not exist; docs/source/ros.rst call signatures need checking against the code.
  • Collapse the repeated colororder branching (about ten copies) into one helper that wraps an array as an Image.
  • ROSBag: replace print() with logging (about 30 print calls in the file).

2. Split into a package (pure move, its own PR, no behaviour change)

git mv Sources.py Sources/__init__.py, then move classes into _base.py (ImageSource and shared helpers), video.py, files.py, archive.py, web.py, tensor.py, labelme.py, pointcloud.py and ros.py.

  • __init__.py must re-export every public name and the private availability flags that tests read via getattr.
  • Update test patch targets that name Sources.safe_plt_show, and check the Sphinx currentmodule directives.
  • Verify with an import of every public name from both machinevisiontoolbox and machinevisiontoolbox.Sources, then tests/test_image_sources.py and tests/test_ros.py (needs the ros extra).
  • Optional follow-up: lazy-import rosbags / roslibpy so import machinevisiontoolbox stops paying for them.

Please do the split after the quick wins, in a PR containing nothing else, so it is easy to review as a pure move. Other work (for example making optional data files downloadable on demand) will also edit this file's call sites, so landing the split first avoids painful rebases.

3. API unification (changes behaviour, needs design discussion first)

  • Shared loop, rgb/colororder, dtype and start/stop/step options on the base class.
  • __iter__ returns a fresh iterator each time.
  • One live-source API: close() plus context-manager support everywhere, retire grab().
  • Lock ROSTopic's latest-frame and timestamp state.

Any of these should come with deprecation warnings for the old behaviour. Please open a discussion or comment here before starting.

4. After the split

  • Annotate the split modules (the parameter annotations for Sources.py are tracked in #60; about 50 are missing today).
  • Add mocked tests for VideoCamera, WebCam and EarthView.

Notes for contributors

  • Branch from main and open a PR; titles follow Conventional Commits (fix:, refactor:, docs:).
  • Please keep each PR to one of the items above.
  • Related open work: #125 is fixed by PR #149 (EarthView key lookup), which touches this file; it should land first.
Ngôn ngữ chính
Python
Star
224
Fork
31
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
28

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của petercorke/machinevision-toolbox-python

Tất cả issue của petercorke/machinevision-toolbox-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.