Pdoc - Change template directory programatically - python

I have a script that generates documentation using pdoc for all of my classes in my project. I want to further customize my documentation by making changes to pdoc templates. I want to do this inside of my project so I can track changes in git, therefor I need to change --template-dir. This is easy enough as a cmd line argument but I have not been able to make this change when using pdoc inside a python script. My question is where can I pass in this argument and or if I make an object of pdoc is there a function or parameter to make this change. Thanks in advance!

The documentation says:
If working with pdoc programmatically, prepend the directory with modified templates into the directories list of the tpl_lookup object.
This is the object in question so something like this should work:
import pdoc
pdoc.tpl_lookup.directories.insert(0, MY_TEMPLATE_DIR)

Related

Django and Mypy : unable to read config options

I am attempting to use mypy with django, following the tutorial here:
django-mypy-check-runs
I wasn't able to use the init.py import as per the article, instead I used the same code in the ready function of the apps.py in my top level app.
mypy runs perfectly, as long as the function api.run has the project base directory in a list as a parameter as per the code in the article:
results = api.run([settings.BASE_DIR])
I am unable to find out why the project base directory presented this way is of any use. According to the docs, the list that is passed to api.run, should have configuration options passed in the list as they would be passed to the executable on the commandline. I have checked the source code of mypy and this seems to be the case.
If I change the code so that the api.run has a list as a parameter, that contains configuration options, mypy doesn't work. If I pass an empty list or no list at all, mypy doesn't work.
Also, although I have a mypy.ini file in the same directory, and also at the project root (in case this is what the settings.BASE_DIR in the list passed to api.run is supposed to specify), the configuration options in mypy.ini don't seem to be being picked up.
So, how to get the api.run to function and use configuration options from mypy.ini...
MTIA.
Ok, it turned out to be quite obvious, documented etc etc.
The api.run command takes the same args as the mypy commandline invocation. So the following worked for me...
results = api.run(['--show-error-codes', settings.BASE_DIR])

What are the parameters and how to add it in plugins of cronicle?

Cronicle is similar to cronjobs
Here is GitHub link: https://github.com/jhuckaby/Cronicle#Plugins%20Tab
But I don't know how to add parameters in plugins.
It says
Parameters are passed to your Plugin via JSON, and as environment variables.
For example, you can use this to customize the PATH variable, if your Plugin requires it.
In Python
import json,sys
path = json.load(sys.stdin)["params"]["path"]
Cronicle takes json as input

Django: Python path syntax to my custom validators.py?

I want to implement the solution detailed in this thread but I can't for the life of me figure out the Python path syntax in settings.py needed to link back to my custom validators.py I'm not even sure where to put it. I feel like a simple explanation of how the Python path syntax works in Django ought to be in the docs but after almost 20 minutes of looking through them I don't see anything. Any help would be greatly appreciated.
I'm assuming your custom validators.py is within your project, so like any of your other Python project's module it is accessed using dot notation.
The only thing "different" here is that you append the actual class name to this module string. For example:
AUTH_PASSWORD_VALIDATORS = [
'yourproject.validators.YourValidatorClass',
]
(although the format is not specified in this specific setting in the docs, it is a constant pattern used throughout Django settings)

Redefine class/model of python module

I want to use django-achievements (link) module in my app, but it lack some fields in it's model. For example, I want to add CharField to it with path to picture of the badge/achievement. Also I will need to modify module's engine.py file for that.
What is the right way to do that? Download that module to my main app' folder and modify original files, or i can somehow redefine some methods/classes of original models.py and engine.py locally without modifing original files?
I'd say fork it and make your own modifications directly to the source. If it's an improvement you can create a Pull Request and contribute your code to the actual repository (not required, you can always just keep it for your own use).

How do I apply a patch from gist to the Django source?

I want to try out a patch on gist that modifies the source code of Django:
gist: 550436
How do I do it? I have never used git so a step by step instruction would be greatly appreciated.
You can use patch to apply diffs. Make sure you're in your django source directory (or wherever you want to apply the patch), and run something like patch -p1 < downloaded-patch.diff.
You may want to experiment with the -p argument if it fails; -p tells patch to strip some of the directory prefix for each file in the diff (look at the first line in the diff).

Categories