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

Make this package into a plugin #23

Merged
merged 6 commits into from
Mar 16, 2020
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ FLAKE8_EXCLUDE=.git
.PHONY: flake8
flake8:
# ignore "line too long"
@flake8 --exclude=$(FLAKE8_EXCLUDE) --ignore=E501 tcms_github_marketplace/
@flake8 --exclude=$(FLAKE8_EXCLUDE) --ignore=E501 tcms_github_marketplace/ tcms_settings_dir/

.PHONY: pylint
pylint:
pylint --load-plugins=pylint_django -d missing-docstring -d duplicate-code *.py \
-d wildcard-import -d unused-wildcard-import tcms_github_marketplace/ test_project/
-d wildcard-import -d unused-wildcard-import tcms_github_marketplace/ test_project/ tcms_settings_dir/


.PHONY: messages
Expand Down
4 changes: 4 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import sys

if __name__ == "__main__":
if os.path.exists("kiwitcms_github_marketplace.egg-info"):
print("ERORR: .egg-info/ directories mess up plugin loading code in devel mode")
sys.exit(1)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")

from django.core.management import execute_from_command_line
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_install_requires(path):
license='GPLv3+',
install_requires=get_install_requires('requirements.txt'),
packages=find_packages(exclude=['test_project*', '*.tests']),
zip_safe=False,
include_package_data=True,
entry_points={"kiwitcms.plugins": ["github/marketplace = tcms_github_marketplace"]},
classifiers=[
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
Expand Down
12 changes: 12 additions & 0 deletions tcms_github_marketplace/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2020 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt

from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _


# Follows the format of ``tcms.settings.common.MENU_ITEMS``
MENU_ITEMS = [
(_('Subscriptions'), reverse_lazy('github_marketplace_plans')),
]
1 change: 1 addition & 0 deletions tcms_settings_dir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
10 changes: 10 additions & 0 deletions tcms_settings_dir/marketplace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2020 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt
# pylint: disable=undefined-variable

if 'tcms_github_marketplace.views.PurchaseHook' not in PUBLIC_VIEWS: # noqa: F821
PUBLIC_VIEWS.append('tcms_github_marketplace.views.PurchaseHook') # noqa: F821

if 'tcms_github_marketplace.views.FastSpringHook' not in PUBLIC_VIEWS: # noqa: F821
PUBLIC_VIEWS.append('tcms_github_marketplace.views.FastSpringHook') # noqa: F821
101 changes: 44 additions & 57 deletions test_project/settings.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,72 @@
# Copyright (c) 2019 Alexander Todorov <atodorov@MrSenko.com>

# Licensed under the GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.txt
# pylint: disable=invalid-name, protected-access, wrong-import-position

import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# site-packages/tcms_settings_dir/ must be before ./tcms_settings_dir/
# so we can load multi_tenant.py first!
if BASE_DIR in sys.path:
sys.path.remove(BASE_DIR)
sys.path.append(BASE_DIR)

import pkg_resources

# pretend this is a plugin during testing & development
# IT NEEDS TO BE BEFORE the wildcard import below !!!
# .egg-info/ directory will mess up with this
dist = pkg_resources.Distribution(__file__)
entry_point = pkg_resources.EntryPoint.parse('github/marketplace = tcms_github_marketplace',
dist=dist)
dist._ep_map = {'kiwitcms.plugins': {'kiwitcms_tenants_devel': entry_point}}
pkg_resources.working_set.add(dist)

from tcms.settings.product import *

# check for a clean devel environment
if os.path.exists(os.path.join(BASE_DIR, "kiwitcms_github_marketplace.egg-info")):
print("ERORR: .egg-info/ directories mess up plugin loading code in devel mode")
sys.exit(1)


# import the settings which automatically get distributed with this package
marketplace_settings = os.path.join(
BASE_DIR, 'tcms_settings_dir', 'marketplace.py')

# Kiwi TCMS loads extra settings in the same way using exec()
exec( # pylint: disable=exec-used
open(marketplace_settings, "rb").read(),
globals()
)

# these are enabled only for testing purposes
DEBUG = True
TEMPLATE_DEBUG = True
SECRET_KEY = '7d09f358-6609-11e9-8140-34363b8604e2'
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
LOCALE_PATHS = [os.path.join(BASE_DIR, 'tcms_github_marketplace', 'locale')]

DATABASES['default'].update({
'NAME': 'test_project',
'USER': 'kiwi',
'PASSWORD': 'kiwi',
'HOST': 'localhost',
'OPTIONS': {},
})

DATABASES = {
'default': {
'ENGINE': 'django_tenants.postgresql_backend',
'NAME': 'test_project',
'USER': 'kiwi',
'PASSWORD': 'kiwi',
'HOST': 'localhost',
'OPTIONS': {},
}
}

DATABASE_ROUTERS = [
'django_tenants.routers.TenantSyncRouter',
]

MIDDLEWARE.insert(0, 'django_tenants.middleware.main.TenantMainMiddleware')

TENANT_MODEL = "tcms_tenants.Tenant"
TENANT_DOMAIN_MODEL = "tcms_tenants.Domain"

INSTALLED_APPS.insert(0, 'django_tenants')
INSTALLED_APPS.insert(1, 'tcms_tenants')
INSTALLED_APPS.extend([
'social_django',
'tcms_github_marketplace',
])

PUBLIC_VIEWS.extend([
'social_django.views.auth',
'social_django.views.complete',
'social_django.views.disconnect',
'tcms_github_marketplace.views.PurchaseHook'
])


TENANT_APPS = [
'django.contrib.sites',

'attachments',
'django_comments',
'modernrpc',
'simple_history',

'tcms.core.contrib.comments.apps.AppConfig',
'tcms.core.contrib.linkreference',
'tcms.management',
'tcms.testcases.apps.AppConfig',
'tcms.testplans.apps.AppConfig',
'tcms.testruns.apps.AppConfig',
]

# everybody can access the main instance
SHARED_APPS = INSTALLED_APPS

# Allows serving non-public tenants on a sub-domain
# WARNING: doesn't work well when you have a non-standard port-number
KIWI_TENANTS_DOMAIN = 'tenants.localdomain'

# share login session between tenants
SESSION_COOKIE_DOMAIN = ".%s" % KIWI_TENANTS_DOMAIN

# attachments storage
DEFAULT_FILE_STORAGE = "tcms_tenants.storage.TenantFileSystemStorage"
MULTITENANT_RELATIVE_MEDIA_ROOT = "tenants/%s"

ROOT_URLCONF = 'test_project.urls'

SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_GITHUB_KEY = 'oauth_client_id'
SOCIAL_AUTH_GITHUB_SECRET = 'oauth_client_secret'
Expand Down
13 changes: 0 additions & 13 deletions test_project/urls.py

This file was deleted.