Skip to content

Commit

Permalink
chore: introduce typo checker to pre-commit and fix typos (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinHolzingerQC-OLD authored Jan 31, 2024
1 parent 2d7baea commit fd3003a
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: (quetz/migrations)
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand Down Expand Up @@ -41,3 +42,8 @@ repos:
rev: v1.1.314
hooks:
- id: pyright
- repo: https://github.com/Quantco/pre-commit-mirrors-typos
rev: 1.16.26
hooks:
- id: typos-conda
exclude: (quetz/tests/authentification/test_oauth.py)
5 changes: 5 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[default.extend-words]
fo = "fo"

[files]
extend-exclude = ["quetz/migrations/*.po", "quetz/tests/authentification/test_oauth.py"]
2 changes: 1 addition & 1 deletion docker/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@
#
# This function is called after the user has passed all authentication checks
# and is ready to successfully authenticate. This function must return the
# authentication dict reguardless of changes to it.
# authentication dict regardless of changes to it.
#
# This maybe a coroutine.
#
Expand Down
2 changes: 1 addition & 1 deletion docs/source/deploying/authenticators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ For example, the custom authenticator might be:
Registering authenticator
^^^^^^^^^^^^^^^^^^^^^^^^^

The standard way to register an authenticator with Quetz, is to distibute it as a plugin
The standard way to register an authenticator with Quetz, is to distribute it as a plugin
(see :ref:`plugins_section`).
To automatize the creation of a plugin, check out our cookiecutter `template`_.

Expand Down
10 changes: 5 additions & 5 deletions docs/source/deploying/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ Configure default user permissions, creating default channel and super-admin per
admins = ["github:admin_user"]
# users with maintainer role
maintainers = ["google:other_user"]
# users with memeber role
# users with member role
members = ["github:some", "github:random", "github:name"]
# default role assigned to new users
# leave out if role should be null
default_role = "member"
# create a default channel for new users named {username}
create_default_channel = false
# wether to collect email addresses when users register
# whether to collect email addresses when users register
collect_emails = false
You can use one of the following options to configure privileged users:
Expand Down Expand Up @@ -193,7 +193,7 @@ Quetz can store packages in Google Cloud Storage. To configure, use the followin
region="..."
:project: The Google Cloud Project ID to work under
:token: A token to pass the `gcsfs`. See the `gcsfs documention <https://gcsfs.readthedocs.io/en/latest/index.html#credentials>`_ for valid values.
:token: A token to pass the `gcsfs`. See the `gcsfs documentation <https://gcsfs.readthedocs.io/en/latest/index.html#credentials>`_ for valid values.
:bucket_prefix:
:bucket_suffix: channel buckets on GCS are created with the following semantics: ``{bucket_prefix}{channel_name}{bucket_suffix}``
:cache_timeout: Timeout in s after which local GCS cache entries are invalidated. Set to a value <=0 to disable caching completely. Default is that entries are never invalidated.
Expand Down Expand Up @@ -270,9 +270,9 @@ You can also use a couple of environment variables to configure the behaviour of
Variable description values default
======================= ====================================== =========================== ===================
``QUETZ_LOG_LEVEL`` log level ERROR, INFO, WARNING, DEBUG INFO or config file
``QUETZ_API_KEY`` api key used by quetz-client log level string
``QUETZ_API_KEY`` api key used by quetz-client string
``QUETZ_TEST_DATABASE`` uri to the database used in tests string sqlite:///:memory:
``QUETZ_TEST_DBINIT`` method to create db tabels in tests "create-tables" or "create-tables"
``QUETZ_TEST_DBINIT`` method to create db tables in tests "create-tables" or "create-tables"
"use-migrations"
``S3_ACCESS_KEY`` access key to s3 (used in tests) string
``S3_SECRET_KEY`` secret key to s3 (used in tests) string
Expand Down
2 changes: 1 addition & 1 deletion docs/source/deploying/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Deploying
=========

There are many options for deploying a package repository with Quetz. You can deploy Quetz either locally for
testing, on a production server or in the cloud. The process can be tailored to your needs and exisiting
testing, on a production server or in the cloud. The process can be tailored to your needs and existing
infrastructure.

.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion docs/source/deploying/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ When the data classes in Quetz are modified (for example, a column is added, rem

.. note::

Before running any of the commands below, you need to make sure that your database is backed up. The backup process depends on the infrastrcuture, but in the simplest case it may involve the dump of the whole database (using ``pg_dump`` for example).
Before running any of the commands below, you need to make sure that your database is backed up. The backup process depends on the infrastructure, but in the simplest case it may involve the dump of the whole database (using ``pg_dump`` for example).

Migrating database
------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/qeps/qep-001-user-permissions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Roles can be configure with a config file:
admins = ["wolfv"]
# users with maintainer role
maintainers = ["btel"]
# users with memeber role
# users with member role
members = ["some", "random", "name"]
# default role assigned to new users
# leave out if role should be null
Expand Down
2 changes: 1 addition & 1 deletion quetz/authentication/azuread.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AzureADAuthenticator(OAuthAuthenticator):
tenant_id = "tenant-name or id"
You can obtain ``client_id`` and ``client_secret`` by registering your
application with AzureAD platfrom at this URL:
application with AzureAD platform at this URL:
`https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps`
The ``tenant_id`` can either be a specific tenant's GUID identifier or one of three
Expand Down
2 changes: 1 addition & 1 deletion quetz/authentication/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GoogleAuthenticator(OAuthAuthenticator):
client_secret = "03728444a12abff17e9444fd231b4379d58f0b"
You can obtain ``client_id`` and ``client_secret`` by registering your
application with Google platfrom at this URL:
application with Google platform at this URL:
`<https://console.developers.google.com/apis/credentials>`_.
"""

Expand Down
6 changes: 3 additions & 3 deletions quetz/authentication/jupyterhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def register(cls, config: Config):


class JupyterhubAuthenticator(OAuthAuthenticator):
"""Use Oauth2 protcol to authenticate with jupyterhub server, which acts
"""Use OAuth2 protocol to authenticate with jupyterhub server, which acts
as identity provider.
To activate add the following section to the ``config.toml`` (see :ref:`configfile`):
Expand All @@ -74,13 +74,13 @@ class JupyterhubAuthenticator(OAuthAuthenticator):
client_id = "quetz_client"
client_secret = "super-secret"
# token enpoint of Jupyterhub, needs to be accessible from Quetz server
# token endpoint of Jupyterhub, needs to be accessible from Quetz server
access_token_url = "http://JUPYTERHUB_HOST:PORT/hub/api/oauth2/token"
# authorize endpoint of JupyterHub, needs to be accessible from users' browser
authorize_url = "http://JUPYTERHUB_HOST:PORT/hub/api/oauth2/authorize"
# API root, needs to be accesible from Quetz server
# API root, needs to be accessible from Quetz server
api_base_url = "http://JUPYTERHUB_HOST:PORT/hub/api/"
To configure quetz as an oauth client in JupyterHub, you will need to define
Expand Down
6 changes: 3 additions & 3 deletions quetz/authentication/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ class OAuthAuthenticator(BaseAuthenticator):
"""Base class for authenticators using Oauth2 protocol and its variants.
The :py:meth:`authenticate` method is already implemented, but you will need to
override some of the following variables in sublasses to make it work:
override some of the following variables in subclasses to make it work:
:var str provider: name of the provider (it will be used in the url)
:var handler_cls: class with handlers for all oauth2
relevant endpoints in Quetz server
:type handler_cls: sublass of :py:class:`OauthHandlers`
:type handler_cls: subclass of :py:class:`OauthHandlers`
:var client_id: required, client id registered with the provider
:var client_secret: required, likewise
:var bool is_enabled: True if authenticator is enabled, can be configured in
:py:meth:`configure` method
:var access_token_url: URL of the OAuth2 endpoint ot request a token
:var access_token_url: URL of the OAuth2 endpoint to request a token
:var authorize_url: URL of the OAuth2 ``authorize`` endpoint
:var api_base_url: URL of the API root of the provider server
:var validate_token_url: path of endpoint to validate the token
Expand Down
2 changes: 1 addition & 1 deletion quetz/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def assert_create_api_key_roles(self, roles):
)
self.assert_channel_roles(role.channel, required_channel_roles)
else:
# create key without assigning special channel/package privilages
# create key without assigning special channel/package privileges
return True

def assert_delete_api_key(self, api_key):
Expand Down
2 changes: 1 addition & 1 deletion quetz/channel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def export(dao, channel_name):
packages = channeldata["packages"]
subdirs = set(['noarch'])

for name, info in dao.get_channel_datas(channel_name):
for name, info in dao.get_channel_data(channel_name):
if info is not None:
data = json.loads(info)
packages[name] = data
Expand Down
14 changes: 7 additions & 7 deletions quetz/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,18 @@ def _get_environ_config(self) -> Dict[str, Any]:
if key.startswith(_env_prefix)
}
for var, value in quetz_var.items():
splitted_key = var.split('_')
config_key = splitted_key[1].lower()
split_key = var.split('_')
config_key = split_key[1].lower()
idx = 2

