jwodder / versioningit

Versioning It with your Version In Git
MIT License
78 stars 5 forks source link

Unable to create versioningit "plugin" - i.e. issues wiring methods #74

Closed wrkhenddher closed 9 months ago

wrkhenddher commented 9 months ago

Hi!

I am trying to create my own versioningit "plugin", "versionista". It has its own custom format() function. My goal is to use "versionista" in other projects.

I'm following these instructions:

However, when I try to install my other project, using the same "venv" where "versionista" is installed, it fails:

$ pip install .
...
Collecting versioningit
    Using cached versioningit-3.0.0-py3-none-any.whl (37 kB)
ERROR: Could not find a version that satisfies the requirement versionista (from versions: none)
ERROR: No matching distribution found for versionista
...

My other project ("dummy"):

# pyproject.toml

[build-system]
requires = [
  "setuptools >= 61",
  "wheel",
  # "setuptools_scm[toml]"
  "versioningit",
  "versionista",  # per instrunctions?!
]
build-backend = "setuptools.build_meta"

...

[tool.versioningit.format]
# distance = "{base_version}.post{distance}+{branch}"
# distance-dirty = "{base_version}.post{distance}+{branch}.{build_date:%Y%m%d%H%M}"
# method = { module = "versionista.main", value = "format"}
method = "format"  # per instructions?!

In my "versionista" project:

# pyproject.toml

[build-system]
requires = [
  "setuptools >= 61",
  "wheel",
  "setuptools_scm[toml]"
]
build-backend = "setuptools.build_meta"

...

[options.entry_points]
# NOTE: documentation asks for the following but that doesn't work:
#    [options.entry_points]
#    versioningit.vcs =
#        foobar = mypackage.vcs:foobar_vcs
# 
# ... I guess it meant this instead?
versioningit.format = { format = "versionista.main:format" }
> pip list
Package            Version
------------------ ----------------------
build              1.0.3
dummy              0.0.0.post6+versiongit
importlib-metadata 7.0.1
packaging          23.2
pip                23.0.1
pyproject_hooks    1.0.0
setuptools         56.0.0
tomli              2.0.1
versioningit       3.0.0
versionista        0.1.dev11+dirty
zipp               3.17.0

Am I missing anything obvious? Can I test my "versionista" plugin wired onto "versioningit" outside a build? (e.g. https://versioningit.readthedocs.io/en/stable/command.html#command)

wrkhenddher commented 9 months ago

If I remove "versionista" from [build-system.requires]

File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-o2jxb8a_/overlay/lib/python3.8/site-packages/versioningit/methods.py", line 64, in load
          raise ConfigError(
      versioningit.errors.ConfigError: versioningit.format entry point 'format' not found
      [end of output]

In my other project ("dummy"), I've got this:

# pyproject.toml

[tool.versioningit.format]
method = "format"

While with this:

# pyproject.toml

[tool.versioningit.format]
method = { module = "versionista.main", value = "format" }

I get this:

File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-zj9l184m/overlay/lib/python3.8/site-packages/versioningit/config.py", line 35, in load
          return VersioningitMethod(self.method_spec.load(project_dir), self.params)
        File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-zj9l184m/overlay/lib/python3.8/site-packages/versioningit/methods.py", line 115, in load
          obj = import_module(self.module)
        File "/Users/henddher/.pyenv/versions/3.8.17/lib/python3.8/importlib/__init__.py", line 127, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
        File "<frozen importlib._bootstrap>", line 991, in _find_and_load
        File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
      ModuleNotFoundError: No module named 'versionista.main'
      [end of output]

FYI - This is what my stub "versionista" looks like:

# versionista/src/versionista/main.py
from typing import Any, Dict

import versioningit

def format(*, description: versioningit.VCSDescription, base_version: str, next_version: str, params: Dict[str, Any]) -> str:
    print(description, base_version, next_version, params)
    return "{base_version}.m"

def main():
    print("main")

if __name__ == "__main__":
    main()
$ python
Python 3.8.17 (default, Nov 14 2023, 12:28:42) 
[Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import versionista
>>> import versionista.main
>>> versionista.main.format()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: format() missing 4 required keyword-only arguments: 'description', 'base_version', 'next_version', and 'params'
wrkhenddher commented 9 months ago

Modified "versionista" as I realized the method declaration instructions are for setup.cfg

With this, I can pip install . "versionista" ok.

...
[project.scripts]
versionista-format = "versionista.main:format"

It runs although with traceback:

$ versionista-format
Traceback (most recent call last):
  File "/Users/henddher/Documents/github/dummy/venv/bin/versionista-format", line 8, in <module>
    sys.exit(format())
TypeError: format() missing 4 required keyword-only arguments: 'description', 'base_version', 'next_version', and 'params'

Yet, I cannot use it my other project:

[tool.versioningit.format]
method = "versionista-format"
> pip install .
...
File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-p8__auxi/overlay/lib/python3.8/site-packages/versioningit/core.py", line 190, in from_config
          format=config.format.load(project_dir),
        File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-p8__auxi/overlay/lib/python3.8/site-packages/versioningit/config.py", line 35, in load
          return VersioningitMethod(self.method_spec.load(project_dir), self.params)
        File "/private/var/folders/md/y_nfnc2j6bs7g8b67tf10tfr0000gn/T/pip-build-env-p8__auxi/overlay/lib/python3.8/site-packages/versioningit/methods.py", line 64, in load
          raise ConfigError(
      versioningit.errors.ConfigError: versioningit.format entry point 'versionista-format' not found
      [end of output]
jwodder commented 9 months ago
jwodder commented 9 months ago

Side note: If you're actually planning on using {base_version}.m as your version format, that's not going to work, as it's not a valid PEP 440 version. versioningit will just give you a warning about this, but newer versions of setuptools will error out completely, and I don't think you'll be able to upload to PyPI with such a version.

Henddher commented 9 months ago

Thank you @jwodder!!!

The "No matching distribution found for versionista" ...

Yes - That was it!

I also managed to solve it by using "versionista @ file:///Users/wrkhenddher/Documents/github/versionista" and/or "versionista @ file:///Users/wrkhenddher/Documents/github/versionista/dist/versionista-0.0.2-py3-none-any.whl".

For the former, I had to pip cache remove versionista from my "dummy"'s "venv". For the latter, versionista/ $ python -m build was enough.

Testing versionista via the ...

👍 👍

In order to declare a method entrypoint ...

I think I tried it but didn't work. I must have been because of [build-system.requires] not having a valid URI.

Side note: If you're actually planning ...

Yes. the "m" was just to verify if my stub was getting called.

I think I'm good!

Again, thank you very much @jwodder!!!