Skip to content

Conversation

@jdelic
Copy link
Member

@jdelic jdelic commented Jul 29, 2025

The requests library has support for passing additional information, such as the intended filename on upload, the content-type and additional headers, by passing a tuple with 2, 3 or 4 elements instead of just a file object.

See "POST a Multipart-Encoded File" in the requests documentation for more details:
https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file

Extend aptly_api files API to also be able to take similar tuples when uploading files to Aptly.

One useful use case is to pass a proper package filename, in cases where packages are generated simply as .deb by upstream projects (usually via non native Debian build systems) but should more properly be stored as :.deb. Renaming files locally is a possibility, but potentially runs into permission issues. Being able to specify the filename to the API solves this in a more elegant way, without having to modify the local filesystem. The package information can be easily derived using debian.debfile.DebFile() to inspect a package file, in specific gencontrol() returns the fields of the control file which can be used to derive the expected filename.

Tested locally by uploading files to aptly using the modified API. Also added a test (even though it mostly relies on mocks.) Confirmed mypy is happy with all the type annotation.

From [#129] by @filbranden. Copied the PR here to rebase and run tests.

filbranden and others added 30 commits September 5, 2024 20:41
The requests library has support for passing additional information,
such as the intended filename on upload, the content-type and additional
headers, by passing a tuple with 2, 3 or 4 elements instead of just a
file object.

See "POST a Multipart-Encoded File" in requests documentation for details:
https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file

Extend aptly_api files API to also be able to take similar tuples when
uploading files to Aptly.

One useful use case is to pass a proper package filename, in cases where
packages are generated simply as <name>.deb by upstream projects
(usually via non native Debian build systems) but should more properly
be stored as <name>_<epoch>:<version>_<arch>.deb. Renaming files locally
is a possibility, but potentially runs into permission issues. Being
able to specify the filename to the API solves this in a more elegant
way, without having to modify the local filesystem. The package
information can be easily derived using debian.debfile.DebFile() to
inspect a package file, in specific gencontrol() returns the fields of
the control file which can be used to derive the expected filename.

Tested locally by uploading files to aptly using the modified API. Also
added a test (even though it mostly relies on mocks.) Confirmed mypy is
happy with all the type annotation.
* ensure that there are no lines longer than 120 characters
* fix imported but not used Union
* fix imported but not used AptlyAPIException
* fix imported but not used Mirror
* removed trailing whitespaces
* removed black lines at the end of files
* Incompatible type assignments
* Incompatible types for arguments
* Incompatible return values
Fixed code style1
I understand that my formatting lacks rhyme or reason, but now this
is consistent with the rest of the files.
* Fixed Mirror.Create. It didn't make use of filter_with_deps argument.
* Organized Mirror.create statements to make them easier to follow.
* Created unit tests for Mirror.Create to make sure post request is
  created correctly.
* Renamed misleading test named test_create to test_mirror_from_response
  and cleaned up the function.

(cherry picked from commit 71e19b4)
* Fixed Snapshot.create_from_mirror. Description argument was not being
  set in the post.
* Fixed test_create_from_mirror to check the post request fields to make
  sure they match expected values.

(cherry picked from commit 292be7d)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.3.2 to 8.3.3.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@8.3.2...8.3.3)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [doc8](https://github.com/pycqa/doc8) from 1.1.1 to 1.1.2.
- [Release notes](https://github.com/pycqa/doc8/releases)
- [Commits](PyCQA/doc8@v1.1.1...v1.1.2)

---
updated-dependencies:
- dependency-name: doc8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.11.1 to 1.11.2.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.11.1...v1.11.2)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.11.2 to 1.12.0.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.11.2...v1.12.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [coverage](https://github.com/nedbat/coveragepy) from 7.6.1 to 7.6.3.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](coveragepy/coveragepy@7.6.1...7.6.3)

---
updated-dependencies:
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [coverage](https://github.com/nedbat/coveragepy) from 7.6.3 to 7.6.7.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](coveragepy/coveragepy@7.6.3...7.6.7)

---
updated-dependencies:
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 5.0.0 to 6.0.0.
- [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst)
- [Commits](pytest-dev/pytest-cov@v5.0.0...v6.0.0)

---
updated-dependencies:
- dependency-name: pytest-cov
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.12.0 to 1.13.0.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.12.0...v1.13.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [flake8](https://github.com/pycqa/flake8) from 7.1.1 to 7.1.2.
- [Commits](PyCQA/flake8@7.1.1...7.1.2)

---
updated-dependencies:
- dependency-name: flake8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [coverage](https://github.com/nedbat/coveragepy) from 7.6.7 to 7.6.12.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](coveragepy/coveragepy@7.6.7...7.6.12)

---
updated-dependencies:
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.13.0 to 1.15.0.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.13.0...v1.15.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pygments](https://github.com/pygments/pygments) from 2.18.0 to 2.19.1.
- [Release notes](https://github.com/pygments/pygments/releases)
- [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES)
- [Commits](pygments/pygments@2.18.0...2.19.1)

---
updated-dependencies:
- dependency-name: pygments
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.3.3 to 8.3.4.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@8.3.3...8.3.4)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
jdelic and others added 7 commits July 29, 2025 12:39
Bumps [flake8](https://github.com/pycqa/flake8) from 7.1.2 to 7.3.0.
- [Commits](PyCQA/flake8@7.1.2...7.3.0)

---
updated-dependencies:
- dependency-name: flake8
  dependency-version: 7.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [coverage](https://github.com/nedbat/coveragepy) from 7.6.12 to 7.10.1.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](coveragepy/coveragepy@7.6.12...7.10.1)

---
updated-dependencies:
- dependency-name: coverage
  dependency-version: 7.10.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 6.0.0 to 6.2.1.
- [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst)
- [Commits](pytest-dev/pytest-cov@v6.0.0...v6.2.1)

---
updated-dependencies:
- dependency-name: pytest-cov
  dependency-version: 6.2.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [mypy](https://github.com/python/mypy) from 1.15.0 to 1.17.0.
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.15.0...v1.17.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-version: 1.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
The requests library has support for passing additional information,
such as the intended filename on upload, the content-type and additional
headers, by passing a tuple with 2, 3 or 4 elements instead of just a
file object.

See "POST a Multipart-Encoded File" in requests documentation for details:
https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file

Extend aptly_api files API to also be able to take similar tuples when
uploading files to Aptly.

One useful use case is to pass a proper package filename, in cases where
packages are generated simply as <name>.deb by upstream projects
(usually via non native Debian build systems) but should more properly
be stored as <name>_<epoch>:<version>_<arch>.deb. Renaming files locally
is a possibility, but potentially runs into permission issues. Being
able to specify the filename to the API solves this in a more elegant
way, without having to modify the local filesystem. The package
information can be easily derived using debian.debfile.DebFile() to
inspect a package file, in specific gencontrol() returns the fields of
the control file which can be used to derive the expected filename.

Tested locally by uploading files to aptly using the modified API. Also
added a test (even though it mostly relies on mocks.) Confirmed mypy is
happy with all the type annotation.
@coveralls
Copy link

coveralls commented Jul 29, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling b5256b5 on feature/pr129
into 9bbb5b2 on master.

@jdelic jdelic closed this Jul 29, 2025
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.

5 participants