numfile
Automatically assign an increasing sequence number to file names.
Installation
$ python -m pip install numfile
Use Cases
Write data to numbered snapshot files in a given directory:
$ python -q
>>> from numfile import open_next
>>> for version in ("first", "second", "third"):
... with open_next("/tmp/snapshot.txt") as file:
... print(f"The {version} version.", file=file)
...
$ ls -d /tmp/* | grep snapshot
/tmp/snapshot-1.txt
/tmp/snapshot-2.txt
/tmp/snapshot-3.txt
Append messages to the latest log file:
$ ls -tr | grep app-error
app-error.log
app-error-2.log
app-error-3.log
$ python -q
>>> from numfile import open_latest
>>> with open_latest("app-error.log") as file:
... print("Oops... Something went wrong!", file=file)
... print(file.name)
...
app-error-3.log
$ tail -n1 app-error-3.log
Oops... Something went wrong!
Consolidate similar files in chronological order:
$ python -q
>>> from numfile import open_all
>>> for file in open_all("/tmp/snapshot.txt"):
... print(file.name, file.read(), end="")
...
/tmp/snapshot-1.txt The first version.
/tmp/snapshot-2.txt The second version.
/tmp/snapshot-3.txt The third version.
Development
$ git clone git@github.com:bzaczynski/numfile.git
$ cd numfile
$ pyenv local 3.9.0
$ python -m venv .venv --prompt=numfile
$ source .venv/bin/activate
$ pip install -U pip flit
$ flit install --deps=all --symlink
$ python -m pytest
Releasing
Test
Make sure there are no uncommitted or untracked files, and then bump the version:
$ bump2version minor
$ git status
$ git commit -am "Bumped version"
Build a new binary package:
$ rm -rf dist
$ flit build
Publish the binaries to the official PyPI server:
$ flit publish
To use the Test PyPI server, create a file ~/.pypirc with your username:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = your-username
[testpypi]
repository = https://test.pypi.org/legacy/
username = your-username
Then, supply the test server using the --repository flag:
$ flit publish --repository testpypi
Metadata
Release files for numfile 0.1.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 | |
|---|---|---|---|
| numfile-0.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| numfile-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.1 kB
Release files / numfile-0.1.0.tar.gz
| Download URL | numfile-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dba81491e97c4163a2c8e721d99b24d61a3aaeda6b99f71115a53e3230839a88
|
|
BLAKE2b-256 checksum How to use checksums |
c30c43ac3e0e05097c43536d211a95841ad16d18bed1a16001423b6f016c3eca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.0
|
Release files / numfile-0.1.0-py3-none-any.whl
| Download URL | numfile-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
988bdb12041f5ca79eeaf198606681103f5fe6754be0d6b5aef206b4221f9251
|
|
BLAKE2b-256 checksum How to use checksums |
b78b20261955d77691e68a36455d6511b13b17fce338544526d21f259408e390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.0
|