English description follows Japanese.
ツール特徴
- 自作ツールを簡単にimportできるツール
- 予め自作ツールが入ったディレクトリを指定しておくことで、簡単にimportできるようになる
簡単な使用例
- 前準備
import private_tools
private_tools.path.append("path/to/your/private-tools") # これはそのPCで1回だけ実行すれば良い
- 利用時
import private_tools # この1行で既にあなたのツールディレクトリが読み込みパスに追加されている
import your_awesome_tool
pathの書き換えについて
- 一度書き換えるとyamlファイルに保存されていて、次回起動時も前回の編集結果が反映されている
- 書き換えのインターフェースは、pythonのlistに対する操作をほぼ全て実装している
# パスの追加
private_tools.path.append("path/to/your/tools")
private_tools.path.push("2nd/path/to/your/tools") # appendと動作は同様
# パス一覧の確認
print(private_tools.path) # -> <private-tools-path-list ['path/to/your/tools', '2nd/path/to/your/tools']>
# パスのオールクリア
private_tools.path = []
# パスの削除
private_tools.path.remove("path/to/your/tools")
発展的な詳細
- private_tools.path は、pythonのデフォルトオブジェクトであるlistへの操作をそのまま受け付けます
- ただし、同一の要素が複数あるときは1つだけ採用されます。setとは異なり、順序は保存します。
- list.append() などのlist自体を変更するメソッドを実装した場合は、pathも即座に書き換わり、その結果はsys.pathやファイルに正しく反映されます。
- 逆に、list[:3] などのlistを変更しない (immutableな) 操作では、pathは変更されず、生成されたlistオブジェクトが返ります
- 以上を踏まえ、下記のような操作が可能です。
private_tools.path += ["path1", "path2"] # 一気に追加
private_tools.path = private_tools.path[:3] + private_tools.path[4:] # リストの結合などもOK
# 下記の操作も受け付ける
del private_tools.path[1]
for e in private_tools.path: print(e)
注意点
- 相対パス指定はそのまま保存されるので、python実行時のカレントパスが変わると読み込めなくなることに注意。
- いつも同じ場所を参照したい場合は、絶対パスで登録すること
- このような設計にした理由は、例えば異なるOSの本番環境の参照先を相対パスで加えたい場合などに、相対参照での指定を勝手にその実行されたOSの絶対パスに変換してしまうと、本来の意図である「別のOSでの相対パス」が意図通り登録できなくなってしまうためである。
Tool Features
- A utility that allows you to easily import your own custom tools
- By specifying a directory containing your custom tools in advance, you can import them effortlessly
Simple Usage Example
- Setup
import private_tools
private_tools.path.append("path/to/your/private-tools") # This only needs to be run once per machine
- When using
import private_tools # This single line already adds your tool directory to the import path
import your_awesome_tool
About Modifying the Path
- Once modified, the path is saved to a YAML file and will persist across sessions
- The path interface implements almost all operations available to a Python
list
# Add a path
private_tools.path.append("path/to/your/tools")
private_tools.path.push("2nd/path/to/your/tools") # Same behavior as append
# Check current paths
print(private_tools.path) # -> <private-tools-path-list ['path/to/your/tools', '2nd/path/to/your/tools']>
# Clear all paths
private_tools.path = []
# Remove a path
private_tools.path.remove("path/to/your/tools")
Advanced Details
private_tools.pathaccepts operations just like Python's built-inlist- However, if duplicate entries exist, only one will be retained. Unlike
set, the order is preserved. - When you use list-mutating methods like
list.append(), the path is immediately updated and reflected in bothsys.pathand the YAML file. - On the other hand, non-mutating (immutable) operations like
list[:3]do not modify the path but return a new list object - Based on the above, the following operations are possible:
private_tools.path += ["path1", "path2"] # Add multiple paths at once
private_tools.path = private_tools.path[:3] + private_tools.path[4:] # List concatenation is also allowed
# The following operations are also supported
del private_tools.path[1]
for e in private_tools.path: print(e)
Notes
- Relative path specifications are saved as-is, so be aware that they may become unreadable if the current working directory changes when running Python.
- If you always want to reference the same location, register it using an absolute path.
- The reason for this design is to avoid unintentionally converting relative references into absolute paths specific to the OS where the code is executed. For example, if you want to register a relative path intended for a different OS's production environment, automatic conversion would prevent the original intention of "a relative path for another OS" from being registered correctly.
Metadata
Release files for private-tools 0.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| private-tools-0.0.0.tar.gz | 6.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| private_tools-0.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / private-tools-0.0.0.tar.gz
| Download URL | private-tools-0.0.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c2351aeff0b250431e1606e8db461c178a750a0b7204382d9080749210d8084
|
|
BLAKE2b-256 checksum How to use checksums |
26e67f475c4ec7825e7d1a6f10ff0b9e233ae5b644654493ffa77e7e82f7b17b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Release files / private_tools-0.0.0-py3-none-any.whl
| Download URL | private_tools-0.0.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8860f3d32250e4685c4eff32751d83a47c64af5790bf616cd660e539a4e2ec1f
|
|
BLAKE2b-256 checksum How to use checksums |
090041c96f4e4117b0d21bfc9cc93690644d2c0cc0d28b90ec4e19d1b1005e31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.3
|
Security for private-tools 0.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.