# look for the first level of config_map.
# It must be done in loop as the key itself can contains '_'.
first_level = None
while idx < len(splitted_key):
while idx < len(split_key):
first_level = self._find_first_level_config(config_key)
if first_level:
break
config_key += f"_{ splitted_key[idx].lower()}"
config_key += f"_{ split_key[idx].lower()}"
idx += 1

# no first_level found, the variable is useless.
Expand All @@ -430,7 +430,7 @@ def _get_environ_config(self) -> Dict[str, Any]:
config[first_level.name] = value
# the first level is a section.
elif isinstance(first_level, ConfigSection):
entry = "_".join(splitted_key[idx:]).lower()
entry = "_".join(split_key[idx:]).lower()
# the entry does not exist in section, the variable is useless.
if entry not in [
section_entry.name for section_entry in first_level.entries
Expand All @@ -439,7 +439,7 @@ def _get_environ_config(self) -> Dict[str, Any]:
# add the entry to the config.
if first_level.name not in config:
config[first_level.name]: Dict[str, Any] = {}
config[first_level.name]["_".join(splitted_key[idx:]).lower()] = value
config[first_level.name]["_".join(split_key[idx:]).lower()] = value

return config

Expand Down Expand Up @@ -506,7 +506,7 @@ def configured_section(self, section: str) -> bool:
Returns
-------
bool
Wether or not the given section is configured
Whether or not the given section is configured
"""

return bool(self.config.get(section))
Expand Down
8 changes: 4 additions & 4 deletions quetz/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def _parse_sort_by(query, model, sortstr: str):
sorts = sortstr.split(',')

for s in sorts:
splitted = s.split(':')
if len(splitted) == 2:
field, order = splitted
split_result = s.split(':')
if len(split_result) == 2:
field, order = split_result
else:
field = s
order = 'desc'
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def get_package_infos(self, channel_name: str, subdir: str):
.order_by(PackageVersion.filename)
)

def get_channel_datas(self, channel_name: str):
def get_channel_data(self, channel_name: str):
# Returns iterator
return (
self.db.query(Package.name, Package.channeldata)
Expand Down
6 changes: 3 additions & 3 deletions quetz/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def register_router() -> 'fastapi.APIRouter':
def post_add_package_version(
version: 'quetz.db_models.PackageVersion', condainfo: 'quetz.condainfo.CondaInfo'
) -> None:
"""hook for post-processsing after adding a package file.
"""hook for post-processing after adding a package file.
:param quetz.db_models.PackageVersion version:
package version model that was added in to the database
Expand All @@ -42,7 +42,7 @@ def post_package_indexing(
files: dict,
packages: dict,
) -> None:
"""hook for post-processsing after building indexes.
"""hook for post-processing after building indexes.
:param quetz.pkgstores.PackageStore pkgstore:
package store used to store/retrieve packages
Expand Down Expand Up @@ -70,7 +70,7 @@ def post_index_creation(
channel_name: str,
subdir: str,
) -> None:
"""hook for post-processsing after creating package index.
"""hook for post-processing after creating package index.
:param dict raw_repodata:
the package index
Expand Down
4 changes: 2 additions & 2 deletions quetz/jobs/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ def _update_running_jobs(self):
.outerjoin(Job)
.filter(running_job)
.group_by(Task.job_id)
# select jobs where all tasks are finsihed
# select jobs where all tasks are finished
.having(all_true(task_done))
.all()
)
for job_id, repeat, failed in results:
if repeat:
# job with repeat non-null repeat column should be
# kept runing until cancelled
# kept running until cancelled
status = JobStatus.pending
elif failed:
status = JobStatus.failed
Expand Down
2 changes: 1 addition & 1 deletion quetz/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ async def task():


@app.on_event("shutdown")
async def stop_sync_donwload_counts():
async def stop_sync_download_counts():
app.sync_download_task.cancel()
try:
await app.sync_download_task
Expand Down
2 changes: 1 addition & 1 deletion quetz/metrics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def synchronize_metrics_from_mirrors(
packages = response_data["packages"]
except KeyError:
logger.error(
f"malfromated respose received from {metrics_url}: "
f"malfromated response received from {metrics_url}: "
"missing 'packages' key"
)
continue
Expand Down
6 changes: 3 additions & 3 deletions quetz/tasks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def validate_packages(dao, pkgstore, channel_name):
in_ls_not_db = ls_result_set - db_result_set
in_db_not_ls = db_result_set - ls_result_set

valid, inexistant, wrong_size = 0, 0, 0
valid, inexistent, wrong_size = 0, 0, 0

# remove all files that are in database and not uploaded
for f in in_db_not_ls:
Expand All @@ -138,7 +138,7 @@ def validate_packages(dao, pkgstore, channel_name):
.one()
)
dao.db.delete(db_pkg_to_delete)
inexistant += 1
inexistent += 1

db_dict = dict(db_result)
for f in ls_result:
Expand Down Expand Up @@ -173,7 +173,7 @@ def validate_packages(dao, pkgstore, channel_name):

logger.info(f"Valid files: {valid}")
logger.info(f"Wrong size: {wrong_size}")
logger.info(f"Not uploaded: {inexistant}")
logger.info(f"Not uploaded: {inexistent}")

update_indexes(dao, pkgstore, channel_name)

Expand Down
6 changes: 3 additions & 3 deletions quetz/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def auto_rollback():
@pytest.fixture
def session_maker(sql_connection, create_tables, auto_rollback):
# run the tests with a separate external DB transaction
# so that we can easily rollback all db changes (even if commited)
# so that we can easily rollback all db changes (even if committed)
# done by the test client

# Note: when rollback is explictly called in the implementation,
# Note: when rollback is explicitly called in the implementation,
# it will remove all objects created in the test even the ones
# that were already committed!

Expand Down Expand Up @@ -255,7 +255,7 @@ def get_session_mock(*args, **kwargs):

mocker.patch("quetz.database.get_session", get_session_mock)

# overiding dependency works with all requests handlers that
# overriding dependency works with all requests handlers that
# depend on quetz.deps.get_db
app.dependency_overrides[get_db] = lambda: db

Expand Down
4 changes: 2 additions & 2 deletions quetz/tests/api/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def remove_jobs(db):
def test_channel_names_are_case_insensitive(
auth_client, maintainer, remove_package_versions
):
channel_name = "MyChanneL"
channel_name = "MyChannel"

response = auth_client.post(
"/api/channels", json={"name": channel_name, "private": False}
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_channel_names_are_case_insensitive(


def test_unique_channel_names_are_case_insensitive(auth_client, maintainer):
channel_name = "MyChanneL"
channel_name = "MyChannel"

response = auth_client.post(
"/api/channels", json={"name": channel_name, "private": False}
Expand Down
2 changes: 1 addition & 1 deletion quetz/tests/api/test_main_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def api_key(db, dao: Dao, owner, private_channel):
],
)
),
"API key with role restruction",
"API key with role restriction",
)

yield key
Expand Down
Loading

0 comments on commit fd3003a

Please sign in to comment.