acsone / setuptools-odoo

A library to help packaging Odoo addons with setuptools. It mainly populates the usual setup.py keywords from the Odoo manifest files.
GNU Lesser General Public License v3.0
41 stars 46 forks source link

[FIX] Use the '--show-toplevel' param instead of guessing from nothing. #41

Closed Byloth closed 5 years ago

Byloth commented 5 years ago

There is a strange case in which the original function does not work.

If you create a script from scratch, import setuptools_odoo as a normal Python module and then you call get_git_postversion (or simply get_git_root) it will be related to the directory in which you run your script.

For example...
If you run your script from inside your GIT repository, it will work properly (of course)... But...
If you run your script from outside the GIT repository, it will not work properly.


e.g.

# ~/myscript.py

import sys
from setuptools_odoo.git_postversion import get_git_root

print(get_git_root(sys.argv[1]))
# console

~ $ cd /tmp
/tmp $ python3 ~/myscript.py "/home/matteo/myrepo1"

# The output, will be:
/tmp
# console

~ $ cd ~/myrepo1
~/myrepo1 $ python3 ~/myscript.py "/home/matteo/myrepo1"

# The output, will be:
/home/matteo/myrepo1
# console

~ $ cd ~/myrepo1/subdir
~/myrepo1/subdir $ python3 ~/myscript.py "/home/matteo/myrepo1"

# The output, will be:
/home/matteo/myrepo1/subdir
# console

~ $ cd ~/myrepo2
~/myrepo2 $ python3 ~/myscript.py "/home/matteo/myrepo1"

# The output, will be:
/home/matteo/myrepo2

This PR, fix this behaviour.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.02%) to 87.543% when pulling 1af59c0b0af1047eefd71579827cf741d36e591a on linkitspa:master into eefbbf7e80b5ff3d38e2c5dfcf66077ff38eabaa on acsone:master.

sbidoul commented 5 years ago

Hi @Byloth,

Thanks for the report and the fix. git rev-parse --git-dir indeed returns a relative path and --show-toplevel is a much better solution.

That said, I want take the opportunity to stress that the only public API of setuptools-odoo, beyond using it as a setuptools plugin, is setuptools.get_addon_metadata(). So anything else is subject to change without notice.