Archive for the ‘Python’ Category

In “The State of the Octoverse ” for 2019 Github writes:

And for the first time, Python outranked Java as the second most popular language on GitHub by repository contributors.

Not bad – JavaScript takes first place, Python and Java follow.

Talking about Python allows me to announce that I hacked my first Python application ;-)

You see, I’m still running an old version of Trac to track issues and document my developments. Old means: version 0.10.5, and the problem is that I don’t have the time at this moment to upgrade to the latest version. So when I had to move to a brand-new Windows 2016 server I just took the existing installation instructions and got Trac running fine, although not under the wings of IIS. Except for one thing: the new server was behind a firewall and a virtual IP address (VIP), the latter also taking care of HTTPS to HTTP conversion. So when my browser sends an HTTPS request, Trac sees HTTP traffic and responds with HTTP redirects when replying to certain actions. Those replies turn into error pages in the browser, since HTTP traffic from the browser does not pass the firewall and is not intercepted by the VIP…

I have been reading up on Python, but I can’t say I have developed anything seriously in it. Python is however sufficiently readable so that I easily found my way in the code. To solve my problem, I just had to force Trac to always redirect to HTTPS URLs. As far as I can tell, I had to change but a single line of code to make that happen. Here’s the code of the ‘_reconstruct_url’ function after my hack:

Image of the Python code for the function '_reconstruct_url'

I changed lines 226-227 to the single statement in line 228

I’m calling this a hack because it only solves my problem; this is not something you want to submit to a public repo. It also means that the application no longer responds to standard HTTP requests. But it’s good enough for now.

From what I have seen on the Trac website there are solutions for running later versions of Trac over SSL, but most (all?) of them seem to rely on an SSL front on the same server as Trac. Too bad that such a solution won’t work for me. Guess I’ll have to study Python and Trac a lot deeper to find the best way to cope with the architecture at work.

Read Full Post »

Sure. As told on the Zappa webpage:

Zappa makes it super easy to build and deploy server-less, event-driven Python applications (including, but not limited to, WSGI web apps) on AWS Lambda + API Gateway. Think of it as “serverless” web hosting for your Python apps. That means infinite scaling, zero downtime, zero maintenance – and at a fraction of the cost of your current deployments!

That’s less revolutionary than Frank Zappa, of course. But it might come in handy, once I find the time to do some real Python development… Then again, you will probably beat me to it!

Read Full Post »

It’s something I need to remember: how do I install an old PyUSB package on Xubuntu (or a similar Debian-based OS). Why, you ask? Because I need that old version 0.4.3 for the little script that reads the solar energy numbers from the SMA Sunny Beam.

Image of the SMA Sunny Beam monitor for our solar panel installation

The SMA Sunny Beam monitor for our solar panel installation

Luckily, it isn’t too hard to do. This is my context:

Step one is to make sure you have the required header files to compile the PyUSB package. So you open up a terminal session and execute

sudo apt-get install libusb-dev
sudo apt-get install python-dev

Step two: Extract the root folder and all the files from the PyUSB archive, and make that folder your current directory in the terminal session.

Step three: compile and install the package with this command:

sudo python setup.py install

That’s it. When all goes well, you’ll be able to verify the existence of two new files on your system, in a directory called “/usr/local/lib/python2.7/dist-packages“:



Read Full Post »

You may be forgiven to think that nowadays developers no longer need text editors, now that there are fantastic IDE’s on the market (IDE = Integrated Development Environment). But if you do any kind of web development, you’re probably using some kind of text editor, in combination with the IDE of your choice or perhaps even instead of an IDE. I know I prefer a tool that doesn’t try to be everything at once.

Choosing a text editor is not so simple, however. No matter what OS you’re on, Windows or OS X or Linux or even Android or iOS, you’ll have a rich palette of tools to choose from – and choosing is always hard. That’s why you will find dozens of web pages extolling the virtues of “the ten best text editors” on your favourite OS! I have mentioned a few OS X editors 9 months ago, but in the meantime I have also installed and worked with KomodoEdit.

I have been trying out a whole series of text editors on Windows as well. Choosing is hard, not only because currently any tool I pick also has to be compatible with Windows XP (I know, don’t say it). At work, I need even more features in an editor: I want macros or programmability, search and replace with regular expressions, syntax highlighting for all my favourite languages, extensibility, and more. Plus a tool I’ll be using a lot has to be friendly to this user: it should please me visually, and I want my most frequent commands to be easily executed from the keyboard. You can see why I do not yet have made my choice…

At this moment, I have no quarrel with TextMate on the Mac, but I’m not really pushing it either. On Windows, I am a staunch defender of Notepad++, which I use daily. Notepad++ is fast, knows HTML, XML, JavaScript and more, does macros, sorts lines, can handle read-only files, has a flexible search-and-replace: that’s almost all I need. I also appreciate its author, who is not afraid to publish a new version of his application just to express his opinion: the latest version, as we speak, is the “6.7.4 Je Suis Charlie” version. Well done, Don!


So why would I look beyond Notepad++? Well, for SharePoint developments Notepad++ comes in handy, for a quick check of HTML or JavaScript. But the rest of my code is mostly CFML (ColdFusion). The standard XML syntax colouring is a bit too simple, and that’s where my troubles start.  You see, there’s a nice plugin to support ColdFusion development in Notepad++ – but it is not entirely compatible with the latest versions of Notepad++. I used Brien Malone’s instructions to get the plugin installed in version 6.7.3. Unfortunately, from time to time the application complains about a missing plugin, and then I have to redo parts of the manual installation described by Brien. After a while, that is no longer funny and adventurous, just plain annoying.

