ManderaGeneral / generalpackager

Tools to interface GitHub, PyPI, NPM and local modules / repos. Used for generating files to keep projects dry and synced. Tailored for ManderaGeneral for now.
https://pypi.org/project/generalpackager/
Apache License 2.0
0 stars 0 forks source link

Make Targets, Targets Literal, and default target DRY #68

Closed Mandera closed 1 year ago

Mandera commented 1 year ago

Currently it's a coupled mess, would be good to clean up

class Metadata(ConfigFile):
    target: Literal["python", "node", "django", "exe"] = "python"
class File:
    """ Instantiated if its owner is. """
    target = Targets.python  # Should probably default to None, and then I put python on most files
    @property
    def target(self):
        if self._target is not Ellipsis:
            return self._target
        else:
            if self.localrepo.metadata_exists():
                return self.localrepo.metadata.target
            else:
                return self.Targets.python
_TARGETS = Literal["python", "node", "django", "exe"]  # This is coupled to generalpackager.api.localrepo.base.targets.Targets, not ideal
class Targets(DataClass):
    python = "python"
    node = "node"
    django = "django"
    exe = "exe"
Mandera commented 1 year ago

Might need to prioritize this. Trying to set default target to Python now and it's proving difficult.

Right now it actually traverses the opposite way:

Making Packager's instantiating read Metadata straight away would solve everything

Times in microseconds - 431% time taken when exists and 271% when doesn't exist

Name | Exists | Didnt Exists -- | -- | -- Read metadata | 1640 | 1030 No read | 380 | 376 Update 2023-03-15 | 185 | 185

python -m timeit -s "from generalpackager import Packager" "Packager('generallibrary')"

Mandera commented 1 year ago
Mandera commented 1 year ago

Not a huge fan of how you have to instantiate LocalRepo_Node and Python. I want a unified way for the user to instantiate it. Probably a localrepo function Why is it only LocalRepo that has this issue? Package hosts have GitHub, PyPI and NPM. Doesn't really matter, the issue is that I wanted to be able to instantiate LocalRepo on a random local repo to get info about it