This is a template for a Python C module. It is a simple example that shows how to create a Python module in C and C++.
- Python C/C++ module
- Python module tests
setup.py
for building and installing the modulepycmtemplate
command line script for running the module in anywherepycmtemplate
Python module for importing the moduleinit.sh
for initializing the projectclean.sh
for cleaning up the project
- Clone the repository
init.sh
to initialize the projectsource venv/bin/activate
to activate the virtual environmentpip install .
for installing the module orpip install -e .
for installing the module in editable modepython -m tests
to run the testspython -m pycmtemplate
or directly runpycmtemplate
to run the module from the command line
Required configurations are in the setup.py
file. The init.sh
script initializes the project by creating virtual environment and installing the required packages.
To build the module, run the following command:
python setup.py build
The build command will create a build
directory with the compiled module.
To install the module after building via setup.py
, run the following command:
python setup.py install
To build and install the module with pip
, run the following command:
pip install .
To install the module in editable mode, run the following command:
pip install -e .
Note: editable mode is useful for development purposes. It allows you to modify the source code and see the changes without reinstalling the module. However, it does not work with C/C++ modules.
After installing the module, you can run it from the command line:
python -m pycmtemplate
or directly:
pycmtemplate
To run the tests:
python -m tests
To clean up the project, run the following command:
./clean.sh
The clean.sh
script removes the build
, dist
, pycmtemplate.egg-info
and venv
directories, as well as the __pycache__
directories.