Specifying a django download link in djangorecipe with buildout - django

I want to deploy my django project using buildout, so I use djangorecipe, but
It will automatically download Django
as says in the readme, and I want to have the option to specify a url to download django (i.e. from a pypi server).
I try to set it with index and find-links buildout options but when they say automatically is true.
I searched through several recipes and found out 2 djangorecipe's forks that seem go in a similar direction, these are thechristmaspig and djbuild. The first left the download responsibility to the recipe zerokspot.recipe.git and the second allow to specify a svn repo. But both of them haven't recent activity (more than 2 years) and a very small community, that poor support make me out.
Can you suggest another way without hacks djangorecipe?
UPDATE:
I had tested with some options without success:
mr.developer:
In djangorecipe mentions use this recipe and I try with fs option of source but no way with an url like this:
[sources]
django = fs http://pypi_server/simple/
I tested with several settings but it seems only works with directory in file system
zc.recipe.egg:
But it also use the same url of the djangorecipe and no found a way change it
UPDATE2:
gp.recipe.pip:
Same results of zc.recipe.egg, but notice something: If remove the use of djangorecipe i.e. (commenting this section):
[buildout]
parts = pip
[pip]
recipe = gp.recipe.pip
install = django
#[django]
#recipe = djangorecipe
#settings = settings
it download django from the local pypi server. With django enabled (uncommenting django section and add django to buildout:parts) it download from www.djangoproject.com server.
In order to execute gp.recipe.pip first (so djangorecipe found django installed) I'm tried with two ways for refering a variable:
Refering a pip's variable from django section (as explain in the section "Automatic part selection and ordering" of buildout docs)
Proceding with section Extending sections (macros) of buildout docs
Note that reorganize sections or change the values order in parts variable no matters for change the execution order.
But again no success
Any ideas?
Thanks

Based on the UPDATE2's comments in the question I figure to have two .cfg files: the one with only pip settings and the second for django settings. Then execute twice buildout using -c option to specify files. So with first buildout call it installs django from pypi server, second encounter that django has been installed and move on. This should works and maybe this is the solution, any other? thx

Related

How to minify ES2016 or convert to ES2015 in flask?

I'm using flask-assets and none of the available filters (rjsmin, jsmin, closure_js, uglifyjs, etc.) is able to minify a ES2016 JavaScript file. The minified files yield errors on the browser console (due to bad conversions) or even crash on execution before serving the resources.
Also, I have tried Babel filter from webassets and I it doesn't make any change on the files, they are just served without changes.
I also can't manage to enforce the closure or babel extra_args to customise their operation.
Any tip or recommendation?
Example code:
from flask_assets import Bundle
page_js = Bundle(
'js/code_with_es2016.js',
filters='rjsmin',
output='public/js/code.min.js'
)
You will need to use the babel filter with babel-presets-env. The webassets documentation is a bit behind on the recent developments which is no surprise considering how fast things are moving in the javascript world.
So first you will need to install babel-cli globally:
npm install -g babel-cli
Now you will need to install babel-preset-env locally, so within your project directory do:
npm install --save babel-preset-env
Finally this is how to set up your bundle with flask-assets:
from flask_assets import Bundle, Environment
from webassets.filter import get_filter
assets = Environment()
assets.init_app(app)
babel = get_filter('babel', presets='babel-preset-env')
assets.register('js_all', Bundle(
'js/code_with_es2016.js',
output='public/js/code.min.js',
filters=[babel, 'rjsmin']
))
You can also tell babel where your babel-preset-env is installed by specifying the absolute or relative path to it:
preset_location = './path/to/node_modules/babel-preset-env'
babel = get_filter('babel', presets=preset_location)
assets.register('js_all', Bundle(
'js/code_with_es2016.js',
output='public/js/code.min.js',
filters=[babel, 'rjsmin']
))
And one last thing, and this is only (like) my opinion, I would highly recommend switching over to javascript/node based build process for your frontend assets (you are using babel already!). Depending on what you are developing gulp or webpack can be good candidates to use for your frontend build. Flask-assets/webassets just seem unnecessary because they're lagging behind with docs and package versions of whatever the latest and greatest in the frontend world is.

