I have an application that is currently in the following folder structure:
myapp/
client/
core/
server/
template_files/
It has a server side and a client side component and when I deploy the code to a user, I don't want to include the server side code as well. Both client
and server
need the core
code to run.
Reading about general Python project structure, I realise I should start by changing my structure to:
myapp/
myapp/
client/
core/
server/
template_files/ (template is only needed by the server)
bin/
setup.py
What's the best way to structure my directories and do code deployment?
You might want to have three separate packages instead of one, even your second structure will result in a package (python egg) that contains all the sub-modules which will result in the server code being packaged with the client code.
What you want is to split them up into three individual packages (i.e. myapp.client
, myapp.core
and myapp.server
) and they will have separated directory structures, so in effect you would have something like
myapp.client/
myapp/
client/
setup.py
myapp.core/
myapp/
core/
setup.py
myapp.server/
myapp/
server/
template_files/
setup.py
As they will all become proper python packages, you can define dependencies in the setup.py
for myapp.client
and myapp.server
to require myapp.core
, so if/when you deploy the packages onto pypi (or others) your users can simply do pip install myapp.client
to get the client library installed onto their system with all dependencies fetched.
You don't necessarily have to have a bin
in anywhere. You can take advantage of the entry_points
attribute in the setup
function to let setuptools create the "binary" for you in an OS agnostic manner. Just define the main function(s) inside your library and let setuptools create the executable for you for your users.
Lastly, you might want to take a look at what other open source projects have done for packaging their libraries, here are some examples:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With