Simple sort utility implemented in Python with Click
Project description
nastya-sort
Lightweight implementation of Unix sort utility in Python with Click framework.
Features
- ✅ Sort lines from files or stdin
- ✅ Numeric sorting with
-nflag - ✅ Reverse order with
-rflag - ✅ Docker support
- ✅ Compatible with Unix sort behavior
Installation
From source
git clone https://github.com/Nastia2004/nastya-sort-lnu.git
cd nastya-sort-lnu
pip install -e .
Using Docker
# Or build locally
docker build -t nastya-sort .
Usage
Command Line Interface
# Sort lines from stdin
echo -e "banana\napple\ncherry" | sort
# Sort file contents
sort file.txt
# Numeric sort
echo -e "10\n2\n100\n20" | sort -n
# Output: 2, 10, 20, 100
# Reverse order
sort -r file.txt
# Combine options
sort -rn numbers.txt
Command Options
| Option | Description |
|---|---|
-n, --numeric |
Compare according to string numerical value |
-r, --reverse |
Reverse the result of comparisons |
-h, --help |
Show help message and exit |
Examples
Basic Sorting
# Alphabetical sort
cat names.txt | sort
# Sort and save to file
sort input.txt > sorted.txt
Numeric Sorting
# Sort numbers correctly
echo -e "100\n20\n3\n1000" | sort -n
# Output:
# 3
# 20
# 100
# 1000
Reverse Sorting
# Descending order
echo -e "a\nc\nb" | sort -r
# Output:
# c
# b
# a
Combined with Other Tools
# Sort and remove duplicates
sort file.txt | uniq
# Sort CSV by second column
cut -d',' -f2 data.csv | sort -n
# Count and sort word frequency
cat text.txt | tr ' ' '\n' | sort | uniq -c | sort -rn
Development
Setup Environment
# Create virtual environment
python3 -m venv test
source test/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
Building Docker Image
docker build -t nastya-sort .
docker run nastya-sort --help
Testing
# Test basic sorting
echo -e "c\na\nb" | sort
# Test numeric sorting
echo -e "10\n2\n1" | sort -n
# Test with Docker
echo -e "3\n1\n2" | docker run -i nastya-sort -n
Project Structure
nastya-sort/
├── nastya_sort/
│ ├── __init__.py # Package version
│ └── cli.py # CLI implementation
├── .github/
│ └── workflows/
│ └── docker-publish.yml # CI/CD pipeline
├── Dockerfile # Docker image definition
├── setup.py # Package configuration
├── README.md # This file
└── .gitignore # Git ignore rules
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nastya_sort_lnu-0.2.6.tar.gz
(4.5 kB
view details)
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 nastya_sort_lnu-0.2.6.tar.gz.
File metadata
- Download URL: nastya_sort_lnu-0.2.6.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c93aad06ed81f62330f5b0261996b3bad679bb81b8f52df7da95a8482c6950ab
|
|
| MD5 |
6c5e5e81e7761832480f214f65b4a112
|
|
| BLAKE2b-256 |
5c18ccd67f2062e2737b57071392e1ff1579da75503df65548aa4595d87f190c
|
File details
Details for the file nastya_sort_lnu-0.2.6-py3-none-any.whl.
File metadata
- Download URL: nastya_sort_lnu-0.2.6-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32690f60847e453eacc46ad56d08c42e5d86c09c4efd13e0cc0cafb4bf1fc3f9
|
|
| MD5 |
08cc780eb8700edbeb929b4fd710e505
|
|
| BLAKE2b-256 |
b30dbd367d0b8ef5193a45d1b3ebd7626223777c2774ed1aa8fc01a53cd3dde7
|