Skip to content

Commit

Permalink
run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gurneyalex committed Jun 24, 2024
1 parent 451facf commit 61d30ef
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 54 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,3 @@ jobs:
run: oca_init_test_database
- name: Run tests
run: oca_run_tests
- name: Update .pot files
run: oca_export_and_push_pot https://x-access-token:${{ secrets.GIT_PUSH_TOKEN }}@github.com/${{ github.repository }}
if: ${{ matrix.makepot == 'true' && github.event_name == 'push' && github.repository_owner == 'camptocamp' }}
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^attachment_s3/|
^attachment_swift/|
^base_fileurl_field/|
^cloud_platform_exoscale/|
^cloud_platform_ovh/|
^monitoring_log_requests/|
^monitoring_statsd/|
^test_base_fileurl_field/|
Expand Down
12 changes: 6 additions & 6 deletions attachment_azure/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IrAttachment(models.Model):
_inherit = "ir.attachment"

def _get_stores(self):
return ["azure"] + super(IrAttachment, self)._get_stores()
return ["azure"] + super()._get_stores()

@api.model
def _get_blob_service_client(self):
Expand Down Expand Up @@ -111,7 +111,7 @@ def _get_blob_service_client(self):
@api.model
def _get_container_name(self):
# Container naming rules:
# https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names # noqa: B950
# https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names # noqa: E501
running_env = os.environ.get("RUNNING_ENV", "dev")
storage_name = os.environ.get("AZURE_STORAGE_NAME", r"{env}-{db}")
storage_name = storage_name.format(env=running_env, db=self.env.cr.dbname)
Expand Down Expand Up @@ -162,14 +162,14 @@ def _store_file_read(self, fname, bin_size=False):
_logger.info("Attachment '%s' missing on object storage", fname)
return read
else:
return super(IrAttachment, self)._store_file_read(fname, bin_size)
return super()._store_file_read(fname, bin_size)

@api.model
def _store_file_write(self, key, bin_data):
location = self.env.context.get("storage_location") or self._storage()
if location == "azure":
container_client = self._get_azure_container()
filename = "azure://%s/%s" % (container_client.container_name, key)
filename = f"azure://{container_client.container_name}/{key}"
with io.BytesIO() as file:
blob_client = container_client.get_blob_client(key.lower())
file.write(bin_data)
Expand All @@ -189,7 +189,7 @@ def _store_file_write(self, key, bin_data):
_("The file could not be stored: %s") % str(error)
) from None
else:
_super = super(IrAttachment, self)
_super = super()
filename = _super._store_file_write(key, bin_data)
return filename

