Skip to content

msakamoto-sf/pythonsnack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pythonsnack

Python demonstration, exercise, practice, study, example codes.

require : Python 3.8

using:

  • unittest discover : 3.2
  • pip as default : 3.6
  • dataclasses : 3.7,
  • functools.singledispatchmethod : 3.8

setup venv and install pip requirements:

## create venv
cd (repository root directory)
python -m venv .venv

## activate venv
(linux-bash)
source .venv/bin/activate

(win-cmd)
.venv\Scripts\activate.bat 

(other-shell, platform, see https://docs.python.org/ja/3/library/venv.html )

## update pip in venv
python -m pip install --upgrade pip

## install pip requirements
python -m pip install -r requirements.txt

run from command line:

cd (repository root directory)
(activate venv)

## run unittest:
python -m unittest discover

## run flake8:
flake8 snacks tests

## run mypy:
mypy snacks tests

## run black (dry-run)
black --diff snacks tests

## run black (write-back to files)
black snacks tests

vscode integration

before opening vscode, you MUST have done creating venv and pip install -r requirements

after opening vscode (first-time only):

  1. select "Python: Select Interpreter" command from the Command Palette (Ctrl+Shift+P)
  2. choose "Python 3.x.y ... .venv" (.venv python)
    • NOTE: vscode automatically generate .vscode/settings.json at this time.
  3. add below settings to .vscode/settings.json
{
    "python.venvPath": ".venv",
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.mypyEnabled": true,
    "python.formatting.provider": "black",
    "editor.formatOnSave": true,
    "python.linting.lintOnSave": true,

    "python.pythonPath": "(path inserted by vscode)"
}
  • Why are you put .vscode/settings.json to git repository ?
    • Because venv's python.pythonPath is different between some platoforms. for Win, Scripts\\python.exe <> but linux/macos, bin/python.
    • I gave up putting these cross-platform behabiours to one-single-common settings.json X(

refs:

reference

venv and pip

pip コマンドのヘルプ: python -m pip help

pip install したら pip freeze 結果を requirements.txt に保存する。そうすれば pip install -r requirements.txt で同じパッケージをインストールできる:

linter, checker, formatter

unittest

write test code

coding rule

About

Python demonstration, exercise, practice, study, example codes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages