Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate circular imports in archives #200

Open
snake-biscuits opened this issue Sep 4, 2024 · 3 comments
Open

Eliminate circular imports in archives #200

snake-biscuits opened this issue Sep 4, 2024 · 3 comments
Assignees
Labels
archives related to archives module bug Something isn't working refactor requires restructuring some backed stuff slow burn lots of work & will take a long time
Milestone

Comments

@snake-biscuits
Copy link
Owner

Some archives scripts cannot import branches.base
valve.source & nexon.cso2 import pkware.Zip & nexon.PakFile
Using Struct would be really handy for some binary structures (those less tightly packed)

This might be because we use from ..branches.base import Struct (to avoid collision w/ archives.base)
Since that has to go through bsp_tool/branches/__init__.py, which loads all branch scripts

Would from ..branches import base as branches_base work?

If that isn't the case, we'll have to move branches.base classes elsewhere (maybe utils.binary?)

@snake-biscuits snake-biscuits added refactor requires restructuring some backed stuff archives related to archives module labels Sep 4, 2024
@snake-biscuits snake-biscuits self-assigned this Sep 4, 2024
@snake-biscuits
Copy link
Owner Author

Would from ..branches import base as branches_base work?

No, it doesn't

Time for Plan B

@snake-biscuits snake-biscuits added the bug Something isn't working label Sep 4, 2024
@snake-biscuits snake-biscuits added the slow burn lots of work & will take a long time label Sep 5, 2024
@snake-biscuits
Copy link
Owner Author

moving such a core feature to a new location is a huge job
we also need to be sure the new location is a good one

utils.binary seems like a good location from a namespaces perspective
but branches.base is a big cluttered file, overlapping w/ function utils could be extremely messy

taking each class (Struct, MappedArray & BitField) into their own script seems smart, but idk
branches.base contains some utils universal to all 3, which might be hard to spread

possible new submodule:

lump_classes/
  | __init__.py
  | bitfield.py
  | mapped_array.py
  | struct.py

tbh we could put this under bsp_tool.lumps, since most lumps interact w/ RawBspLump etc.
branches.shared.UnsignedInts etc. (BasicLumpClasses) would need to move too
grouping them together makes sense to me, feels intuitive to remember
branches.shared is kinda an awkward spot anyway

@snake-biscuits
Copy link
Owner Author

would also be cool to have a generic SpecialLumpClass baseclass
for wiring up a .from_bytes() @classmethod
that way implementations only need a .from_stream() __init__

binary.read_struct has been really handy for building .from_stream()s in archives
I can see it getting a lot of use in SpecialLumpClass specs as well

Just can't think of where'd be a good place to put that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archives related to archives module bug Something isn't working refactor requires restructuring some backed stuff slow burn lots of work & will take a long time
Projects
Status: Todo: Code
Development

No branches or pull requests

1 participant