Skip to content

feat: python2 to python3#9

Open
zeidlitz wants to merge 3 commits into
masterfrom
feat/python2-to-python3
Open

feat: python2 to python3#9
zeidlitz wants to merge 3 commits into
masterfrom
feat/python2-to-python3

Conversation

@zeidlitz

@zeidlitz zeidlitz commented Nov 29, 2025

Copy link
Copy Markdown

the goal with this change is to make the source in this project compatible with python3 while keeping any previous python2 logic intact

@zeidlitz
zeidlitz force-pushed the feat/python2-to-python3 branch 2 times, most recently from c95215d to f832360 Compare November 29, 2025 21:32
@zeidlitz zeidlitz changed the title Feat/python2 to python3 feat: python2 to python3 May 12, 2026
zeidlitz and others added 3 commits July 26, 2026 20:31
The test suite could not run at all in this PR: every test file mixed
a bare `from BaseTestCase import X` (needs tests/ on sys.path) with
`from lib import X` (needs the repo root on sys.path), while the
leftover sys.path.insert only added <repo_root>/lib, satisfying
neither. Normalized every test file + BaseTestCase.py to insert the
repo root and import BaseTestCase via `tests.BaseTestCase`. Also gave
lib/processor.py and lib/networks.py package-relative imports for
ipcalc, since bare `import ipcalc` only worked when lib/ itself was on
sys.path (the old, now-abandoned convention).

Real bugs found once the suite could actually run:
- TestParser.py: testParseNetwork/testParseNetworkNoVlan silently lost
  their processor.network(...) setup calls during the port, so they
  asserted against an empty table. Restored them.
- processor.py host(): vlan lookup used the host's own freshly-created
  node_id instead of the passed-in network_id, so vlan (and therefore
  IPv6 address generation) was always None. Also dropped a bogus
  `row[5] = json.dumps(row[5])` that JSON-encoded the network_id
  foreign key before insert.
- processor.py network(): `len(net_ipv4)` crashed (ipcalc.Network has
  no __len__) on every call; and the function returned a
  (node_id, network_id) tuple instead of just node_id, corrupting
  parse()'s network_id tracking for every host/network line after the
  first network definition in a file.
- lib/packages.py, lib/firewall.py: leftover `.iteritems()` calls
  (removed in Python 3). One of them (firewall.py's redundant-flow
  pruning loop) had also lost its `node, services` tuple unpacking,
  silently disabling that logic entirely rather than crashing.
- lib/location.py switch_locations(): `/` now does true division in
  Python 3 where Python 2 silently floor-divided, producing fractional
  pixel coordinates. Restored `//` to keep whole-pixel output.
- lib/ipcalc.py: removed a redundant duplicate `self.mask = int(...)`
  line.
- requirements.txt: removed `requests`, `layout`, `ipcalc`, `six`,
  `processor` (layout/ipcalc/processor are this project's own lib/
  modules, not PyPI packages; requests/six are unused), and bumped
  PyYAML off the ancient 3.11 pin, which fails to build against modern
  CPython.
- makefile: test/coverage/draw targets still invoked python2.7.

TestSeatmap.testAddCoordinates/testSwitchLocation/
testSwitchLocationWithMixedLayout expectations updated for two
inherent, unavoidable Python 2->3 differences that surfaced once the
suite could run: dict iteration order (insertion-order in Py3 vs
hash-order in Py2) changes which hall's switches get inserted first,
and round()'s tie-breaking rule (round-half-to-even in Py3 vs
round-half-away-from-zero in Py2) changes one scaled-width value by 2px.

Verified: full test suite passes under Python 3, and an end-to-end
`generate.py` run against real fixture data produces correct host
vlan/IPv6/network_id data (previously broken by the host() bug above).
@SoundGoof
SoundGoof force-pushed the feat/python2-to-python3 branch from 66e573e to 62ca988 Compare July 26, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants