Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Configuration file for EditorConfig
# More information is available under http://EditorConfig.org

# Ignore any other files further up in the file system
root = true

# Configuration for all files
[*]
# Enforce Unix style line endings (\n only)
end_of_line = lf
# Always end files with a blank line
insert_final_newline = true
# Force space characters for indentation
indent_style = space
# Always indent by 4 characters
indent_size = 4
# Remove whitespace characters at the end of line
trim_trailing_whitespace = true
86 changes: 86 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"editor.tabSize": 4,
"editor.detectIndentation": false,
// "debug.toolBarLocation": "docked",
"editor.suggestSelection": "first",
"editor.fontSize": 14,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.wordWrapColumn": 250,
"editor.columnSelection": false,
"editor.mouseWheelZoom": true,
"explorer.confirmDelete": false,
"editor.renderWhitespace": "all",
"editor.renderControlCharacters": true,
"editor.suggest.shareSuggestSelections": true,
"editor.renderIndentGuides": false,
"debug.console.fontSize": 14,
"git.autofetch": true,
"[json]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[jsonc]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"terminal.integrated.fontSize": 14,
"markdown.extension.toc.githubCompatibility": true,
"markdownlint.config": {
"MD033": false,
"MD034": false,
},
"markdown.extension.katex.macros": {},
"markdown.extension.toc.levels": "2..6",
"terminal.integrated.copyOnSelection": true,
// "files.autoSave": "afterDelay",
"files.insertFinalNewline": true,
"files.autoGuessEncoding": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.pyc": true
},
"python.analysis.extraPaths": [
"./src",
"./mock",
"./test",
"./venv2/bin",
"./venv2/Lib/python2.7/site-packages"
],
"python.analysis.logLevel": "Trace",
"python.analysis.watchSearchPaths": true,
"python.autoComplete.extraPaths": [
"./src",
"./mock",
"./test",
"./venv2/bin",
"./venv2/Lib/python2.7/site-packages",
// "./venv/bin",
// "./venv/Lib/python3.7/site-packages",
],
"python.pythonPath": "venv2/bin/python",
"python.formatting.provider": "yapf",
"python.languageServer": "Microsoft",
// "python.languageServer": "Pylance",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--max-line-length=250"],
"python.testing.unittestArgs": [
"-v",
"-s",
"./test",
"-p",
"test_*.py"
],
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.testing.cwd": "${workspaceFolder}",
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"workbench.iconTheme": "vscode-icons",
"workbench.editor.enablePreview": true,
"workbench.editor.enablePreviewFromQuickOpen": true,
"window.zoomLevel": 0,
}
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

# Python-DeMo

Python DeMo

