1

I am trying to create a directory upon a package installation. The function to create the directory, by itself, successfully creates it. Additionally, when I run "python3.7 setup.py install", the directory is created.

Why does this not work when using pip though? I don't see any errors. When I added print statements, I do not see them.

I have chosen to use setuptools' 'bdist_egg' function instead of the 'install' function for reasons found in here:

Running custom setuptools build during install

from sys import platform
from setuptools import setup
from os import mkdir, chmod, path
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg

class OverrideInstall(_bdist_egg):

    def run(self):
        _bdist_egg.run(self)

        # create log directory
        log = "/var/log/FOO"
        mode = 0o777
        if not path.exists(log):
            mkdir(log)
            chmod(log, mode)

setup(
    name='cox-nams',
    version='FOO',
    description='FOO',

    <-- output omitted for brevity / security>

    cmdclass={"bdist_egg": OverrideInstall},
)
user3746195
  • 346
  • 1
  • 16
  • 1
    "*Why does this not work when using pip?*" Because `pip` doesn't run `python setup.py install`. You cannot have a post-installation code with `pip`. – phd Sep 12 '19 at 22:48
  • 1
    Thanks for the reply. How is it recommended to perform these simple installation tasks? I guess the modules being installed could perform a check and install if they're not there. Is there anyway to do this within pip so that the install and actual code are kept separate? – user3746195 Sep 13 '19 at 15:20
  • "*the modules being installed could perform a check and install if they're not there*" Also wouldn't work because such programs seldom run under root and you need to be root to create a directory under `/var/log`. For system-wide installation you better create a real system package (RPM or DEB). For virtualenv you can do whatever you want but don't touch system directories. – phd Sep 13 '19 at 17:09
  • 1
    I was trying to mimic a package that is very similar to mine. In fact, I was cutting/pasting from it. https://github.com/Juniper/jsnapy/blob/master/setup.py . Do you know how they are able to do this and why it is different than what I am doing? There is also an 'install-ubuntu-debian' page they have which shows a 'pip install' as the instructions. – user3746195 Sep 13 '19 at 18:22
  • 1
    I don't think it does. I just ran `pip install jsnappy` under a non-root user — the package installed (into a virtualenv), but non of `/etc/jsnappy` or `/var/log/jsnappy` was created and no error was reported. – phd Sep 13 '19 at 20:22

1 Answers1

1

Apparently not supported with pip install.

user3746195
  • 346
  • 1
  • 16