Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1369)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 24.4.0 → 24.4.2](psf/black@24.4.0...24.4.2)
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)
- [github.com/pre-commit/mirrors-mypy: v1.9.0 → v1.10.0](pre-commit/mirrors-mypy@v1.9.0...v1.10.0)

* pre-commit: fixed warnings, updated CHANGELOG.md, AUTHORS.md, version

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>

---------

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexander Piskun <13381981+bigcat88@users.noreply.github.com>
Co-authored-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
3 people committed May 1, 2024
1 parent 56866eb commit cce6ce5
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 73 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
exclude: nextcloudappstore/core/migrations
Expand All @@ -56,12 +56,12 @@ repos:
- id: pyproject-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.2
hooks:
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
files: nextcloudappstore/(api/v1/release|certificate)/
Expand Down
15 changes: 10 additions & 5 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2# Authors
# Authors

* [Bernhard Posselt](mailto:dev@bernhard-posselt.com)
* [Alexander Piskun](mailto:13381981+bigcat88@users.noreply.github.com)
Expand All @@ -12,24 +12,29 @@
* [Julius Härtl](mailto:jus@bitgrid.net)
* [Mario Danic](mailto:mario@lovelyhq.com)
* [Arthur Schiwon](mailto:blizzz@arthur-schiwon.de)
* [Matthieu Gallien](mailto:matthieu.gallien@nextcloud.com)
* [Vitor Mattos](mailto:vitor@php.rio)
* [Joas Schilling](mailto:213943+nickvergessen@users.noreply.github.com)
* [Andrey Borysenko](mailto:andrey18106x@gmail.com)
* [Mario Đanić](mailto:mario@lovelyhq.com)
* [Ferdinand Thiessen](mailto:opensource@fthiessen.de)
* [Christoph Wurst](mailto:ChristophWurst@users.noreply.github.com)
* [Matthieu Gallien](mailto:matthieu.gallien@nextcloud.com)
* [Daniel Kesselberg](mailto:mail@danielkesselberg.de)
* [Roeland Jago Douma](mailto:rullzer@users.noreply.github.com)
* [Andrey Borysenko](mailto:andrey18106x@gmail.com)
* [Allan Nordhøy](mailto:epost@anotheragency.no)
* [Daphne Muller](mailto:86835268+DaphneMuller@users.noreply.github.com)
* [John Molakvoæ](mailto:skjnldsv@protonmail.com)
* [Kate](mailto:26026535+provokateurin@users.noreply.github.com)
* [Patrizio Bekerle](mailto:patrizio@bekerle.com)
* [rakekniven](mailto:mark.ziegler@rakekniven.de)
* [rakekniven](mailto:2069590+rakekniven@users.noreply.github.com)
* [Jannick Hemelhof](mailto:clone1612@me.com)
* [Marius Blüm](mailto:marius@lineone.io)
* [Olivier Paroz](mailto:oparoz@users.noreply.github.com)
* [provokateurin](mailto:kate@provokateurin.de)
* [Christian Wolf](mailto:github@christianwolf.email)
* [Côme Chilliet](mailto:come.chilliet@nextcloud.com)
* [Daniel](mailto:mail@danielkesselberg.de)
* [Gary Kim](mailto:gary@garykim.dev)
* [John Molakvoæ](mailto:skjnldsv@protonmail.com)
* [Jos Poortvliet](mailto:jos@opensuse.org)
* [Maxence Lange](mailto:maxence@artificial-owl.com)
* [Simon L](mailto:szaimen@e.mail.de)
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## [Unreleased]

## [4.8.1] - 2024-05-10

### Changed

- `App templates` now generated from GitHub repo template. #1368 by @provokateurin
- redis dependency updated from `5.0.3` to `5.0.4` #1363
- sqlparse dependency updated from `0.4.4` to `0.5.0` #1353
- dnspython dependency updated from `2.5.0` to `2.6.1` #1351
- pillow dependency updated from `10.2.0` to `10.3.0` #1346

## [4.8.0] - 2024-03-17