- [一. 构建`venv`环境](#一-构建venv环境)
- [1.1 venv2](#11-venv2)
- [1.1.1 venv2 for mac](#111-venv2-for-mac)
- [1.1.2 venv2 for windows](#112-venv2-for-windows)
- [1.2 venv3](#12-venv3)
- [1.2.1 venv3 for mac](#121-venv3-for-mac)
- [1.2.2 venv3 for windows](#122-venv3-for-windows)
- [二. 多模块配置](#二-多模块配置)

## 一. 构建`venv`环境

### 1.1 venv2

#### 1.1.1 venv2 for mac

```bash
virtualenv -p /usr/local/bin/python2 --no-site-packages venv2
```

#### 1.1.2 venv2 for windows

```bash
python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2


python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2 > venv2.log
```

### 1.2 venv3

#### 1.2.1 venv3 for mac

```bash
virtualenv -p /usr/local/bin/python3 --no-site-packages venv
```

#### 1.2.2 venv3 for windows

```bash
python3 -m virtualenv -p C:\Python\Python38\python3.exe venv


python3 -m virtualenv -p C:\Python\Python38\python3.exe venv > venv.log
```

## 二. 多模块配置

具体步骤:

1. 在`venv2`和`venv` 下新建一个`python.pth`文件,具体目录为`venv2/lib/python2.x/site-packages/python.pth`和`venv/lib/python3.x/site-packages/python.pth`;
2. 在上述`python.pth`文件中写入多模块的`绝对路径`(自己设备上实际目录);

```python
# venv2 环境
# /Users/.../Python-DeMo/venv2/lib/python2.x/site-packages/python.pth
#
# venv 环境
# /Users/.../Python-DeMo/venv/lib/python3.x/site-packages/python.pth

/Users/.../Python-DeMo/src
/Users/.../Python-DeMo/test
/Users/.../Python-DeMo/mock
/Users/.../Python-DeMo/case
```
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions case/argparse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
File renamed without changes.
1 change: 1 addition & 0 deletions case/class/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions case/file/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
File renamed without changes.
1 change: 1 addition & 0 deletions case/function/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
123 changes: 123 additions & 0 deletions case/function/test_dict_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- coding:utf-8 -*-

import collections
import json
# import pprint

tags = {
'a': 2,
'v0.0.2': {
'stamp': 1576053555,
'date': '2019-12-11',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 22
},
'bc': '32',
'ac': {},
'v0.0.3': {
'stamp': 1576053555,
'date': '2019-12-21',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 23
},
'v0.0.1': {
'stamp': 1576053555,
'date': '2019-12-1',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 21
},
's': ['2020-01-09', '2020-01-10']
}


def test_dict_sort_slowly():
''' 使用sorted 会生成新的list,导致性能下降,建议使用内置sort '''
global tags
tags_tuple_list = sorted(tags.items())
# tags_tuple_list = sorted(tags.items(), key=lambda element: element[1])
print('\n')
print(tags_tuple_list)
tags.clear()
print("tags is %s" % tags)
for item in tags_tuple_list:
tags[item[0]] = item[1]
print("tags is %s" % tags)


def test_dict_sort():
global tags
# print(tags.items())
keys = tags.keys()
keys.sort()
# tuple_with_tags = [(key, tags[key]) for key in keys]
# print("%s\n%s" % (type(tuple_with_tags), tuple_with_tags))
tags_with_sort = collections.OrderedDict() # 有序字典
for key in keys:
# tags_with_sort.setdefault(key, tags[key])
tags_with_sort[key] = tags[key]
tags = tags_with_sort

# prettyPrinter = pprint.PrettyPrinter(indent=4)
# prettyPrinter.pprint(tags)

json_list = json.dumps(tags, indent=4)
print(json_list)

# print()
# print(tags)


def test_print():
'''
{
'v0.0.1':
{
'stamp': 1576053555,
'date': '2019-12-1',
'commits': 21,
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'authors':
{
'DovSnier': 3
}
},
'v0.0.2':
{
'stamp': 1576053555,
'date': '2019-12-11',
'commits': 22,
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'authors':
{
'DovSnier': 3
}
},
'v0.0.3':
{
'stamp': 1576053555,
'date': '2019-12-21',
'commits': 23,
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'authors':
{
'DovSnier': 3
}
}
}
'''
pass


if __name__ == "__main__":
'''主函数入口'''
test_dict_sort()
# test_dict_sort_slowly()
51 changes: 51 additions & 0 deletions case/function/test_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding:utf-8 -*-


def test_map():
tags = {
'v0.0.2': {
'stamp': 1576053555,
'date': '2019-12-11',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 22
},
'v0.0.3': {
'stamp': 1576053555,
'date': '2019-12-21',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 23
},
'v0.0.1': {
'stamp': 1576053555,
'date': '2019-12-1',
'authors': {
'DovSnier': 3
},
'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9',
'commits': 21
}
}
# lambda
list_o = map(lambda el: (el[1]['date'], el[0]), tags.items())

# function
# list_o = map(test_tuple, tags.items())

print list_o
tags_sorted_by_date_desc = map(lambda el: el[1], reversed(sorted(list_o)))
print tags_sorted_by_date_desc


def test_tuple(element):
return (element[1]['date'], element[0])


if __name__ == "__main__":
'''主函数入口'''
test_map()
Loading