A template for python project across multiple purpose
.
├── CHANGELOG.md
├── datas
│ └── helloworld.csv
├── LICENSE
├── packages
│ └── helloworld
│ ├── hello
│ │ ├── __init__.py
│ │ └── output.py
│ ├── requirements.txt
│ ├── run.py
│ └── world
│ ├── __init__.py
│ └── string.py
├── README.md
├── requirements.txt
├── resources
├── scripts
│ └── development
│ ├── README.md
│ ├── source.sh
│ └── tools
│ ├── run.sh
│ └── pip-update-requirements.sh
└── VERSION
9 directories, 16 files
To use this template you need to clone it with a new name and remove the .git directory:
git clone https://github.com/Wabri/TemplateRepository_Python.git <your_name>
cd <your_name>
rm -rf .gitIs also possible to use the install.sh scripts and reuse this template multiple times. The first thing is to clone the project:
git clone https://github.com/Wabri/TemplateProject_python.gitThen move inside the repository:
cd TemplateProject_pythonAnd run the install.sh with arguments or none:
./install.sh --directory path_to_workspace \
--name project_name \
--repository https://github.com/github_name/repository_name.gitA simple example could be:
./install.sh --directory ~/workspace/ \
--name my_awesome_new_project \
--repository https://github.com/wabri/AwesomePythonProject.git
With output:
-----> ./install.sh script start
-----> Creation of the project directory
The directory of the project is: /home/wabri/workspace/
-----> Coping files and directories
The name of the project is: my_awesome_new_project
-----> Removing useless files and directories
-----> Setting up the git repository
The remote git repository is: https://github.com/wabri/AwesomePythonProject.git
There is inside the scripts a directory called development where can be found a source.sh that can be use to create environment and define some useful alias. The usage is simple:
Usage: source ./scripts/development/source.sh [OPTION]'
Mandatory arguments to long options are mandatory for short options too.'
-h, --help Print help page
-c, --cache Use virtualenv if exists
-q, --quiet Quiet mode with no output'
-n, --name NAME Specify the name of virtual environment'
-p, --package NAME Specify the name of the package'
This source scripts manage to install all the dependencies for the project and also create the alias:
- run
- requirement
A simple example could be:
source scripts/development/source.sh
With output:
-----> Install python3 venv and pip dependencies
[...]
-----> Deactivate precedent environment
There are not any environment activated
-----> Setting up virtual environment
Create environment with name /home/wabri/workspace/my_awesome_new_project/venv
-----> Activate Environment
The python environment is in path /home/wabri/workspace/my_awesome_new_project/venv/bin/python
The pip environment is in path /home/wabri/workspace/my_awesome_new_project/venv/bin/pip
-----> Upgrade pip
[...]
-----> Install requirements of project
-----> Create aliases
The run alias have multiple purpose:
-
If the package name was given in argument for the source file, then:
run [ARGUMENTS]
Where ARGUMENTS are the arguments of the run.py file of the package given.
-
If the package was not given in argument for the source file, then:
run PACAKGE_NAME [ARGUMENTS]
Where:
- PACKAGE_NAME is the name of the package to run
- ARGUMENTS are the arguments of the run.py file of the package given
This is the help page:
Usage: ./run.sh [OPTION]'
Mandatory arguments to long options are mandatory for short options too.'
-h, --help Print help page'
-p, --package PATH Specify the path to the package'
-m, --main PATH Specify the path to the main file'
The run.sh script try to find inside the packages directory for the package name passed, if exists it execute the run.py inside of that directory.
A simple example could be:
With output:
For more infos check out the bash code of run.sh script.
The requirement alias works as pip but also update the right requirements.txt:
-
Install package
requirement --install NAME
Where NAME is the name of the package you need to install.
-
Uninstall package
requirement --uninstall NAME
Where NAME is the name of the package you need to remove.
This is the help page:
Usage: ./pip-update-requirements.sh [OPTION]'
Mandatory arguments to long options are mandatory for short options too.'
-h, --help \t\t\t Print help page'
-r, --requirements NAME\t Specify the path to the requirements file'
-u, --uninstall NAME\t\t Specify the package to remove'
-i, --install NAME\t\t Specify the package to install'
To use the run.sh script follow this steps:
- Select the Run options
- Edit configuration...
- Add New Configuration
- In the Script path just select the run.sh script inside the development/tools directory
- Followed by
--package NAME_PACKAGE - If the run.py of the package need more arguments just put before the package argument
- Give a useful name for this run configuration
- Done
Every contributions are apprecieted, just create issues or fork and pull requests.