Git Product home page Git Product logo

pretix-plugin-cookiecutter's Introduction

pretix-plugin-cookiecutter

A simple cookiecutter template to bootstrap a pretix plugin.

Usage

Let's pretend you want to create a pretix plugin called "superplugin". First, create a virtual environment and install the cookiecutter package using pip. Next, use it to bootstrap your project folder:

$ cd <your-project-folder-parent>
$ cookiecutter https://github.com/pretix/pretix-plugin-cookiecutter

You'll be prompted for some questions. Answer them, and you will find a project folder created for you:

repo_name [pretix-superplugin]: pretix-superplugin
repo_url [GitHub repository URL]: https://github.com/myuser/pretix-superplugin
module_name [pretix_superplugin]: pretix_superplugin
human_name [The pretix super plugin]: Super Plugin
author_name [Your name]: J Random Developer
author_email [Your email]: [email protected]
short_description [Short description]: The best plugin
Select license:
1 - Apache
2 - pretix Enterprise
Choose from 1, 2 [1]: 1
min_basever [2.7.0]: 2.7.0
Select category:
1 - FEATURE
2 - PAYMENT
3 - INTEGRATION
4 - CUSTOMIZATION
5 - FORMAT
6 - API
Choose from 1, 2, 3, 4, 5, 6 [1]: 1

Now, change to the newly created directory:

$ cd pretix-superplugin

Voilà, there's your plugin structure! See pretix' documentation for more info.

pretix-plugin-cookiecutter's People

Contributors

felixrindt avatar luelista avatar nerdoc avatar pc-coholic avatar raphaelm avatar rixx avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pretix-plugin-cookiecutter's Issues

Tests > Run "py.test tests" fails on GitHub

Disclaimer: I am not familiar with cookiecutters and only very, very vaguely with CI/CD.

I tried using the pretix-plugin-cookiecutter and pushed it to a private repository. I made a minor change (added urlpatterns to urls.py) and py.test tests fails, with this being the last call:

File "/opt/hostedtoolcache/Python/3.8.7/x64/lib/python3.8/site-packages/pretix/base/secrets.py", line 7, in <module>
    from cryptography.hazmat.primitives.serialization.base import (
ImportError: cannot import name 'Encoding' from 'cryptography.hazmat.primitives.serialization.base' (/opt/hostedtoolcache/Python/3.8.7/x64/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py)

This does not seem to be related to the change I made.

make localegen not working on OS X

The command make localgen is not working on OS X.

The problem is the -printf command for find which is not POSIX compliant.

A quick workaround is installing findutils with brew brew install findutils and changing find in the makefile to gfind

How to run pytest with custom DJANGO_SETTINGS_MODULE in plugin development

I updated our authentication plugin for Pretix with the 4.7 changes and wanted to create tests. Given that our plugin is based on the cookiecutter, this would seem the best place to open this issue.

To test our custom authentication backend, we need to adjust the settings module to one included in the plugin. Given that we have a custom settings file tests/settings.py:

from pretix.testutils.settings import *  # NOQA
PRETIX_AUTH_BACKENDS = ["pretix_superplugin.SuperOAuthBackend"]

And I adopt the following change:

diff --git a/setup.cfg b/setup.cfg
index 30aed19..9b82383 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -17,7 +17,7 @@ line_length = 88
 known_first_party = pretix_superplugin
 
 [tool:pytest]
-DJANGO_SETTINGS_MODULE = pretix.testutils.settings
+DJANGO_SETTINGS_MODULE = tests.settings
 
 [coverage:run]
 source = pretix_superplugin

Given I've also installed pretix and it's development setup: pip install pretix[dev]. Without, pytest-django, the included tests work, however for obvious reasons we'd want to use things like @pytest.mark.django_db. Running pytest with [dev]-dependencies installed, we run into the following error:

  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pytest_django/plugin.py", line 183, in _handle_import_error
    raise ImportError(msg)
ImportError: No module named 'tests.settings'

pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.
Full traceback
Traceback (most recent call last):
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pytest_django/plugin.py", line 179, in _handle_import_error
    yield
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pytest_django/plugin.py", line 351, in pytest_load_initial_conftests
    dj_settings.DATABASES
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tests.settings'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/pretix-superplugin/venv/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1191, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pytest_django/plugin.py", line 351, in pytest_load_initial_conftests
    dj_settings.DATABASES
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/tmp/pretix-superplugin/venv/lib/python3.8/site-packages/pytest_django/plugin.py", line 183, in _handle_import_error
    raise ImportError(msg)
ImportError: No module named 'tests.settings'

pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.

I've attempted to debug this but am stuck on this. I've looked through the tests in various public plugins, but could not locate any using custom settings. Any clue to how I might go about this scenario? Perhaps you're open to sharing how plugins with required custom settings are set-up, that are developed non-publicly.

docformatter removed but only in CI?

bbed3b6 removes docformatter from the CI configs, but it is still in the git commit hook, the dev install instructions and even in the pip install line in the gitlab-ci.yml. Are these oversights or is it expected that docformatter runs locally but not on the CI?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.