Expand All @@ -215,4 +215,4 @@ def _store_file_delete(self, fname):
# user
_logger.exception("Error during deletion of the file %s" % fname)
else:
super(IrAttachment, self)._store_file_delete(fname)
super()._store_file_delete(fname)
3 changes: 3 additions & 0 deletions attachment_azure/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
20 changes: 8 additions & 12 deletions base_attachment_object_storage/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def clean_fs(files):
try:
os.unlink(full_path)
except OSError:
_logger.info(
"_file_delete could not unlink %s", full_path, exc_info=True
)
except IOError:
# Harmless and needed for race conditions
_logger.info(
"_file_delete could not unlink %s", full_path, exc_info=True
Expand Down Expand Up @@ -124,7 +120,7 @@ def _store_in_db_instead_of_object_storage_domain(self):
domain = []
storage_config = self._get_storage_force_db_config()
for mimetype_key, limit in storage_config.items():
part = [("mimetype", "=like", "{}%".format(mimetype_key))]
part = [("mimetype", "=like", f"{mimetype_key}%")]
if limit:
part = AND([part, [("file_size", "<=", limit)]])
domain = OR([domain, part])
Expand Down Expand Up @@ -207,15 +203,15 @@ def _file_read(self, fname):

def _store_file_read(self, fname):
storage = fname.partition("://")[0]
raise NotImplementedError("No implementation for %s" % (storage,))
raise NotImplementedError(f"No implementation for {storage}")

def _store_file_write(self, key, bin_data):
storage = self.storage()
raise NotImplementedError("No implementation for %s" % (storage,))
raise NotImplementedError(f"No implementation for {storage}")

def _store_file_delete(self, fname):
storage = fname.partition("://")[0]
raise NotImplementedError("No implementation for %s" % (storage,))
raise NotImplementedError(f"No implementation for {storage}")

@api.model
def _file_write(self, bin_data, checksum):
Expand Down Expand Up @@ -249,7 +245,7 @@ def _is_file_from_a_store(self, fname):
for store_name in self._get_stores():
if self.is_storage_disabled(store_name):
continue
uri = "{}://".format(store_name)
uri = f"{store_name}://"
if fname.startswith(uri):
return True
return False
Expand Down Expand Up @@ -339,7 +335,7 @@ def force_storage_to_db_for_special_fields(self, new_cr=False):
(
normalize_domain(
[
("store_fname", "=like", "{}://%".format(storage)),
("store_fname", "=like", f"{storage}://%"),
# for res_field, see comment in
# _force_storage_to_object_storage
"|",
Expand Down Expand Up @@ -394,11 +390,11 @@ def _force_storage_to_object_storage(self, new_cr=False):
# is required! It's because of an override of _search in ir.attachment
# which adds ('res_field', '=', False) when the domain does not
# contain 'res_field'.
# https://github.com/odoo/odoo/blob/9032617120138848c63b3cfa5d1913c5e5ad76db/odoo/addons/base/ir/ir_attachment.py#L344-L347 # noqa: B950
# https://github.com/odoo/odoo/blob/17.0/odoo/addons/base/models/ir_attachment.py#L523

domain = [
"!",
("store_fname", "=like", "{}://%".format(storage)),
("store_fname", "=like", f"{storage}://%"),
"|",
("res_field", "=", False),
("res_field", "!=", False),
Expand Down
2 changes: 1 addition & 1 deletion base_attachment_object_storage/models/strtobool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError as error:
raise ValueError('"{}" is not a valid bool value'.format(value)) from error
raise ValueError(f'"{value}" is not a valid bool value') from error
3 changes: 3 additions & 0 deletions base_attachment_object_storage/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
6 changes: 3 additions & 3 deletions cloud_platform/models/cloud_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _install(self, platform_kind):
self.check()
if configs.filestore.location == "remote":
self.env["ir.attachment"].sudo().force_storage()
_logger.info("cloud platform configured for {}".format(platform_kind))
_logger.info(f"cloud platform configured for {platform_kind}")

@api.model
def install(self):
Expand Down Expand Up @@ -105,7 +105,7 @@ def _check_redis(self, environment_name):
prefix = os.environ["ODOO_SESSION_REDIS_PREFIX"]
assert re.match(r"^[a-z-0-9]+-odoo-[a-z-0-9]+$", prefix), (
"ODOO_SESSION_REDIS_PREFIX must match '<client>-odoo-<env>'"
", we got: '%s'" % (prefix,)
f", we got: '{prefix}'"
)

@api.model
Expand All @@ -126,5 +126,5 @@ def check(self):
self._check_redis(environment_name)

def _register_hook(self):
super(CloudPlatform, self)._register_hook()
super()._register_hook()
self.sudo().check()
2 changes: 1 addition & 1 deletion cloud_platform/models/strtobool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError as error:
raise ValueError('"{}" is not a valid bool value'.format(value)) from error
raise ValueError(f'"{value}" is not a valid bool value') from error
3 changes: 3 additions & 0 deletions cloud_platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
8 changes: 4 additions & 4 deletions cloud_platform_azure/models/cloud_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class CloudPlatform(models.AbstractModel):

@api.model
def _filestore_kinds(self):
kinds = super(CloudPlatform, self)._filestore_kinds()
kinds = super()._filestore_kinds()
kinds["azure"] = AZURE_STORE_KIND
return kinds

@api.model
def _platform_kinds(self):
kinds = super(CloudPlatform, self)._platform_kinds()
kinds = super()._platform_kinds()
kinds.append("azure")
return kinds

Expand Down Expand Up @@ -103,14 +103,14 @@ def _check_filestore(self, environment_name):
if environment_name == "prod":
assert prod_bucket, (
"AZURE_STORAGE_NAME should match '^[a-z]+\\-[a-z]+\\-\\d+$', "
"we got: '%s'" % (storage_name,)
f"we got: '{storage_name}'"
)
else:
# if we are using the prod bucket on another instance
# such as an integration, we must be sure to be in read only!
assert not prod_bucket, (
"AZURE_STORAGE_NAME should not match '^[a-z]+\\-[a-z]+\\-\\d+$', "
"we got: '%s'" % (storage_name,)
f"we got: '{storage_name}'"
)

elif environment_name == "test":
Expand Down
3 changes: 3 additions & 0 deletions cloud_platform_azure/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 1 addition & 1 deletion logging_json/json_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_fields(self, log_record, record, message_dict):
record.dbname = getattr(threading.currentThread(), "dbname", "?")
record.request_id = getattr(threading.current_thread(), "request_uuid", None)
record.uid = getattr(threading.current_thread(), "uid", None)
_super = super(OdooJsonFormatter, self)
_super = super()
return _super.add_fields(log_record, record, message_dict)


Expand Down
3 changes: 3 additions & 0 deletions logging_json/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 1 addition & 1 deletion logging_json/strtobool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError as error:
raise ValueError('"{}" is not a valid bool value'.format(value)) from error
raise ValueError(f'"{value}" is not a valid bool value') from error
3 changes: 3 additions & 0 deletions monitoring_prometheus/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions monitoring_status/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
19 changes: 6 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
azure-storage-blob==12.17.0
azure-identity==1.13.0
boto3==1.26.7
redis==4.3.4
python-json-logger==2.0.4
statsd==4.0.1
python-swiftclient==4.1.0
python-keystoneclient==5.0.0
keystoneauth1==5.0.0
# error with 5.x (ConstructorError: could not determine a constructor for the tag '!record')
PyYAML==6.0
prometheus_client==0.15.0
pyopenssl==22.1.0
# generated from manifests external_dependencies
azure-identity
azure-storage-blob
prometheus_client
python-json-logger
redis
2 changes: 1 addition & 1 deletion session_redis/json_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SessionDecoder(json.JSONDecoder):
"""Decode json, recomposing recordsets and date/datetime"""

def __init__(self, *args, **kwargs):
super().__init__(object_hook=self.object_hook, *args, **kwargs)
super().__init__(*args, object_hook=self.object_hook, **kwargs)

def object_hook(self, obj):
if "_type" not in obj:
Expand Down
3 changes: 3 additions & 0 deletions session_redis/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
6 changes: 3 additions & 3 deletions session_redis/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def __init__(
self.anon_expiration = anon_expiration
self.prefix = "session:"
if prefix:
self.prefix = "%s:%s:" % (self.prefix, prefix)
self.prefix = f"{self.prefix}:{prefix}:"

def build_key(self, sid):
return "%s%s" % (self.prefix, sid)
return f"{self.prefix}{sid}"

def save(self, session):
key = self.build_key(session.sid)
Expand All @@ -56,7 +56,7 @@ def save(self, session):
expiration = session.expiration or self.anon_expiration
if _logger.isEnabledFor(logging.DEBUG):
if session.uid:
user_msg = "user '%s' (id: %s)" % (session.login, session.uid)
user_msg = f"user '{session.login}' (id: {session.uid})"
else:
user_msg = "anonymous user"
_logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion session_redis/strtobool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError as error:
raise ValueError('"{}" is not a valid bool value'.format(value)) from error
raise ValueError(f'"{value}" is not a valid bool value') from error

0 comments on commit 61d30ef

Please sign in to comment.