What happens when you open source
Student Login

What happens when you open source

It was a surprising bug I never predicted.

Two years ago, I wrote and open-sourced a small tool, useful to data scientists. Doesn't matter what it is. But it's stable and doesn't need much maintenance.

I almost forgot about it. So I was surprised to get a bug report last week, where os.rename() failed.

You know about this function? It simply renames or moves a file, like /usr/bin/mv on something Unixy, or "rename" on something Windowsy. What my data-sciency tool does is create a file in a temporary directory (look up tempfile.mkdtemp()); assemble that file in steps; then atomically "publish" it by os.rename()'ing out of that temp directory, to the final destination.

Based on what I told you so far... can you spot the potential bug?

If you have enough experience with Linux or MacOS or Unix, you may have guessed: os.rename() doesn't always work if you are moving the file across a filesystem.

For example...

If Python creates the temporary directory on your machine's main drive, but the user wants the output file written to a thumb drive...

Boom. Bug report.

The solution was to use a higher-level function, shutil.move() - also in Python's standard library. This function detects the situation where the move-across-filesystem call fails, and falls back to copying the file instead (and deleting the original when done). Bug squashed.

In essence:

1) I didn't realize os.rename() had this problem.

2) I never encountered the bug on my own.

3) But one of my users did. And let me know.

4) And now I'm wiser. I know to use shutil.move() instead of os.rename() from now on.

None of this would have happened if I hadn't put my code out there in the first place.

And since my top-secret subversive goal is to create a revolutionary world-changing army of hundred-x-programmers - shhh, don't tell anyone - I'm wondering if you have an open-source project yourself. So you can benefit in the same way.

A lot of you have done this. A lot of you haven't. Either way, is there some program you wrote recently, which might be useful to someone else?

Upload that bad boy to github. You might have to invest some work generalizing it, so the program is useful to someone other than yourself. That's fine. More good practice.

And you'll have to *shudder* document it. That's okay, you can handle that.

The more of your code you open-source, the better it is for your growth as a developer.

So start open-sourcing.

Newsletter Bootcamp

Book Courses