fix(api): pylint crashes on redefined-builtin
See https://github.com/PyCQA/pylint/issues/8079 Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2203>
This commit is contained in:
parent
6806adb4f5
commit
6528039e95
|
@ -1,3 +0,0 @@
|
||||||
# loads what is required to generate the swagger docs
|
|
||||||
# https://matrix.to/#/!nNBDNverFlbfNpReEO:matrix.org/$16579878472182UmZUv:tchncs.de?via=tchncs.de&via=matrix.org&via=juniorjpdj.pl
|
|
||||||
import config.schema # noqa: F401
|
|
|
@ -477,14 +477,13 @@ def monkey_patch_request_build_absolute_uri():
|
||||||
def get_file_hash(file, algo=None, chunk_size=None, full_read=False):
|
def get_file_hash(file, algo=None, chunk_size=None, full_read=False):
|
||||||
algo = algo or settings.HASHING_ALGORITHM
|
algo = algo or settings.HASHING_ALGORITHM
|
||||||
chunk_size = chunk_size or settings.HASHING_CHUNK_SIZE
|
chunk_size = chunk_size or settings.HASHING_CHUNK_SIZE
|
||||||
handler = getattr(hashlib, algo)
|
hasher = hashlib.new(algo)
|
||||||
hash = handler()
|
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
if full_read:
|
if full_read:
|
||||||
for byte_block in iter(lambda: file.read(chunk_size), b""):
|
for byte_block in iter(lambda: file.read(chunk_size), b""):
|
||||||
hash.update(byte_block)
|
hasher.update(byte_block)
|
||||||
else:
|
else:
|
||||||
# sometimes, it's useful to only hash the beginning of the file, e.g
|
# sometimes, it's useful to only hash the beginning of the file, e.g
|
||||||
# to avoid a lot of I/O when crawling large libraries
|
# to avoid a lot of I/O when crawling large libraries
|
||||||
hash.update(file.read(chunk_size))
|
hasher.update(file.read(chunk_size))
|
||||||
return f"{algo}:{hash.hexdigest()}"
|
return f"{algo}:{hasher.hexdigest()}"
|
||||||
|
|
|
@ -151,8 +151,9 @@ class TrackFactory(
|
||||||
if created:
|
if created:
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
@factory.post_generation
|
# The @factory.post_generation is not used because we must
|
||||||
def license(self, created, extracted, **kwargs):
|
# not redefine the builtin `license` function.
|
||||||
|
def _license_post_generation(self, created, extracted, **kwargs):
|
||||||
if not created:
|
if not created:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -160,6 +161,8 @@ class TrackFactory(
|
||||||
self.license = LicenseFactory(code=extracted)
|
self.license = LicenseFactory(code=extracted)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
license = factory.PostGeneration(_license_post_generation)
|
||||||
|
|
||||||
|
|
||||||
@registry.register
|
@registry.register
|
||||||
class UploadFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
class UploadFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
||||||
|
|
|
@ -28,7 +28,7 @@ def load(data):
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
try:
|
try:
|
||||||
license = existing_by_code[row["code"]]
|
license_ = existing_by_code[row["code"]]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.debug("Loading new license: {}".format(row["code"]))
|
logger.debug("Loading new license: {}".format(row["code"]))
|
||||||
to_create.append(
|
to_create.append(
|
||||||
|
@ -36,15 +36,15 @@ def load(data):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.debug("Updating license: {}".format(row["code"]))
|
logger.debug("Updating license: {}".format(row["code"]))
|
||||||
stored = [getattr(license, f) for f in MODEL_FIELDS]
|
stored = [getattr(license_, f) for f in MODEL_FIELDS]
|
||||||
wanted = [row[f] for f in MODEL_FIELDS]
|
wanted = [row[f] for f in MODEL_FIELDS]
|
||||||
if wanted == stored:
|
if wanted == stored:
|
||||||
continue
|
continue
|
||||||
# the object in database needs an update
|
# the object in database needs an update
|
||||||
for f in MODEL_FIELDS:
|
for f in MODEL_FIELDS:
|
||||||
setattr(license, f, row[f])
|
setattr(license_, f, row[f])
|
||||||
|
|
||||||
license.save()
|
license_.save()
|
||||||
|
|
||||||
models.License.objects.bulk_create(to_create)
|
models.License.objects.bulk_create(to_create)
|
||||||
return sorted(models.License.objects.all(), key=lambda o: o.code)
|
return sorted(models.License.objects.all(), key=lambda o: o.code)
|
||||||
|
@ -78,12 +78,12 @@ def match(*values):
|
||||||
else:
|
else:
|
||||||
existing = load(LICENSES)
|
existing = load(LICENSES)
|
||||||
_cache = existing
|
_cache = existing
|
||||||
for license in existing:
|
for license_ in existing:
|
||||||
if license.conf is None:
|
if license_.conf is None:
|
||||||
continue
|
continue
|
||||||
for i in license.conf["identifiers"]:
|
for i in license_.conf["identifiers"]:
|
||||||
if match_urls(url, i):
|
if match_urls(url, i):
|
||||||
return license
|
return license_
|
||||||
|
|
||||||
|
|
||||||
def match_urls(*urls):
|
def match_urls(*urls):
|
||||||
|
|
Loading…
Reference in New Issue