### Added
Expand Down
3 changes: 1 addition & 2 deletions nextcloudappstore/api/v1/release/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def get_archive(
it's definitely the best we can do now given security circumstances
"""
filename = url[url.rfind("/") + 1 :]
msg = "%s is not a valid tar.gz archive " % filename
raise UnsupportedAppArchiveException(msg)
raise UnsupportedAppArchiveException(f"{filename} is not a valid tar.gz archive ")
return ReleaseDownload(file.name)

def _stream_to_file(self, file: Any, max_size: int, req: requests.Response) -> None:
Expand Down
34 changes: 13 additions & 21 deletions nextcloudappstore/api/v1/release/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def extract_app_metadata(self, archive_path: str) -> AppMetaData:
unwanted. To mitigate the issue we now get only the filename
and include that in the error message
"""
msg = "%s is not a valid tar.gz archive " % Path(archive_path).name
raise UnsupportedAppArchiveException(msg)
raise UnsupportedAppArchiveException(f"{Path(archive_path).name} is not a valid tar.gz archive ")

try:
with tarfile.open(archive_path, "r:gz") as tar: # type: ignore
Expand All @@ -92,10 +91,10 @@ def extract_app_metadata(self, archive_path: str) -> AppMetaData:

def _parse_archive(self, tar: Any) -> AppMetaData:
app_id = find_app_id(tar, self.app_folder_regex)
info = get_contents("%s/appinfo/info.xml" % app_id, tar, self.config.max_file_size)
database = get_contents("%s/appinfo/database.xml" % app_id, tar, self.config.max_file_size, "")
info = get_contents(f"{app_id}/appinfo/info.xml", tar, self.config.max_file_size)
database = get_contents(f"{app_id}/appinfo/database.xml", tar, self.config.max_file_size, "")
changelog = {
"en": get_contents("%s/CHANGELOG.md" % app_id, tar, self.config.max_file_size, "")
"en": get_contents(f"{app_id}/CHANGELOG.md", tar, self.config.max_file_size, "")
} # type: dict[str, str]

for code, _ in self.config.languages:
Expand Down Expand Up @@ -125,8 +124,7 @@ def get_contents(path: str, tar: Any, max_file_size: int, default: Any = None) -
if member is None:
if default is not None:
return default
msg = "Path %s does not exist in package" % path
raise InvalidAppPackageStructureException(msg)
raise InvalidAppPackageStructureException(f"Path {path} does not exist in package")
return stream_read_utf8(tar, member, max_file_size)


Expand Down Expand Up @@ -182,9 +180,9 @@ def element_to_dict(element: Any) -> dict:
elif type == "list":
return {key: list(map(element_to_dict, element.iterchildren()))}
elif type == "min-version":
return {key: pad_min_version(element.text), "raw_%s" % key: raw_version(element.text)}
return {key: pad_min_version(element.text), f"raw_{key}": raw_version(element.text)}
elif type == "max-version":
return {key: pad_max_version(element.text), "raw_%s" % key: raw_version(element.text)}
return {key: pad_max_version(element.text), f"raw_{key}": raw_version(element.text)}
elif len(list(element)) > 0:
contents = {}
for child in element.iterchildren():
Expand Down Expand Up @@ -220,8 +218,7 @@ def parse_app_metadata(xml: str, schema: str, pre_xslt: str, xslt: str) -> dict:
try:
doc = lxml.etree.fromstring(bytes(xml, encoding="utf-8"), parser)
except lxml.etree.XMLSyntaxError as e:
msg = "info.xml contains malformed xml: %s" % e
raise XMLSyntaxError(msg)
raise XMLSyntaxError(f"info.xml contains malformed xml: {e}")
for _ in doc.iter(lxml.etree.Entity): # type: ignore
raise InvalidAppMetadataXmlException("Must not contain entities")
pre_transform = lxml.etree.XSLT(lxml.etree.XML(pre_xslt)) # type: ignore
Expand All @@ -231,8 +228,7 @@ def parse_app_metadata(xml: str, schema: str, pre_xslt: str, xslt: str) -> dict:
try:
schema.assertValid(pre_transformed_doc) # type: ignore
except lxml.etree.DocumentInvalid as e:
msg = "info.xml did not validate: %s" % e
raise InvalidAppMetadataXmlException(msg)
raise InvalidAppMetadataXmlException(f"info.xml did not validate: {e}")
transform = lxml.etree.XSLT(lxml.etree.XML(xslt)) # type: ignore
transformed_doc = transform(pre_transformed_doc) # type: ignore
mapped = element_to_dict(transformed_doc.getroot()) # type: ignore
Expand All @@ -254,8 +250,7 @@ def validate_database(xml: str, schema: str, pre_xslt: str) -> None:
try:
doc = lxml.etree.fromstring(bytes(xml, encoding="utf-8"), parser)
except lxml.etree.XMLSyntaxError as e:
msg = "database.xml contains malformed xml: %s" % e
raise XMLSyntaxError(msg)
raise XMLSyntaxError(f"database.xml contains malformed xml: {e}")
for _ in doc.iter(lxml.etree.Entity): # type: ignore
raise InvalidAppMetadataXmlException("Must not contain entities")
pre_transform = lxml.etree.XSLT(lxml.etree.XML(pre_xslt)) # type: ignore
Expand All @@ -265,8 +260,7 @@ def validate_database(xml: str, schema: str, pre_xslt: str) -> None:
try:
schema.assertValid(pre_transformed_doc) # type: ignore
except lxml.etree.DocumentInvalid as e:
msg = "database.xml did not validate: %s" % e
raise InvalidAppMetadataXmlException(msg)
raise InvalidAppMetadataXmlException(f"database.xml did not validate: {e}")


def validate_english_present(info: dict) -> None:
Expand All @@ -280,8 +274,7 @@ def validate_english_present(info: dict) -> None:
translated_fields = ["name", "summary", "description"]
for field in translated_fields:
if "en" not in app[field]:
msg = 'At least one element "%s" with lang "en" required' % field
raise InvalidAppMetadataXmlException(msg)
raise InvalidAppMetadataXmlException(f'At least one element "{field}" with lang "en" required')


def fix_partial_translations(info: dict) -> None:
Expand Down Expand Up @@ -407,6 +400,5 @@ def check_member(path: str) -> Any:

for member in filter(lambda m: m is not None, checked_members):
if member.issym() or member.islnk():
msg = "Symlinks and hard links can not be used for %s" % member
raise ForbiddenLinkException(msg)
raise ForbiddenLinkException(f"Symlinks and hard links can not be used for {member}")
return check_member(path)
3 changes: 1 addition & 2 deletions nextcloudappstore/api/v1/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def setUp(self):
def _login(self, user="test", password="test"):
credentials = f"{user}:{password}"
base64_credentials = base64.b64encode(credentials.encode(HTTP_HEADER_ENCODING)).decode(HTTP_HEADER_ENCODING)
auth = "Basic %s" % base64_credentials
self.api_client.credentials(HTTP_AUTHORIZATION=auth)
self.api_client.credentials(HTTP_AUTHORIZATION=f"Basic {base64_credentials}")

def _login_token(self, user="test"):
token = "Token " + Token.objects.get(user__username=user).key
Expand Down
2 changes: 1 addition & 1 deletion nextcloudappstore/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _check_permission(self, request, app_id, version, is_nightly):
try:
app = App.objects.get(pk=app_id)
except App.DoesNotExist:
raise ValidationError("App %s does not exist, you need to registerit first" % app_id)
raise ValidationError(f"App {app_id} does not exist, you need to registerit first")

# if an app release does not exist, it must be checked if the
# user is allowed to create it first
Expand Down
2 changes: 1 addition & 1 deletion nextcloudappstore/certificate/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_validate_crl_revoked2(self) -> None:
self.validator.validate_certificate(cert, chain, crl)

def _read_cert(self, file: str) -> str:
return read_relative_file(__file__, "data/certificates/%s" % file)
return read_relative_file(__file__, f"data/certificates/{file}")

def _read_bin_file(self, rel_path: str) -> bytes:
target_path = resolve_file_relative_path(__file__, rel_path)
Expand Down
11 changes: 3 additions & 8 deletions nextcloudappstore/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@

RATING_CHOICES = ((0.0, _("Bad")), (0.5, _("OK")), (1.0, _("Good")))

REGISTER_SIGN_CMD = (
' echo -n "APP_ID" | openssl dgst -%s -sign ~/.nextcloud/certificates/APP_ID.key | openssl base64'
% settings.CERTIFICATE_DIGEST
)
RELEASE_SIGN_CMD = (
" openssl dgst -%s -sign ~/.nextcloud/certificates/APP_ID.key /path/to/app.tar.gz | openssl base64"
% settings.CERTIFICATE_DIGEST
)
S_APP_ID_KEY = "-sign ~/.nextcloud/certificates/APP_ID.key"
REGISTER_SIGN_CMD = f' echo -n "APP_ID" | openssl dgst -{settings.CERTIFICATE_DIGEST} {S_APP_ID_KEY} | openssl base64'
RELEASE_SIGN_CMD = f" openssl dgst -{settings.CERTIFICATE_DIGEST} {S_APP_ID_KEY} /path/to/app.tar.gz | openssl base64"
CREATE_CERT_CMD = ' openssl req -nodes -newkey rsa:4096 -keyout APP_ID.key -out APP_ID.csr -subj "/CN=APP_ID"'


Expand Down
4 changes: 2 additions & 2 deletions nextcloudappstore/core/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class GitHubClient:
def __init__(self, base_url: str, api_token: str = None) -> None:
self.base_url = base_url.rstrip("/")
self.api_token = api_token
self.headers = None if self.api_token else {"Authorization": "token %s" % self.api_token}
self.headers = None if self.api_token else {"Authorization": f"token {self.api_token}"}

def get_tags(self, page: int, size: int = 100):
url = "%s/repos/nextcloud/server/tags" % self.base_url
url = f"{self.base_url}/repos/nextcloud/server/tags"
params = (("per_page", size), ("page", page))
response = requests.get(url, params=params, headers=self.headers, timeout=21)
response.raise_for_status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def escape_tpl_string(string):

class Command(BaseCommand):
translation_file = "core/templates/translation/db_translations.txt"
help = "Goes through all translated database models (hardcoded) and creates translations in %s" % translation_file
help = f"Goes through all translated database models (hardcoded) and creates translations in {translation_file}"
translated_fields = ((Category, ("name", "description")),)
source_lang = "en"

Expand All @@ -24,11 +24,10 @@ def handle(self, *args, **options):
with open(target_file, "w") as f:
f.write(content)

msg = "Exported translations to %s" % target_file
self.stdout.write(self.style.SUCCESS(msg))
self.stdout.write(self.style.SUCCESS(f"Exported translations to {target_file}"))

def _create_translations(self, model, fields):
objs = model.objects.language(self.source_lang).all()
strings = flatmap(lambda o: [getattr(o, f) for f in fields], objs)
strings = map(escape_tpl_string, strings)
return list(map(lambda s: '{%% trans "%s" %%}' % s, strings))
return list(map(lambda s: f'{{%% trans "{s}" %%}}', strings))
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def handle(self, *args, **options):
if issubclass(model, TranslatableModel):
self._import_translations(model, fields, language_code)
else:
raise CommandError('Model "%s" is not translatable' % model.__name__)
raise CommandError(f'Model "{model.__name__}" is not translatable')
self.stdout.write(self.style.SUCCESS("Imported db translations"))

def _import_translations(self, model, fields, language_code):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def _get_tags(self, page: int, size: int = 100) -> dict[Any, Any]:
return json.loads(self._read("tags_page_%d.json" % page))

def _read(self, path: str) -> str:
return read_relative_file(__file__, "../../../tests/data/%s" % path)
return read_relative_file(__file__, f"../../../tests/data/{path}")
2 changes: 1 addition & 1 deletion nextcloudappstore/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class AppAuthor(Model):

def __str__(self) -> str:
if self.mail:
mail = "<%s>" % self.mail
mail = f"<{self.mail}>"
else:
mail = ""
return f"{self.name} {mail}"
Expand Down
2 changes: 1 addition & 1 deletion nextcloudappstore/core/tests/e2e/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def assertOnPage(self, url_name: str, kwargs: dict[str, str] = None) -> None:

def findNavigationLink(self, url_name: str, kwargs: dict[str, str] = None):
route = reverse(url_name, kwargs=kwargs)
return self.by_css('#navbar-wrapper a[href="%s"]' % route)
return self.by_css(f'#navbar-wrapper a[href="{route}"]')

@staticmethod
def _url_to_be(url: str) -> Callable[[Any], bool]:
Expand Down
6 changes: 2 additions & 4 deletions nextcloudappstore/core/tests/e2e/test_app_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def validate_success_msg(el):
self.wait_for(".global-success-msg", validate_success_msg)

def read_cert(self, name: str) -> str:
path = "data/%s" % name
return read_relative_file(__file__, path)
return read_relative_file(__file__, f"data/{name}")

def cert_path(self, name: str) -> str:
path = "data/%s" % name
return resolve_file_relative_path(__file__, path)
return resolve_file_relative_path(__file__, f"data/{name}")
4 changes: 2 additions & 2 deletions nextcloudappstore/core/tests/e2e/test_owner_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_transfer(self):
self.login("admin", "admin")
self.go_to("user:account-transfer-apps")
news_transfer_url = reverse("user:account-transfer-app", kwargs={"pk": "news"})
self.by_css('form[action="%s"] button' % news_transfer_url).click()
self.by_css(f'form[action="{news_transfer_url}"] button').click()
self.logout()

# try to register unlocked app
Expand All @@ -43,5 +43,5 @@ def test_transfer(self):
self.wait_for(".global-success-msg", lambda el: self.assertTrue(el.is_displayed()))

self.go_to("user:account-transfer-apps")
el = self.by_css('form[action="%s"] button' % news_transfer_url)
el = self.by_css(f'form[action="{news_transfer_url}"] button')
self.assertTrue(el.is_displayed())
2 changes: 1 addition & 1 deletion nextcloudappstore/core/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def _get_tags(self, page: int, size: int = 100) -> dict[Any, Any]:
return json.loads(self._read("tags_page_%d.json" % page))

def _read(self, path: str) -> str:
return read_relative_file(__file__, "data/%s" % path)
return read_relative_file(__file__, f"data/{path}")
2 changes: 1 addition & 1 deletion nextcloudappstore/core/tests/test_rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def test_app_rating_save(self):

def create_user(self, id):
user_id = "test%i" % id
return get_user_model().objects.create_user(username=user_id, password=user_id, email="%s@test.com" % user_id)
return get_user_model().objects.create_user(username=user_id, password=user_id, email=f"{user_id}@test.com")
10 changes: 5 additions & 5 deletions nextcloudappstore/core/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pad_max_version(version: str) -> str:
elif len(parts) == 3:
parts[2] += 1
else:
raise ValueError("Could not parse version %s" % version)
raise ValueError(f"Could not parse version {version}")
return ".".join([str(part) for part in parts])


Expand Down Expand Up @@ -103,9 +103,9 @@ def to_raw_spec(min_version: str, max_version: str) -> str:
if max_version == "*" and min_version == "*":
return "*"
elif max_version == "*":
return ">=%s" % min_version
return f">={min_version}"
elif min_version == "*":
return "<=%s" % max_version
return f"<={max_version}"
else:
return f">={min_version},<={max_version}"

Expand All @@ -121,9 +121,9 @@ def to_spec(min_version: str, max_version: str) -> str:
if max_version == "*" and min_version == "*":
return "*"
elif max_version == "*":
return ">=%s" % min_version
return f">={min_version}"
elif min_version == "*":
return "<%s" % max_version
return f"<{max_version}"
else:
return f">={min_version},<{max_version}"

Expand Down

0 comments on commit cce6ce5

Please sign in to comment.