Skip to content

Conversation

@DEVANSH-GAJJAR
Copy link

@DEVANSH-GAJJAR DEVANSH-GAJJAR commented Jan 6, 2026

Description

This PR implements the list_folders_v2 method in fossology/folders.py to extend support for the Fossology API v2.

Currently, the wrapper defaults to v1 endpoints. This implementation allows users to fetch folder lists using the new v2 structure by dynamically adjusting the API base URL.

Changes

  • Added list_folders_v2 method to the Folders class.
  • Implemented URL logic to switch from .../api/v1 to .../api/v2 dynamically.
  • Added response parsing to handle the V2 JSON list format and return Folder objects.

Related Issue

Relates to #140

Testing & Verification

  • Static Analysis: Verified syntax validity (py_compile) and successful import (from fossology.folders import Folders).
  • Unit Tests: I encountered some local environment issues setting up the pytest mock server infrastructure.
    • Note to Reviewers: I have opened this PR to get feedback on the implementation logic first. I am happy to add the responses mock test once I resolve the local setup or with guidance on the preferred testing pattern for v2.

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation (docstrings) accordingly.
  • I have read the CONTRIBUTING document.

@deveaud-m
Copy link
Collaborator

@DEVANSH-GAJJAR welcome to Fossology Python and thanks for starting this PR.

I would like to avoid duplicating all the methods just to support v2 because I think most of the content will be similar, only some endpoints will only be available for one version or the other.

I started doing a little bit of refactoring in preparation to supporting v2 in this PR: https://github.com/fossology/fossology-python/pull/162/files#diff-df2ec7af328aecf9da4e6ef7c9d4a7515e50c73a692d5857c8fc20f970bd3068R133.

The targeted version shall be given during instanciation of the Fossology class using the version parameter.

If the response diverge between v1 and v2, we should use a slightly adapted object factory, e.g.:

# fossology/obj.py
class FolderFactory:
    @staticmethod
    def from_json(version, data):
        if version == "v2":
            return Folder.from_json_v2(data)
        return Folder.from_json(data)
...
class Folders:
    """Class dedicated to all "folders" related endpoints"""

    def list_folders(self):
        response = self.session.get(f"{self.api}/folders")
        if response.status_code == 200:
            folders_list = list()
            response_list = response.json()
            for folder in response_list:
				if self.version == "v2":
                	sub_folder = FolderFactory.from_json_v2(self.version, folder)
				else:
					sub_folder = FolderFactory.from_json(self.version, folder)
                folders_list.append(sub_folder)
            return folders_list
        else:
            description = f"Unable to get a list of folders for {self.user.name}"
            raise FossologyApiError(description, response)

Could you give it a shot once you rebased on top of #162?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants