Menu

How to prevent PyDev from deleting pyc files?

2009-02-09
2013-03-15
  • Volodya Orlenko

    Volodya Orlenko - 2009-02-09

    Hi,

    I am using PyDev Extensions, and generally I'm very happy with it.

    There's only one thing that drives me crazy. When I refresh a folder, Pydev deletes *.pyc and *.pyo files. In most cases this is desirable, of course. But there are situations when I want to keep *.pyc files, for example, when I keep a copy of compiled third-party libraries in my repository. Unfortunately, PyDev seems to absolutely insist on deleting them on every refresh. Is there a way to say to PyDev, "do not delete compiled Python modules from this directory"?

    Thanks!

     
    • Salim Fadhley

      Salim Fadhley - 2009-02-09

      Might I suggest that you look into distutils, it's a better way for dealing with 3rd party libraries. You can use distutils to make ".egg" files which are a widely used standard for containing compiled 3rd party python libraries.

      Most people would argue that it's an improper use of a source-control system to use it to keep track of binary objects such as pyc files. Perhaps if you explain a little bit more about why you have decided to go down this route we can think up a better way of doing what you want to do which works better with Python's conventions.

      For example, my own project relies on a number of 3rd party modules: I do not want to version them in my own source control system - simply keep track of which versions my project requires. When my project is installed I can ensure that those dependencies are installed - and that would preferably be the automatically installed egg files.

      On the occasion when egg files cannot be installed automatically (e.g. because they are not easily available), I run my own egg-repository which is nothing more than a folder on a web-server. It's really that easy... and I do not have to clog up my svn-server with a bunch of binary that cannot be versioned or diffed.

       
      • liturgist

        liturgist - 2009-02-16

        If you must deliver only a single .exe file, how about wrapping the egg with a tiny C/C++/VB/etc. program that simply writes the egg out and uses distutils?

         
    • Volodya Orlenko

      Volodya Orlenko - 2009-02-14

      Thanks Salim,

      You are right, using distutils, eggs, and specifying dependencies and versions is the standard, preferred way of handling things. Unfortunately, I am dealing with a non-standard situation: the product I am working on is packaged as a single-exe Windows service that requires a single-click installer. Py2exe does not understand eggs, and so I have to maintain a slightly customized, "un-egged" version of 3rd-party libraries my product depends on.

      Although the situation I am in is non-standard, I doubt I am the only person in the world who needs to keep some *.pyc files in the source tree. What would it take to add an option to avoid deleting *.pyc files from a specific directory? After all, PyDev has an option to skip code analysis for specific files, why not allow skipping directory cleanup where it's not needed?

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2009-02-16

        Ok, I was thinking a bit about it, and I think that the way to handle that is adding it somewhere outside of the pydev project and just reference it as an external source folder.

        For that, you can either create a separate project to be added to the svn only with those files and don't mark it as a Pydev project, and in the project you're referencing, add it as an external source folder or simply add it to your site-packages (and add that to svn).

        The point is, it should be treated as something totally external to Pydev, as it's not really source code and not meant to be edited and managed internally by Pydev (anything in your project pythonpath is treated as if it was part of something you're developing, not something external -- and when you're developing, I don't think you ever want to keep your .pyc files floating around unless you actually have its source -- that can lead to some subtle and unexpected bugs)

        Cheers,

        Fabio

         
  • Anonymous

    Anonymous - 2011-08-08

    Hi All,

    I have the same issue.. Is a option to turn off it?
    In my case is:
    I want to deploy a test version to user and not provide the source code, the test version will be changed very frequently. And user use the source control to get the latest version, they know about the svn, but not has any idea of Python.
    So, I don't want to package the scripts to egg file, the pyc files are the best solution, it's easy to get and easy version control.

    Thanks,
    Simon He

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-08-11

    Ok, just added more options to PyDev on how to handle .pyc files (under preferences > pydev > builders).

    In your case, leave 'Only delete .pyc when .py delete is detected.' selected.

    Please grab the latest nightly build (just published) and test to see if it works for you (will be available on a final in 2.2.2).

    Cheers,

    Fabio