Besides that: sometimes I need just a bit more from my text editor. I do not have a C-compiler at hand to create my own plugins, so I went looking for an alternative text editor. Like I said, the list of possible candidates is long, but in the end I decided to try out KomodoEdit and Editra. Not because they’re the absolute best, but because they work on XP and are installable without admin rights… Their programmability far exceeds Notepad++, and that has already paid off (I’m also learning a bit of Python this way, just on the side). I can use them on Windows – but there are versions for the Mac and Linux as well, which is handy if you dabble on all three platforms like me. But for the moment both of them stay as an assistant to Notepad++, and neither is going to become my main editor soon.

If you’re looking for a text editor, be prepared to spend a serious amount of time on your search – and make sure that you know what you need and what you don’t need.

PS. I think I have found a small but annoying bug in Notepad++. I had this little macro that included a “goto the end of the line” instruction. When repeated until the end of the file, however, the macro failed to do its intended work if and when the editor was in “word wrap” mode. I’m not sure it’s the same problem as described in bug report “#4526 Macro scrambles on EOL with word wrap“, but it seems to be related… Anyway, it’s a bug that easily avoided, so this won’t make me throw Notepad++ out the window ;-)

Read Full Post »

While installing the ColdFusion Builder app I obtained at the ColdFusion 11 Launch Party last week, I needed a Java runtime. I recalled installing a Java 8 runtime on my Macs (or at least on one of them) , but couldn’t find it on the Mac Mini I currently use for development. I really should document the maintenance and configuration of my machines… and why not start now, on an autumn afternoon in October?

For a long time, I have wanted to play around with Python (the programming language, not the snake), but I never found enough time to try my hand at real, serious Python programming. But today I thought: why not whip up an instance of my favorite bug tracker and use that for my documentation? Trac, to be explicit, is a Python application that does what I want (and lots more), and it can be installed in the cloud – and that last part is useful if I want to make certain that I can read my docs even when the machines at home go down.

So I created a free “Beginner” account at the PythonAnywhere site, and started playing around in an attempt to get Trac 1.0.1 running on that site. There are instructions to be found on the PythonAnywhere Forums for just that purpose, but I managed to get a first reasonable response in just five simple steps:

  1. From the PythonAnywhere dashboard of your ‘Beginner’,  start a ‘bash’ console;
  2. Run the ‘trac-admin /home/youruseraccountname/trac initenv’ command (substituting your account name for the ‘youruseraccountname’ part, of course) and giving your repository a name;
  3. Go to the ‘Web’ tab of your dashboard, and adapt the WSGI configuration file (just click on the link to this file, and you’ll be able to edit it in the browser). Comment out all the existing content or start from an empty file and add these lines:
    import os
    import sys
    import trac
    import trac.web.main
    os.environ['TRAC_ENV'] = '/home/youruseraccountname/trac'
    os.environ['PYTHON_EGG_CACHE'] = '/tmp'
    trac_app = trac.web.main.dispatch_request
  4. Reload your app with the big green button;
  5. Check out your app at your PythonAnywhere address ;-)
Your first Trac screen in the Cloud!

Your first Trac screen in the Cloud!

No, you’re not done yet: you still need to configure Trac to your linking – but that is not different from any normal Trac configuration action. I’m currently the only user for my PA instance, and I just need the Wiki and the ticket tracker, so I won’t be trying to add user management and access control to Trac. Nor will I be using source control for the time being. But all that is quite possible, if I’m to believe the experts…

Read Full Post »

A few days ago, Daniel Greenfeld wrote a blog post on the “Tools we used to write Two Scoops of Django“. Mentioning the words “tools” and “Django” in a single phrase is sure to get my attention, and the post did not disappoint. What fascinated me most, however, was not the “tools” part nor the “Django” part. The story is a good example to explain which difficulties show up in the process of creating and managing good content – even when it is “just” the writing of a book and its publication in multiple formats.

If you read the story, you will notice that

  • the authors started using familiar tools, like Python’s reStructuredText and Google Documents;
  • they then noticed that those tools did not measure up to their requirements, and had to switch again and again – until they ended up with LaTeX, allowing them to clearly structure the content and only then apply the formatting and layout for a paper version;
  • e-book formats are a world on their own, and it’s a complex world with many pitfalls;
  • technical content is never finished, so it requires forethought and planning to keep up with reality during the lifetime of your document.

All this about a relatively simple thing as a book, and by that I mean no disrespect to the authors. But assembling and maintaining say a website with hundreds of pages will be even harder, since such an endeavour add factors such as user management, target audiences, multiple authors, possibly multiple languages, categorization of pages, an editorial policy, and more – and that’s not mentioning a series of technical aspects. Enterprise content management ups the ante again, sometimes by several factors. So, yes, Content Management can be hard, very hard, to do right.

* * *

And what about the book, you ask? Well, if I’m ever going to do anything serious with Django I’ll need a copy of “Two Scoops of Django“. The sample chapter was a bit over my head, since I’m an absolute Django beginner, but the patterns and tips seemed logical and well explained. The writing is clear and sensible. The only thing I did not like is the fact that code samples are sometimes being split over two pages. That should not happen except when the code is longer than what fits on a single page, and even then I would prefer the code to be rewritten and packaged in smaller blocks. But all in all, this looks like a worthwhile book.

Read Full Post »

A month ago, I mentioned the appeal by the Python Software Foundation to help them defend the name “Python”. The good news is that both sides came to an amicable agreement: PO Box Hosting Limited (trading as Veber) will rebrand its services later under a yet to be determined name.

In the words of the Chairman of the PSF: “To Veber’s credit, they were willing to recognize the Python brand without protracted negotiations. We are grateful for Veber’s support and we wish them luck in their business“. I agree: it’s good to see that a dispute like this can be resolved amicably in just a few weeks, without having to go to court.

Read Full Post »

Older Posts »