Skip to content
This repository was archived by the owner on Jul 25, 2020. It is now read-only.

Wabri/TemplateRepositoryPython

Repository files navigation

TemplateRepository_Python

A template for python project across multiple purpose

Tree structure of project

.
├── 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

How to set up your project

Clone it

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

Install.sh

Is 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.git

Then move inside the repository:

cd TemplateProject_python

And 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.git

A 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

Use the source script to create the environment

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

Run alias

The run alias have multiple purpose:

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

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

Requirement alias

The requirement alias works as pip but also update the right requirements.txt:

  1. Install package

    requirement --install NAME

    Where NAME is the name of the package you need to install.

  2. 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'

Use on ide

PyCharm

To use the run.sh script follow this steps:

  1. Select the Run options
  2. Edit configuration...
  3. Add New Configuration
  4. In the Script path just select the run.sh script inside the development/tools directory
  5. Followed by --package NAME_PACKAGE
  6. If the run.py of the package need more arguments just put before the package argument
  7. Give a useful name for this run configuration
  8. Done

Contributions

Every contributions are apprecieted, just create issues or fork and pull requests.

About

A template for python project across multiple purpose

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published