GithubHelp home page GithubHelp logo

zbailey83 / init_python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ninefrm/init_python

0.0 0.0 0.0 8 KB

Init python projects, feel free to suggest improvements

Shell 43.38% PowerShell 56.62%

init_python's Introduction

Initializing a project in Python

These are the steps I normally follow to start a python project, I do it more as a reminder to myself.

Prerequisites

  1. Installation Pyenv & virtualenv:

    brew update
    brew install pyenv

    Windows || Powershell

    Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"

Init project

Having the folder/repository created

  1. Set Python version, open your Terminal and execute the following commands:

    MacOS / Linux

    pyenv versions # Installed versions
        pyenv install -l #List python version list
        pyenv install <version> # Install your version if needed
    pyenv local <version> # Set the version needed
    python -m pip install –user virtualenv # Install virtualenv
    # Create a new virtual environment (replace 'env' with your desired environment name)
    python -m venv env
    # Activate the virtual environment
    source env/bin/activate

    Windows

    pyenv versions # Installed versions
        pyenv install -l #List python version list
        pyenv install <version> # Install your version if needed
    pyenv local <version> # Set the version needed
    python -m pip install –user virtualenv # Install virtualenv
    # Create a new virtual environment (replace 'env' with your desired environment name)
    python -m venv env
    # Activate the virtual environment
    .\env\Scripts\activate 
  2. Init required folders:

    MacOS / Linux

    mkdir -p config source test utils && touch main.py requirements.txt config/__init__.py source/__init__.py test/__init__.py utils/__init__.py

    Windows || Powershell

    New-Item -ItemType File -Path main.py -Force; New-Item -ItemType File -Path requirements.txt -Force; New-Item -ItemType File -Path .\config\__init__.py -Force; New-Item -ItemType File -Path .\source\__init__.py -Force; New-Item -ItemType File -Path .\test\__init__.py -Force; New-Item -ItemType File -Path .\utils\__init__.py -Force
  3. How I work with the folders:

    1. config: This directory is often used to store configuration files. These might include settings for different environments (like development, staging, and production), constants used throughout your application, or configuration for external services. A common way to structure this is to have Python files such as dev.py, prod.py, staging.py etc. which are loaded based on the current environment. Each file could contain settings relevant to that environment.

    2. source: This directory, often also named src, contains the main source code for your application. This could include different modules, packages, or standalone scripts, depending on the size and complexity of your application. In larger projects, the source directory often contains subdirectories corresponding to different parts of your application. For example, if you were building a web application, you might have subdirectories for routes, models, controllers, etc.

    3. test: As you might expect, this directory is used to contain tests. These could be unit tests, integration tests, or others. A common structure is to have a mirror of your source directory, but with each file replaced by a corresponding test file. So if you had a file source/routes/user.py, you might have a corresponding test file test/routes/test_user.py. This makes it easy to find the tests for a given piece of functionality.

    4. utils: This directory is usually used for utility scripts or modules that are used across your application. For example, you might have a utils.py file with common helper functions, or a logging.py file to set up logging consistently across your application.

  4. Scripts

    MacOS / Linux

    chmod 700 py_init.sh
    pyenv install -l #List python version list
    py_init.sh unix <version>

    Windows || Powershell

    pyenv install -l #List python version list
    py_init.ps1 win <version>

init_python's People

Contributors

ninefrm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.