Package: pymodulegen
pymodulegenTable of ContentsInstallationUsageContributingLicenseAcknowledgementsContactExamples and ScreenshotsDescriptionpymodulegen is a project aimed to generate python modules and packages, and add root directory of the project in sys path to allow importing parent modules in child using absolute paths relative to root directory.Issue ResolutionThis section outlines the types of issues and problems that our package,pymodulegen, is designed to address. If you encounter any of the following scenarios, our package can be a valuable solution:Problem 1: Importing modules from parent packagesSince Python 3.3, referencing or importing a module in the parent directory is not allowed. Hence, we must handle it manually.
For example, in a folder structure like the one below,.
    ├── directory_tree.txt
    └── src
        ├── main.py
        └── api
            ├── __init__.py
            └── common
                ├── load_environment.py
                ├── __init__.py
            └── v1
                ├── __init__.py
                └── endpoints
                    ├── chat.py
                    ├── __init__.pyIf you wish to import 'load_environment' into 'chat.py', you will get the following error:chat.py:from src.api.common import load_environmentError:File "your-machine-path\project-root\src\api\v1\endpoints\chat.py", line 1, in <module>
    from src.api.common import load_environment
ModuleNotFoundError: No module named 'src'Problem 2: Creating folder structures, packages and modules for a python projectCurrently, in Python development, we have to either manually create files and folders (along withinit.py files) or use a third-party template provider like Cookiecutter, FastAPI Project Generator,Django-style CLI, etc. However, if you want to generate packages as per your liking in a custom fashion, it can only be done manually for the time being.How Our Package HelpsWhen we setup the folder structures using our package, it includes codes in theinit.py file (or in the module itself, depending on the user preference), which will allow us to do imports using absolute paths (not relative paths, like the usage of '.','..') even from parent packages.
Also, it is pretty easy to setup folder structures using our command-line tool rather than doing it manually.InstallationUsing pippipinstallpymodulegenClone from sourcegitclonehttps://github.com/YashNarK/pymodulegen.gitUsageTo generate a module or package and set root directory, use the following command:pymodulegenmodule_name[--options]Options:module_name: The name of the module to generate.--directory: (Optional) The directory where the module should be created.--root_directory: (Optional) The root directory for sys.path.--is_module_only: (Optional) Specify if the module should be used as a module only.--not_is_module_only: (Optional) Specify if the module should be used as a main program as wellContributingContributions are welcome! Please follow these guidelines:Create an issue to discuss major changes or enhancements.Fork the repository and create a new branch for your contribution.Submit a pull request with a clear description of your changes.Follow coding standards and maintain code quality.LicenseThis project is licensed under theMIT License.AcknowledgmentsI would like to acknowledge the following resources that were helpful during the development of this project:GeeksforGeeks - Python Import from Parent Directory: This tutorial provided valuable insights into importing modules from parent directories in Python. It was a useful reference while working on this project.ContactEmail:narenkrithick@gmail.comGitHub:YashNarKExamples and ScreenshotsExample 1Generate a module named "mymodule" in the current directory (default settings).Example 2Generate a module named "chatgpt" in the "app/api/v1/endpoints" directory with root directory "project-root" and use it as a main program as well.Example 3Generate a package (withinit.py) named "my_package" in the current directory (default settings) with a module my_module.