Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable code formatting with black #226

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ repos:
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[flake8]
max-line-length = 100
max-line-length = 102

[pylint]
max-line-length = 102
46 changes: 23 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@


def get_long_description():
with open('README.rst', 'r', encoding="utf-8") as file:
with open("README.rst", "r", encoding="utf-8") as file:
return file.read()


def get_install_requires(path):
requires = []

with open(path, 'r', encoding="utf-8") as file:
with open(path, "r", encoding="utf-8") as file:
for line in file:
if line.startswith('-r '):
if line.startswith("-r "):
continue
requires.append(line.strip())
return requires


setup(
name='kiwitcms-tenants',
version='2.6.1',
description='Multi-tenant support for Kiwi TCMS',
name="kiwitcms-tenants",
version="2.6.1",
description="Multi-tenant support for Kiwi TCMS",
long_description=get_long_description(),
author='Kiwi TCMS',
author_email='[email protected]',
url='https://github.com/kiwitcms/tenants/',
license='GPLv3+',
install_requires=get_install_requires('requirements.txt'),
author="Kiwi TCMS",
author_email="[email protected]",
url="https://github.com/kiwitcms/tenants/",
license="GPLv3+",
install_requires=get_install_requires("requirements.txt"),
include_package_data=True,
packages=find_packages(exclude=['test_project*', '*.tests']),
packages=find_packages(exclude=["test_project*", "*.tests"]),
zip_safe=False,
entry_points={"kiwitcms.plugins": ["kiwitcms_tenants = tcms_tenants"]},
classifiers=[
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.11',
"Framework :: Django",
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.11",
],
)
2 changes: 1 addition & 1 deletion tcms_settings_dir/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
64 changes: 43 additions & 21 deletions tcms_settings_dir/multi_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@


# start multi-tenant settings override
DATABASES['default']['ENGINE'] = 'django_tenants.postgresql_backend' # noqa: F821
DATABASE_ROUTERS = ['django_tenants.routers.TenantSyncRouter', ]
DATABASES["default"]["ENGINE"] = "django_tenants.postgresql_backend" # noqa: F821
DATABASE_ROUTERS = [
"django_tenants.routers.TenantSyncRouter",
]


# attachments storage
Expand All @@ -16,31 +18,48 @@


# this always needs to be the first app
if 'django_tenants' not in INSTALLED_APPS: # noqa: F821
INSTALLED_APPS.insert(0, 'django_tenants') # noqa: F821
if "django_tenants" not in INSTALLED_APPS: # noqa: F821
INSTALLED_APPS.insert(0, "django_tenants") # noqa: F821

for app_list in (INSTALLED_APPS, TENANT_APPS): # noqa: F821
if 'tenant_groups' not in app_list:
app_list.append('tenant_groups')
if "tenant_groups" not in app_list:
app_list.append("tenant_groups")


KIWI_TENANTS_DOMAIN = os.environ.get('KIWI_TENANTS_DOMAIN')
KIWI_TENANTS_DOMAIN = os.environ.get("KIWI_TENANTS_DOMAIN")


# TenantMainMiddleware always needs to be first
if 'django_tenants.middleware.main.TenantMainMiddleware' not in MIDDLEWARE: # noqa: F821
MIDDLEWARE.insert(0, 'django_tenants.middleware.main.TenantMainMiddleware') # noqa: F821

if 'tcms_tenants.middleware.BlockUnauthorizedUserMiddleware' not in MIDDLEWARE: # noqa: F821
MIDDLEWARE.append('tcms_tenants.middleware.BlockUnauthorizedUserMiddleware') # noqa: F821
if (
"django_tenants.middleware.main.TenantMainMiddleware"
not in MIDDLEWARE # noqa: F821
):
MIDDLEWARE.insert( # noqa: F821
0, "django_tenants.middleware.main.TenantMainMiddleware"
)

if (
"tcms_tenants.middleware.BlockUnauthorizedUserMiddleware"
not in MIDDLEWARE # noqa: F821
):
MIDDLEWARE.append( # noqa: F821
"tcms_tenants.middleware.BlockUnauthorizedUserMiddleware"
)

# replace ModelBackend with GroupsBackend
if 'django.contrib.auth.backends.ModelBackend' in AUTHENTICATION_BACKENDS: # noqa: F821
idx = AUTHENTICATION_BACKENDS.index('django.contrib.auth.backends.ModelBackend') # noqa: F821
AUTHENTICATION_BACKENDS[idx] = 'tenant_groups.backends.GroupsBackend' # noqa: F821
if "django.contrib.auth.backends.ModelBackend" in AUTHENTICATION_BACKENDS: # noqa: F821
idx = AUTHENTICATION_BACKENDS.index( # noqa: F821
"django.contrib.auth.backends.ModelBackend"
)
AUTHENTICATION_BACKENDS[idx] = "tenant_groups.backends.GroupsBackend" # noqa: F821

if 'tcms_tenants.backends.PubliclyReadableBackend' not in AUTHENTICATION_BACKENDS: # noqa: F821
AUTHENTICATION_BACKENDS.append('tcms_tenants.backends.PubliclyReadableBackend') # noqa: F821
if (
"tcms_tenants.backends.PubliclyReadableBackend"
not in AUTHENTICATION_BACKENDS # noqa: F821
):
AUTHENTICATION_BACKENDS.append( # noqa: F821
"tcms_tenants.backends.PubliclyReadableBackend"
)


TENANT_MODEL = "tcms_tenants.Tenant"
Expand All @@ -55,7 +74,10 @@
SHARED_APPS = INSTALLED_APPS # noqa: F821

# add tennants context processor
if 'tcms_tenants.context_processors.tenant_navbar_processor' not in\
TEMPLATES[0]['OPTIONS']['context_processors']: # noqa: F821
TEMPLATES[0]['OPTIONS']['context_processors'].append( # noqa: F821
'tcms_tenants.context_processors.tenant_navbar_processor') # noqa: F821
if (
"tcms_tenants.context_processors.tenant_navbar_processor"
not in TEMPLATES[0]["OPTIONS"]["context_processors"] # noqa: F821
):
TEMPLATES[0]["OPTIONS"]["context_processors"].append( # noqa: F821
"tcms_tenants.context_processors.tenant_navbar_processor"
) # noqa: F821
Loading
Loading