requestsbut you can’t use specific Django Rest Framework.
PROVIDERSlist defined in your
providers.pyconfiguration file. When a package provider is added to this list, this will allow additional bindings, commands, views, routes, migrations and assets to be registered in your project.
Use this templateto create your own GitHub repository scaffolded with the default package layout and then clone your repository to start developing locally.
cookiecutterpackage to scaffold your package with configuration options (name, author, url...). The advantages is that you won't need to edit all the occurences of your package name after generation.
cookiecutterglobally (or locally) on your computer:
pytestand it will also install your package locally so that you can start using and testing it in the test project directly.
tests/integrations. This project is really useful to directly test your package behaviour. It is scaffolded as a default Masonite project with your package already installed (see Installing a Package section). You can run the project with the usual command:
http://localhost:8000to see the welcome page.
API tokenssection. Click on
Add API token, give a significant name such as
publish-tokenand create the token. Write down the token key somewhere for later.
.pypircfile in your home directory. If you do not have one then you can easily creating one using:
passwordkey with the token you created later prefixed by
pypi-. With a token starting with
.pypircfile would look like:
setup.pyfile are up to date. It's the file describing your package. Fill in the correct version number you want to publish. When ready you can run:
configure()method is called in usual
register()method and is used to register all resources used in your package.
root(import_path)method should be called first and is used to specify the import path of your package. If your package needs to be used like this:
super_awesome_packageis the import path of your package. If your package is imported like this:
masonite.inertiais the import path of your package.
name(string)method should be called in second and is used to specify the name of your package (not the PyPi package name neither the Python module name) but the name that will be used to reference your package in the publish command or in the resources paths (it should be a name without special characters and spaces i.e. a Python valid name). This will also be the name of your package configuration file.
config()Masonite helper. For this you will need to call
super_awesome_package/config/super_awesome.pyinto Masonite config. The configuration will then be available with
databases/migrations/. Migrations file are published with a timestamp, so here it would result in those two files:
super_awesome_package/routes/web.pyand the controllers files available in
super_awesome_package/controllersyou can do:
configure()method. The views will be namespaced after your package name:
adminfolder located at
index.htmlview you can do:
publish=Trueargument. The package publish command will publish the views files into the defined project views folder. With the default project settings it would be in
assetsfolder located at
super_awesome_package/assets/containing some asset files and folders you can do:
python craft my_package_command. For this you will need to call
python craftyou should see the two registered commands.
PackageProviderclass to create your package service provider, you will be able to publish all package resources defined below in a project. You just need to run the command
package:publishwith the name of the package (declared inside
configure()method). With our example it would be: