Skip to content

Simple example that shows how to create a Python module in C and C++.

Notifications You must be signed in to change notification settings

EtkinD/PythonCModuleTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python C Module Template

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++.

Features

  • Python C/C++ module
  • Python module tests
  • setup.py for building and installing the module
  • pycmtemplate command line script for running the module in anywhere
  • pycmtemplate Python module for importing the module
  • init.sh for initializing the project
  • clean.sh for cleaning up the project

How to use

  1. Clone the repository
  2. init.sh to initialize the project
  3. source venv/bin/activate to activate the virtual environment
  4. pip install . for installing the module or pip install -e . for installing the module in editable mode
  5. python -m tests to run the tests
  6. python -m pycmtemplate or directly run pycmtemplate to run the module from the command line

How to build with setup.py

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.

Install after build

To install the module after building via setup.py, run the following command:

python setup.py install

How to build and install with pip

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.

How to run the module

After installing the module, you can run it from the command line:

python -m pycmtemplate

or directly:

pycmtemplate

How to run the tests

To run the tests:

python -m tests

How to clean up

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.

About

Simple example that shows how to create a Python module in C and C++.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published