semvec/pypi-packages huggingface dataset:
pypinonevirgin 0.0.2
Build my first PyPI package
License: MIT
Requires Python: >=3.7.3
Keywords: build your pypi

# pypi
Build My first PyPI package
PyPI : the Python Package Index

###### tags: `Python` `PyPI`

## Steps-by-Steps
1. 準備好要上傳 PyPI 的套件
    > :memo: 
    > 1. 資料夾結構
    > ![steps_0.png](https://i.imgur.com/fUDgUGv.png)


2. 進入該層目錄 : `cd C:\Users\chichun.chen\Desktop\git\pypi`

3. 打包檢查 : `python setup.py check`

4. 打包 : `python setup.py sdist`
    > :memo: 
    > 1. **sdist** : 較常用，支持 **pip** 安裝
    > 2. bdist_egg : 支持 easy_install 安装
    > 3. 打包好的檔案會在 `/dist` 底下
    > ![steps_1.png](https://i.imgur.com/InQ2tEs.png)
    > 
    > 4. 使用 `pip install pypinonevirgin-0.0.1.tar.gz` 測試打包完的檔案是否能正確執行

5. 安裝 **twine** 作為後續上傳 PyPI 用 : `pip install twine`

6. 註冊 [PyPI](https://pypi.org/)

7. 上傳 : `twine upload dist/*`
    > :memo: 
    > 1. 需註冊 PyPI 帳號密碼
    > ![steps_2.png](https://i.imgur.com/xSqHkps.png)

## FAQ
* Register Fail:
    * **Command** : `python setup.py register`
    * **ErrorMsg** : Server response (410): Project pre-registration is no longer required or supported, upload your files instead.
    * **Explain** : PyPI 因為 HTTP 安全性認證的問題，不再支援 register、upload 等指令
    * **Solution** : 改用 `twine upload` (官方建議)

* Upload Fail : 
    * **Command** : `twine upload dist/*`
    * **ErrorMsg** : HTTPError: 400 Bad Request: This filename has already been used, use a different version.
    * **Explain** : PyPI 上已經存在相同名稱的套件/版號
    * **Solution** : 更改套件名稱 or 調整版號

* console_scripts : 
    > :memo: 
    > 1. Build python scripts automatically
    > ![steps_3.png](https://i.imgur.com/hICMmdU.png)



## Windows 打印資料夾結構的小工具
```powershell=
tree <yourPath> /f | Select-Object -Skip 2 | ForEach-Object {
	if ($_.Contains(':\')) {
		Write-Host $_ -ForegroundColor Cyan
	}
	elseif ($_.Contains('─')) {
		Write-Host "$($_.Replace('─', '─<'))>" -ForegroundColor Yellow
	}
	else{
		Write-Host $_ -ForegroundColor White
	}
}

```

## Reference
* [PyPI Official](https://pypi.org/)
* [PyPI 教學](https://zhuanlan.zhihu.com/p/26159930)
* [PyPI 教學](https://www.cnblogs.com/jaysonteng/p/15221886.html)
* [輸出資料夾結構](https://blog.darkthread.net/blog/dump-folder-tree/)
fake-read-write-files 0.10
Write/read from memory instead of files when open() is called
License: MIT
Keywords: read,write,memory,open,faster


# Write/read from memory instead of files when open() is called 

## @read_decorator fakes the existence of a file and provides the file content when open(mode='r'/mode='rb') from the builtins is called. 
## @write_decorator captures the output when open(mode='w'/mode='wb') from the builtins is called. 

#### The decorators don't work with functions/methods that don't use the open() function (for example: cv2.imread / cv2.imwrite)

### Some examples 
```python
import pandas as pd
import cv2
from PIL import Image
import numpy as np
import os.path
from fake_read_write_files import read_decorator, write_decorator

@read_decorator
def readutf8(filename, _file_data):
    with open(filename, mode="r", encoding="utf-8") as f:
        data = f.read()
    return data


@write_decorator
def write_pil_image(pilpic, filepath):
    pilpic.save(filepath)
    # don't use "return" here, the function will return a dict


@read_decorator
def read_bin_file(filename, _file_data):
    with open(filename, mode="rb") as f:
        data = f.read()
    return data


@read_decorator
def pandasread(filename, _file_data):
    return pd.read_csv(filename)


@write_decorator
def pandaswrite(df, filename):
    df.to_csv(filename)
    # don't use "return" here, the function will return a dict


# the read decorator always checks for the kwarg "_file_data"
# It must be passed as a kwarg
e = readutf8(
    filename="f:\\txtdoesnotexist.txt", _file_data="I am fake\nDid you know that?"
)
print(e)

# real file
bi = Image.open(r"C:\Users\Gamer\anaconda3\envs\dfdir\xxxxxxxxxx.png")

# writing to a fake file, returns a dict with all written files in the function,
# even if there is no return value declared
o = write_pil_image(bi, filepath="i_am_a_fake_image.png")
print(
    cv2.imdecode(np.frombuffer(o["i_am_a_fake_image.png"], np.uint8), cv2.IMREAD_COLOR)
)


binaryfile = read_bin_file(
    filename="i_am_a_fake_image.png", _file_data=o["i_am_a_fake_image.png"]
)


df = pandasread(filename="test.csv", _file_data="john,1\nmaria,2\ncarlos,3")
print(df)

pdcsv = pandaswrite(df, filename="test.csv")
print(pdcsv)


# output 
I am fake
Did you know that?
[[[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 255]
  [254 255 255]
  [253 255 255]]
 [[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 255]
  [254 255 255]
  [253 255 255]]
 [[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 255]
  [254 255 255]
  [253 255 255]]
 ...
 [[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 254]
  [255 255 254]
  [255 255 254]]
 [[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 254]
  [255 255 254]
  [255 255 254]]
 [[255 255 255]
  [255 255 255]
  [255 255 255]
  ...
  [255 255 254]
  [255 255 254]
  [255 255 254]]]
     john  1
0   maria  2
1  carlos  3
{'test.csv': ',john,1\r\n0,maria,2\r\n1,carlos,3\r\n'}


```