2

I'm refactoring the directory structure of a large Python repo that has a few dozen C and C++ files littered throughout. Is there a suggested architecture for a Python package that contains C/C++ code within it? What I have at the moment for my repo foo is:

foo/
├── LICENSE
├── Makefile
├── README.md
├── docs/
├── examples/
├── foo/
│   ├── __init__.py
│   ├── README.md
│   ├── core/
│   │   ├── __init__.py
│   │   ├── foo_tricks_slow.py
│   │   ├── foo_tricks_fast.cpp
│   │   └── foo_tricks_fast.mk
│   ├── experiments/
│   └── utils/
├── requirements.txt
├── setup.py
└── tests/  # Run with py.test
    ├── __init__.py
    └── test_foo.py

Each subdir core/, experiments/, utils/, and so on contains mostly python files, and some C/C++ files.

Some things I've heard mixed opinions on that I'd like to reach a conclusion on include

  1. Putting tests outside the Python package
  2. Putting source in a src/ dir
  3. Keeping a directory for Python and a directory for C/C++

Some sources of info I've looked at include:

A. Filesystem structure of a Python project by Jean-Paul Calderone

B. cookiecutter

C. Jeff Knupp's blog post

D. This SO question is close, but I don't have a self-contained C++ project, but rather some misc. files, each with their own mk file that gets accumulated when running the main Makefile.

E. Example repositories like Tensorflow, Keras, Nupic, Django

Related: I would like the repo to be installed and built with pip install foo. I'm unsure how this would also build the C/C++ files though. For example, pip install tensorflow accomplishes this. Perhaps that's for a followup SO question though.

  • 2
    Your folder structure does not constitute a software architecture. – Robert Harvey Jul 26 '17 at 23:44
  • TensorFlow installs precompiled libraries. If you install it from sources, you need more steps than just pip install tensorflow – mouviciel Jul 27 '17 at 9:35
  • Would you explain more @RobertHarvey? Or if you're just arguing semantics, would you prefer "repo structure"? – BoltzmannBrain Jul 27 '17 at 15:59
  • 1
    "Folder structure" or "directory structure." – Robert Harvey Jul 27 '17 at 17:52

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.