Error in locating and reading specific .env file, in django project

In my project, I just added new security methods, separating the .env from the project into another folder and adopting the use of new processes. To do this, I followed the python-dotenv lib documentation, which I use in my app.
But even following the suggestion I can not find all the parameters, since I end up having the following error:
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
My settings:
from dotenv import load_dotenv
env_path = Path('/home/user/configs') / '.env'
load_dotenv(dotenv_path=str(env_path))
How can I resolve this problem from the specific path?
Note: I use in my project, python 3.4.5 and django 1.9.4, but I do not believe that the problem is caused by the old versions adopted in the project.
Another important detail is that the .env file is correct, because when I use it in the same folder where I find the file settings.py it works without problems!
I'm also using this approach and from past few months I'm following a very good developer and he also writes about a python dependency "python-decouple" and you will going to get it in detail at this link
I think this will definitely going to solve your problem.
Python-decouple github repo : here
You can add the folder containing .env to the path. Here's how I did it:
load_dotenv(os.path.join(BASE_DIR, "project", ".env"))
Answered it here.

Install third-party Markdown extension in Pelican

I'm using Pelican for a static blog, and attempting to install the figure-ref extension. Since I'm using Markdown, the plugin relies on the figureAltCaption third-party Markdown extension. However I have no idea how to install it.
Pelican has an MD_EXTENSIONS configuration option, but I've tried a few obvious options with no luck. It seems like this is a dead-simple gimme but it's not clear how to proceed. Would love some suggestions.
Unfortunately, the author of figureAltCaption appears to have not provided an install script. My suggestion would be to create one and contribute it as a pull request. This tutorial about creating Extensions for Python-Markdown covers creating an install script as well.
However, as a shortcut, you should be able to just copy the figureAltCaption.py file to the appropriate directory. Usually you want the site-packages directory. As this answer shows, just do the following from Python:
>>> import site; site.getsitepackages()
Then copy the figureAltCaption.py file to the first directory returned.
Now that the extension is on your PYTHONPATH, it should be importable. From the Python prompt, try:
import figureAltCaption
If you get no errors, then it worked and you just need to tell Pelican about it.
MD_EXTENSIONS = ['figureAltCaption']

Django Buildout recipe for pywhois (not on pypi)

I Am trying to create a buildout recipe for pywhois on google code.
The site of which is here:
http://code.google.com/p/pywhois/
Note: if you use easy_install pywhois it installs another package from pypi (python package index) : http://pypi.python.org/pypi/pywhois/0.1
I Am following the documentation on buildout recipe... (http://pypi.python.org/pypi/djangorecipe/1.3)
and I found out I can clone the sourcecode from here:
hg clone https://code.google.com/p/pywhois/
but I can't get it all stick together in a working buildout script... (to be honoust, this is my first buildout script trial... for all other packages I found an existing recipe and normally I try to avoid anything that's not on pypi)
i created 2 issues on their site... on of them is to use another name than in the python package index, the other one is to get their package over there.
Any buildout guru?
EDIT
(already 2 guys trying to help me, thanks!)
I used this in my buildout.conf:
extensions =
buildout.dumppickedversions
mr.developer
auto-checkout = pywhois
and added to my list develop:
develop = src/pywhois
and added to my egg list:
eggs =
myproject
pywhois
and declared the source of the repo:
[sources]
pywhois = hg https://code.google.com/p/pywhois/
and off course add to eggs: pywhois
and it's downloading it and creating an egg...
EDIT2
Whatever I do, I keep getting: Source URL for existing package 'pywhois' differs. Expected 'https://code.google.com/p/pywhois/'.";
It seems to me if the package-name of the google code package is gonna be changed, that this issue will be solved... I aleady got response on the issue tracker about this.
see http://code.google.com/p/pywhois/issues/detail?id=33
EDIT 3: Now on PyPI: python-whois
And, a brilliant quick action from the developer (Richard Penman). So the package is renamed to python-whois (he is thinking about another name, but for now this works). And he put it on pypi!
So this issue is resolved for me, but the answers of Martijn and Reinout learned me a lot more about buildout, thanks!
I'd use mr.developer to grab a local checkout, and use it as a development egg:
[buildout]
extensions = mr.developer
auto-checkout = pywhois
[sources]
pywhois = hg https://code.google.com/p/pywhois/
Now mr.developer will check out pywhois into src/, run it's setup.py to make it a development egg, and tell buildout it's available as such. Now buildout will use that local copy to satisfy any pywhois requirement.

