1

I'm making python application for linux os. And I'm wondering how can I make my package that will create config folders/files on executing: pip install my-package. On https://pip.pypa.io I didn't find if this is considered a bad practice, since my app is part package/app, probably the best way would to make dpkg package, but out of curiosity I want to know how can one achive this.

1 Answer 1

1

Your typical setup.py file would be structured like so:

from setuptools import setup import sys setup(name = "package_name" ..... 

After the setup call you can use os.mkdir or anything else that you want to do.

Your final code would look something like this:

from setuptools import setup import sys import os setup(name = "package_name" ..... os.mkdir('test_path') 

What pip typically does is run python setup.py install. When the setup file is run, the os.mkdir will get run and hence your directory will be created.

Sign up to request clarification or add additional context in comments.

3 Comments

But what if setup.py is corupted? I don't want to mess users system before i'm not really 100% that package is installed on system properly.
Place the os.mkdir after the setup. In this case, if there are errors, it will not create the directory. Edited the answer to reflect that.
Hm... must to test this, I'm kinda suspicious obout this, but thanx for your input :)