Re: [Distutils] Fwd: setup('postinstall'='my.py')
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 process. 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 it. Your answers are great for me; *now* I understand all this much better. Thanks! > consider adding some code to the installer itself Wouldn't it be great if setuptools.setup provided that option, and OS-independent? > 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 - thanks. Might be a good sentence to be placed in a box in a central place in the manual. > 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! :-)
On 5 February 2016 at 16:39, AltSheets Dev <altsheets+mailinglists@gmail.com> wrote:
Would it be a valid feature request to make those two useful options (pre-install-script/install-script) available platform-independent?
It's something that has been discussed under the "Metadata 2.0" banner. It's certainly a valid request - but addressing the various concerns and issues that come up is complex, and (AFAIK) no-one has really come up with a satisfactory solution yet. [...]
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?
The "appdirs" project (https://pypi.python.org/pypi/appdirs) is one I've seen used/recommended a lot. Paul
On Fri, Feb 5, 2016 at 8:39 AM, AltSheets Dev < altsheets+mailinglists@gmail.com> wrote:
consider adding some code to the installer itself Wouldn't it be great if setuptools.setup provided that option, and OS-independent?
well, no. setuptools is a bit of an (ugly?) amalgamation of build tool, install tool, etc... we are trying to clean that up, so that setuptools is a built tool, and pip is the install tool (and each can be replaced by other options for your use-case). so it would be pip that would need a post-install-hook. Thought that's tricky too -- where would you put that code, with binary wheels, or ??? You might look at the conda package manager -- I"m pretty sure it has a post-install hook. https://github.com/conda/conda 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?
yup. :-( -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (3)
-
AltSheets Dev
-
Chris Barker
-
Paul Moore