Skip to content

Commit 36a3b57

Browse files
committed
Core uicli architecture (#9)
* Refactor project structure and enhance CLI functionality * Enhance CIDR detection across platforms and improve IP validation in GUI * Update README.md * Refactor network functionality by introducing adapters for IP detection and CIDR handling * Update README.md * Add skipping GUI tests in CI without DISPLAY * Add skipping GUI tests in CI without DISPLAY * Fix CI tests * Fix CI tests
1 parent 9d55eba commit 36a3b57

File tree

16 files changed

+1826
-958
lines changed

16 files changed

+1826
-958
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ exclude =
66
__pycache__,
77
*.egg-info,
88
build,
9-
dist
9+
dist,
10+
.backup,

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ jobs:
5757
flake8 lancalc/ --count --select=E9,F63,F7,F82 --show-source --statistics
5858
flake8 lancalc/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
5959
60-
- name: Run core tests
61-
run: |
62-
python -m pytest test_lancalc.py -v
63-
64-
- name: Run GUI tests (Linux)
60+
- name: Run tests (Linux)
6561
if: matrix.os == 'ubuntu-latest'
6662
run: |
6763
xvfb-run -a python -m pytest test_lancalc.py -v
68-
69-
- name: Run GUI tests (macOS)
64+
65+
- name: Run tests (macOS)
7066
if: matrix.os == 'macos-latest'
7167
run: |
7268
python -m pytest test_lancalc.py -v
73-
74-
- name: Run GUI tests (Windows)
69+
70+
- name: Run tests (Windows)
7571
if: matrix.os == 'windows-latest'
7672
run: |
7773
python -m pytest test_lancalc.py -v

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: publish
1+
name: Publish
22
on:
33
push:
44
tags:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ venv/
109109
ENV/
110110
env.bak/
111111
venv.bak/
112+
.backup
112113

113114
# Spyder project settings
114115
.spyderproject

README.md

Lines changed: 154 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
LanCalc is a desktop application built with PyQt5, designed to calculate network configurations for Windows, macOS, and Linux systems.
88

9-
![image](https://github.com/user-attachments/assets/be7655cc-9348-4d7c-bb25-a650e00cc422)
9+
![image](https://github.com/user-attachments/assets/a7d1779f-d138-4819-84c6-4df876efc292)
1010

1111
[Download](https://github.com/lancalc/lancalc/releases)
1212

@@ -18,19 +18,44 @@ Support IPv4 address formats, subnet masks and prefixes. This tool is particular
1818

1919
### Installation
2020

21-
**Install LanCalc Stable version:**
21+
Python 3.9+ is required.
22+
23+
- Default (with GUI):
2224

2325
```bash
2426
pip3 install lancalc
2527
```
2628

27-
**Or install LanCalc from GitHub:**
29+
- CLI-only / headless (avoid installing PyQt5):
2830

2931
```bash
30-
pip3 install git+https://github.com/lancalc/lancalc.git
32+
# Install package without dependencies, then only required CLI deps
33+
pip3 install --no-deps lancalc
34+
pip3 install -r requirements.txt
3135
```
3236

33-
Install PIP
37+
- Install without GUI dependencies:
38+
39+
```bash
40+
# Install with nogui extras (excludes PyQt5)
41+
pip3 install 'lancalc[nogui]'
42+
```
43+
44+
- Install from GitHub:
45+
46+
```bash
47+
# With GUI (default)
48+
pip3 install 'git+https://github.com/lancalc/lancalc.git'
49+
50+
# CLI-only / headless
51+
pip3 install --no-deps 'git+https://github.com/lancalc/lancalc.git'
52+
pip3 install -r requirements.txt
53+
54+
# Without GUI dependencies
55+
pip3 install 'git+https://github.com/lancalc/lancalc.git#egg=lancalc[nogui]'
56+
```
57+
58+
If pip is missing:
3459

3560
```bash
3661
curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
@@ -50,16 +75,22 @@ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
5075
source ~/.bashrc
5176
```
5277

78+
Notes:
79+
- On Linux, PyQt5 may require system Qt libraries (xcb plugin). If GUI fails to start, ensure a desktop environment is available and try installing system packages (e.g. Debian/Ubuntu: `sudo apt install python3-pyqt5`), or use the CLI-only steps above.
80+
- In CI/headless environments, prefer the CLI-only steps above to skip GUI dependencies.
81+
5382
## Running the Application
5483

5584
### GUI Mode
5685

57-
After installation, launch the application with the command:
86+
After installation (default with GUI), launch the application with the command:
5887

5988
```bash
6089
lancalc
6190
```
6291

92+
LanCalc auto-detects the environment. If GUI dependencies are unavailable or you are in a headless session, the launcher falls back to CLI help. In such cases, use the CLI examples below.
93+
6394
### CLI Mode
6495

6596
LanCalc also supports command-line interface for automation and scripting:
@@ -78,6 +109,12 @@ lancalc 192.168.1.100/31 # Point-to-point network
78109
lancalc 192.168.1.1/32 # Single host
79110
```
80111

112+
You can also run via module:
113+
114+
```bash
115+
python3 -m lancalc 192.168.1.1/24 --json
116+
```
117+
81118
### Output Format
82119

83120
**Text mode** (default):
@@ -117,21 +154,34 @@ That's it! The application will start and automatically detect your current netw
117154

118155
### Prerequisites
119156

120-
Python 3.9+ is required.
157+
Python 3.9+ is required. GUI development requires PyQt5 (installed by default).
121158

122-
For production use (CLI only):
159+
- Production (CLI only):
123160
```bash
124161
pip3 install -r requirements.txt
125162
```
126163

127-
For GUI support:
164+
- Editable install with GUI (default):
128165
```bash
129-
pip3 install -e .[gui]
166+
pip3 install -e .
167+
```
168+
169+
- Editable install without GUI:
170+
```bash
171+
pip3 install --no-deps -e .
172+
pip3 install -r requirements.txt
130173
```
131174

132-
For development:
175+
- Full dev setup (with GUI):
133176
```bash
134-
pip3 install -e .[dev,gui]
177+
pip3 install -e '.[dev]'
178+
```
179+
180+
- Dev without GUI:
181+
```bash
182+
pip3 install --no-deps -e .
183+
pip3 install -r requirements.txt
184+
pip3 install pytest pytest-qt pre-commit flake8
135185
```
136186

137187
### Installation for Development
@@ -145,7 +195,11 @@ git clone https://github.com/lancalc/lancalc.git
145195
### Running from Source
146196

147197
```bash
198+
# GUI (requires PyQt5)
148199
python3 lancalc/main.py
200+
201+
# CLI
202+
python3 -m lancalc 192.168.1.1/24
149203
```
150204

151205
### Development Tools
@@ -272,8 +326,95 @@ lancalc 224.0.0.1/4 --json
272326

273327
The JSON output includes the following fields:
274328

275-
- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
276329
- **`comment`**: Description and RFC reference for special ranges (empty for normal unicast addresses)
277330
- **`hosts`**: Number of available host addresses in the specified subnet
278331

279332
These fields are always present, making the JSON output format consistent regardless of address type.
333+
334+
## Usage
335+
336+
### Command Line Interface
337+
338+
```bash
339+
# Basic subnet calculation
340+
lancalc 192.168.1.1/24
341+
342+
# JSON output
343+
lancalc 192.168.1.1/24 --json
344+
345+
# Show internal/private IP address
346+
lancalc --internal
347+
lancalc -i
348+
349+
# Show external/public IP address
350+
lancalc --external
351+
lancalc -e
352+
353+
# Use multiple info flags simultaneously
354+
lancalc -i -e
355+
lancalc -i -e --json
356+
357+
# Show version
358+
lancalc --version
359+
```
360+
361+
### Examples
362+
363+
**Basic calculation:**
364+
```bash
365+
$ lancalc 192.168.1.1/24
366+
Network: 192.168.1.0
367+
Prefix: /24
368+
Netmask: 255.255.255.0
369+
Broadcast: 192.168.1.255
370+
Hostmin: 192.168.1.1
371+
Hostmax: 192.168.1.254
372+
Hosts: 254
373+
```
374+
375+
**JSON output:**
376+
```bash
377+
$ lancalc 192.168.1.1/24 --json
378+
{
379+
"network": "192.168.1.0",
380+
"prefix": "/24",
381+
"netmask": "255.255.255.0",
382+
"broadcast": "192.168.1.255",
383+
"hostmin": "192.168.1.1",
384+
"hostmax": "192.168.1.254",
385+
"hosts": "254"
386+
}
387+
```
388+
389+
**Interface information:**
390+
```bash
391+
$ lancalc -i
392+
Address: 10.16.69.146
393+
Prefix: /24
394+
395+
$ lancalc -i --json
396+
{"address": "10.16.69.146", "prefix": "/24"}
397+
```
398+
399+
**External IP detection:**
400+
```bash
401+
$ lancalc -e
402+
External IP: 216.66.18.3
403+
404+
$ lancalc -e --json
405+
{"external_ip": "216.66.18.3"}
406+
```
407+
408+
**Multiple info flags:**
409+
```bash
410+
$ lancalc -i -e
411+
Address: 10.16.69.146
412+
Prefix: /24
413+
414+
External IP: 216.66.18.3
415+
416+
$ lancalc -i -e --json
417+
{"address": "10.16.69.146", "prefix": "/24"}
418+
419+
{"external_ip": "216.66.18.3"}
420+
```

docs/CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ All notable changes to LanCalc will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.9] - 2024-12-19
9+
10+
### Added
11+
- **External IP detection**: New `-e/--external` CLI flag to retrieve external/public IP address via `https://ifconfig.me/`
12+
- **Simultaneous CLI flags**: Support for using multiple info flags simultaneously (e.g., `-i -e`)
13+
- **Modular architecture**: Created `adapters.py` for external system interactions
14+
- **Clean separation**: Moved network interface detection and external IP retrieval to `adapters.py`
15+
- **Enhanced error handling**: Better validation and error messages for external IP retrieval
16+
- **nogui extras**: New optional dependency group for CLI-only installations without PyQt5
17+
- **Adaptive launcher**: Main entry point automatically detects environment and chooses CLI/GUI mode
18+
- **Better error handling**: Improved fallback mechanisms when GUI is unavailable
19+
20+
### Changed
21+
- **Architecture refactoring**: Simplified project structure with main.py as core CLI and gui.py as optional GUI module
22+
- **Modular design**: Separated CLI and GUI functionality into distinct modules for better maintainability
23+
- **Optional GUI**: GUI can now be installed separately or excluded entirely via nogui extras
24+
- **Clean imports**: Replaced complex import fallbacks with clean absolute package imports
25+
26+
### Technical
27+
- **Simplified structure**: Removed cli.py, core.py modules in favor of consolidated main.py
28+
- **Import optimization**: Clean absolute imports throughout the codebase
29+
- **Entry point fixes**: Corrected pyproject.toml entry point to use main module
30+
831
## [0.1.8] - 2024-12-19
932

1033
### Added

lancalc/__init__.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
LanCalc - A desktop application for calculating network configurations
5+
LanCalc - IPv4 subnet calculator with GUI and CLI interfaces.
6+
7+
A cross-platform tool for calculating IPv4 network parameters including
8+
network address, broadcast address, host range, and special IPv4 range detection.
69
"""
710

8-
__version__ = '0.1.8'
11+
__version__ = "0.1.9"
912
__author__ = 'Aleksandr Pimenov'
1013
__email__ = 'wachawo@gmail.com'
1114

12-
from .main import main
15+
# Import modules
16+
from . import core
17+
from . import cli
18+
from . import gui
19+
from . import main
20+
from . import adapters
1321

14-
# Try to import LanCalc only if GUI is available
22+
# Export LanCalc for tests
1523
try:
16-
from .main import LanCalc # noqa: F401
17-
__all__ = ['main', 'LanCalc', '__version__']
24+
from .gui import LanCalcGUI
25+
LanCalc = LanCalcGUI
1826
except ImportError:
19-
# GUI not available, only export main function
20-
__all__ = ['main', '__version__']
27+
LanCalc = None
28+
29+
__all__ = [
30+
"__version__",
31+
"__author__",
32+
"__email__",
33+
"core",
34+
"cli",
35+
"gui",
36+
"main",
37+
"adapters",
38+
"LanCalc",
39+
]

lancalc/__main__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
from .main import main
6+
7+
if __name__ == "__main__":
8+
sys.exit(main())

0 commit comments

Comments
 (0)