Really confused about installing PHP Modules

I need to add http://us3.php.net/xsl this module to my PHP but I'm really confused how I actually do this? It says in install from that link 'PHP 5 includes the XSL extension by default and can be enabled by adding the argument --with-xsl[=DIR] to your configure line. DIR is the libxslt installation directory.' But unsure where these files would be? I have a VPS and access to WHM Cpanel, can I do this from there? I came across the software and install module bit in WHM but get the feeling that's not what I want...
Go to WHM -> Software -> EasyApache (Apache Update)
On the EasyApache page, choose Start customizing based on profile now, and after a couple screens, choose Exhaustive Options List. Select the modules you want to install, XSL in your case, and proceed to recompile.
You need to compile PHP manually, if you want any modules that you don't currently have. There are plenty of tutorials how to do it, for example if you have Apache 2 as a webserver, then follow this page on php.net: http://www.php.net/manual/en/install.unix.apache2.php
When you compile PHP, one of the commands to do is
./configure
in which you can (and most webhostings do) supply many many arguments, which say which modules you want to have installed and what features PHP can use. It may look like this:
./configure '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/lib' '--with-apxs' '--with-iconv=/usr/local/php' '--with-openssl=/usr' '--with-zlib=/usr' '--with-mysql' '--with-pgsql=/Users/marc/cvs/entropy-php4/php-module/build/postgresql-build' '--enable-cgi' '--with-gd' '--with-png-dir=/usr/local/php' '--with-freetype-dir=/usr/local/php' '--with-t1lib=/usr/local/php' '--with-jpeg-dir=/usr/local/php' '--with-tiff-dir=/usr/local/php' '--with-curl=/usr/local/php' '--with-mcal=/usr/local/php' '--with-mcrypt=/usr/local/php' '--with-mhash=/usr/local/php' '--with-pdflib=/usr/local/php' '--with-imap=../imap-2002d' '--with-imap-ssl=/usr' '--with-expat-dir=/usr/local/php' '--with-gettext=/usr/local/php' '--with-dom=/usr/local/php' '--with-dom-xslt=/usr/local/php' '--with-dom-exslt=/usr/local/php' '--with-xslt-sablot=/usr/local/php' '--with-mime-magic=/usr/local/php/etc/magic.mime' '--with-mssql=/usr/local/php' '--with-fbsql=/Users/marc/cvs/entropy-php4/php-module/build/frontbase-build/Library/FrontBase' '--with-ming=/Users/marc/cvs/entropy-php4/php-module/build/ming-build' '--enable-xslt' '--with-ldap' '--with-xml' '--with-xmlrpc' '--with-iodbc=/usr' '--enable-sockets' '--enable-dbx' '--enable-dbase' '--enable-trans-sid' '--enable-exif' '--enable-wddx' '--enable-ftp' '--enable-mbstring'
it this example there are a lot of enabled modules. You can also see what "configure line" was used to compile your current version of PHP in phpinfo (it's right at the top, third line).