Python Forum
Organization of project directories
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Organization of project directories
#1
Hi everyone! How do you organize your code? I like to separate everything into directories, preferably in the form of a monorepo. Custom libraries, services, etc. I then import everything using Poetry. An alternative is to keep either all scripts in one directory or in directories with the main script. I don't like this way of organizing, but unfortunately, my method (monorepo) causes a significant increase in memory usage. Each library and service has its own virtual environment, and many dependencies are repeated. Isn't there a better way?
Reply
#2
I fail to see why one method requires a virtual environment for each library/service, but the other does not. Can you explain why you think this is the case? Maybe you are wrong.

I don't think monorepo is a good way to organize code. I find them difficult to work with. But I don't see why a monorepo would not work for Python or why it would be any more inefficient than monorepos normally are.
Reply
#3
I think we might have misunderstood each other. I'm not saying that other approaches don't require a virtual environment or that they can't be used. I'm also not claiming that a monorepo doesn't work well for Python or that it's more or less efficient.

I'm simply asserting that if I use a monorepo and import my own libraries into other projects/services, I have dependencies redundancy.

Alternatively, I could create a simple directory structure like my_project/modules and my_project/main.py or app.py and import my modules in the app. But if I do it this way, and I have several independent sub-projects/services, each utilizing a script (with the same content) in modules, then I have code redundancy. I need to place the same code in each modules directory.

I hope this explanation is clear.

And one more thing - I assume upfront that I'm omitting something obvious. Blindsight ;p That's why I'm writing this here.
Reply
#4
FYI: I never start a bona fide project without first creating a virtual environment.

One of the main reasons is that each project can have it's own version of python.
There are many other benefits, such as keeping packages localized, and requirements to a minimum.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Listing directories (as a text file) kiwi99 1 847 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Virtual Environments - Organization (VS Code) JaysonWonder 11 1,869 Jan-26-2023, 11:34 PM
Last Post: Larz60+
  Find duplicate files in multiple directories Pavel_47 9 3,146 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  rename same file names in different directories elnk 0 719 Nov-04-2022, 05:23 PM
Last Post: elnk
  I need to copy all the directories that do not match the pattern tester_V 7 2,448 Feb-04-2022, 06:26 PM
Last Post: tester_V
  Functions to consider for file renaming and moving around directories cubangt 2 1,770 Jan-07-2022, 02:16 PM
Last Post: cubangt
  Python create directories within directories mcesmcsc 2 2,226 Dec-17-2019, 12:32 PM
Last Post: mcesmcsc
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,568 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  Accessing files in various directories and folders ccuny 2 2,180 May-08-2019, 12:11 PM
Last Post: ccuny
  Opening Directories on anothe File System mickrobinson567812 2 2,410 Apr-25-2019, 04:59 AM
Last Post: mickrobinson567812

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020