[Distutils] Fwd: setup('postinstall'='my.py')

AltSheets Dev altsheets+mailinglists at gmail.com
Fri Feb 5 11:39:24 EST 2016

Thank you Robert, Leonardo, Jeremy, Paul, Greg!

> One very simple technique used by some projects like
> numpy is just to have ``setup.py`` write a file into the
> source tree before calling setup(). example:
> https://github.com/numpy/numpy/blob/master/setup.py#L338-L339

Done that now. But:

> The thing about setup.py is that it only runs at "build time".
Yes, ouch. So ... not the way to go, in this case.

Still good to know, useful for static but often updated version info, etc.

> However, it looks like you want to generate a unique id at every install.
Correct. The idea is to let me discover a possible abuse of serial keys
- if a serial key appears together with many UUIDs, I can revoke it.
(Not a protection against experts of course, but might still help.).

My older frontend, a GoogleSheet (see altfolio.ddns.net) always
automatically generates a UUID, in the moment when the user
makes a copy of my mastersheet. That had inspired me now.

Another goal of my questions on this list ... is learning about the whole

I have been coding in Python for over a decade,
but scientifically, sharing source code with other coders;
or on a webserver - but I had never needed to
make my code directly available to end users.
I had always been wondering about packages & installers - now I am learning

Your answers are great for me; *now* I understand all this much better.

> consider adding some code to the installer itself
Wouldn't it be great if setuptools.setup provided that option, and

> It appears that you are using bdist_wininst to create the installer.
> So you are in luck!  The bdist_wininst command supports running
> simple scripts at a few points in the installation process. [...]
> To use an installer script, you need to pass options to the
> bdist_wininst command.  '--pre-install-script=<pathname>' for the
> pre-install script, where 'pathname' is the path to the script to
> include (relative to setup.py or fully-qualified).
> '--install-script=<scriptname>' for the post-install/pre-uninstall script

Great. That sounds as if it is perhaps the way to go then, thanks a lot.

Sounds as if it can do exactly what I need.

However then ... aren't I stuck with a windows-only solution?

Would it be a valid feature request to make those two useful options
(pre-install-script/install-script)  available platform-independent?

> Here is (an untested) set of additions that should achieve
> what you are asking for. [...] Hope this helps!
Yes, fantastic. Very nice. Thanks a lot. Makes it 100% clear now.

> > Does that mean that setup.py is then also not run during deployment
> No. By the time a wheel is generated (or an egg, or any other bdist_*
> command is run) the job of the setup.py for your package is done.

That was the essential sentence that made "click" in my understanding -
Might be a good sentence to be placed in a box in a central place in the

> I would consider the following strategies:
> Create the UUID on first run (e.g. at import time)
> Add a script (or function) for creating the UUID and document for your
> users that it needs to be called before using your library

> Have you thought of maybe not relying on the UID being generated at
> "install" time, but rather having a "coinq init" command that the user
> runs *once* to set up his/her UID? The other commands could then
> check for that UID wherever you choose to store it, and if they don't
> find it [...] automatically run init if they find no UID.

Yes. I know, that is the other way to go.

But then I need to understand where I am allowed to write persistent files
- outside the place where the other .py files are installed anyways.
And as that UUID.py has to be created only once in the lifetime of
my tool on their computers, I had thought the /site-packages/... folder
is the best place for it.   But perhaps it is really not.

Do you know a Python package that abstracts from the platform ... with which

I can write to (would those be the right places?)

   (username/AppData/Roaming/myfolder) on Windows, and
   (~/.myfolder) on Linux - and is it
   (~/Library/myfolder) on Mac?

Thanks a lot!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20160205/04ee7e77/attachment.html>

More information about the Distutils-SIG mailing list