A lightweight string pattern tool
Project description
Star Trace
A program originally created by William Coker for ACU Atom Smashers
Installation
Pypi (pip)
This project is on the python install index, meaning you may install it via pip:
pip install startrace
Release
There are pre-built .whl files in the releases section for this project on
github available for download. Once downloaded, call
pip install /location/of/your/file/startrace-x-x-x-py3-none-any.whl
Build from source
Alternatively you may also clone this repository using
git clone https://github.com/wdc756/StarTrace.git
Then you may make any changes you'd like, and call
python -m build
Note: This is assuming you already have build, setuptools, and wheel installed. If
this is not the case run pip install build setuptools wheel first. Additionally
there is already a file with unit tests in the test/ dir. If you wish to run unit
tests before building, run pytest (Assuming it's already installed)
Usage
StarTrace is a lightweight python module aimed to help manage similarly-named files or objects. Main usage generally follows this flow:
# To cut down on verbosity, it's easier to just import everything
from startrace import *
import numpy as np
# Create pattern via Token list
file_pattern = Pattern([
Token('syn ', 1, Iter(1, 3, 1)),
Token('.npy')
])
# While the pattern can increment, load each numpy file
while True:
print(file_pattern.get_pattern())
values = np.load(file_pattern.get_pattern())
if not values.increment():
break
This example code will create a file pattern that will load the following files:
syn 1.npy
syn 2.npy
syn 3.npy
Iters
Iters are the most basic dataclass included in StarTrace. They hold three Numbers: start, end,
and step. These values are then used when Pattern.increment() is called to either increment
the number or through a list of strings
Tokens
Tokens are the main dataclass you will interact with when creating Patterns, and they can be created using several different arguments.
from startrace import *
import numpy as np
# This will create a token that iterates over numbers 1-10
Token('', 1, Iter(1, 10, 1))
# This will also create a token iterating over 1-10
Token('', 1, (1, 10, 1))
# This creates a Token iterating over 1-9, counting by 3 -> (1, 3, 9)
Token('', 1, (1, 9, 3))
# This creates a Token that iterates over the string list -> 'test', 'hello', 'world'
Token(['test', 'hello', 'world'])
# This creates a Token that iterates over the int values in the list -> 1, 3, 4, 2, 5
list = [1, 3, 4, 2, 5]
Token(list)
# There's also numpy support, so you can enter 1D np.ndarrays for phrases and Token will interpret it
npList = np.arange(1, 10, 1)
Token("I'm a numpy value:", npList)
Patterns
Patterns are the high-level dataclass you'll interact with most once created. It has two
only two functions: get_pattern() and increment(). Get Pattern returns a string stitching
all Tokens together with their current number/str values, and Increment moves all numbers up by
one value, one Token at a time. For example
from startrace import *
pat = Pattern([
Token('syn', 1, (1, 2, 1)),
Token('_percent', 1, (1, 3, 1))
])
while True:
print(pat.get_pattern())
if not pat.increment():
break
will print
syn1_percent1
syn1_percent2
syn1_percent3
syn2_percent1
syn2_percent2
syn2_percent3
Dictionary Patterns
You may also use pre-generated patterns in the form of dictionaries using a list[type: "t", value: "v"]
format. For example:
from startrace import *
test_dict = [
{"type": "c_str", "value": "This is a const str "},
{"type": "d_str", "values": ["These ", "will be ", "iterated over "]},
{"type": "c_str", "value": "0"}, # this is a str, because StarTrace doesn't support single numbers
{"type": "r_val", "start": 1, "end": 3, "step": 1}, # This iterates between 1 and 10
{"type": "d_val", "values": [1, 5, 50]} # This iterates over each value
]
pat = Pattern(test_dict)
while True:
print(pat.get_pattern())
if not pat.increment():
break
will print
This is a const str These 011
This is a const str These 015
This is a const str These 0150
...
This is a const str iterated over 031
This is a const str iterated over 035
This is a const str iterated over 0350
License
This project is under the GNU General Public License, feel free to modify or distribute this code however you see fit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file startrace-1.1.0.tar.gz.
File metadata
- Download URL: startrace-1.1.0.tar.gz
- Upload date:
- Size: 45.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36653dbcb8360d9d2ee6da231bc05891d3850189f5e06a08f3badba54989c7f6
|
|
| MD5 |
af0abb562beef64ab1b0629d6479c21b
|
|
| BLAKE2b-256 |
589645bd8e54e64fbfba5c7fc6d3bd3a42ac994db6721723bed4cd6d3bfbc05e
|
File details
Details for the file startrace-1.1.0-py3-none-any.whl.
File metadata
- Download URL: startrace-1.1.0-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbbfc97fa19ebcd2dd4d5db387c828d967c57c16f3d90f15e7250725d3d1d30f
|
|
| MD5 |
e2050ba2a0c736a430f87d1f4eda550b
|
|
| BLAKE2b-256 |
c7877601ac771d4bb57fc352520314d9ceb4da264ae96986951ed51864c2a714
|