Skip to content

Allow upload generic package from bytes #1815

Closed
@dAnjou

Description

@dAnjou

Hi,

gl = Gitlab()
project = gl.projects.get(project_id)

Project file upload allows both, path or bytes:

file = project.upload(
    filename="my_file.txt",
    filepath="/path/to/my_file.txt",
    # or
    filedata=b"content",
)

But project generic package upload only allows path:

package = project.generic_packages.upload(
    package_name="my_package",
    package_version="0.1",
    file_name="my_file.txt",
    path="/path/to/my_file.txt",
    # no bytes allowed :(
)

I'm happy to work on this, but I'd like to discuss with you first.

I might be too pedantic here but I like consistent argument naming. Both methods already have inconsistent argument names, filename and file_name, but I guess there's not too much you can do about it without a breaking change, unless you'd be okay with having a weird function signature that allows both for some time while deprecating the old names.

Then there are filepath and path, so considering there is filedata in project file upload, maybe data could be used in project generic package upload?

Ideally though, a much cleaner approach would be to accept a file-like object exclusively, considering how easy it is to create one: pathlib.Path("my_file.txt").open("rb") or io.BytesIO(b"content"). This would result in simpler code, less stuff to test and maintain, and arguably more flexibility for users.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions