mpmath icon indicating copy to clipboard operation
mpmath copied to clipboard

mpmath should not hard depend on pkg_resources

Open asmeurer opened this issue 6 years ago • 4 comments
trafficstars

It looks like https://github.com/fredrik-johansson/mpmath/pull/422 added a hard dependency on pkg_resources.

I think this is a bad idea. It forces a dependency on setuptools. pkg_resources is also known to have a lot of issues.

I would recommend using something like versioneer if you want to have a version based on git tags.

asmeurer avatar Feb 26 '19 20:02 asmeurer

To add a concrete use-case where that is a problem : I m trying to import mpmath from source (a cloned worktree on my filesystem, via sys.path hacking, to easily work on my project, yet also be able to modify my fork of mpmath), and I get :

  File "/home/alexv/Projects/crypy/crypy/euc/__init__.py", line 51, in <module>
    import mpmath
  File "/home/alexv/Projects/crypy/submodules/mpmath/mpmath/__init__.py", line 2, in <module>
    __version__ = pkg_resources.get_distribution(__name__).version
  File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/__init__.py", line 479, in get_distribution
    dist = get_provider(dist)
  File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/__init__.py", line 355, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/__init__.py", line 898, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/__init__.py", line 784, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'mpmath' distribution was not found and is required by the application

because the package has not been installed. I havent tested but I'd probably get the same error, if I just cloned the repository on the side and open it with my IDE (Pycharm), which will add it to the PYTHONPATH.

So in my usecase, I need a way to import directly from source, that means a way to get a version number without installing, without involving setuptools at all.

I think this means that the version number should be in the source (as it was before #422), to minimize dependencies to other systems around (installer, version control, etc.)

asmodehn avatar Mar 08 '19 09:03 asmodehn

I'd be happy to have it in the source again.

On Fri, Mar 8, 2019, 10:45 AlexV [email protected] wrote:

To add a concrete use-case where that is a problem : I m trying to import mpmath from source (a cloned worktree on my filesystem, via sys.path hacking, to easily work on my project, yet also be able to modify my fork of mpmath), and I get :

File "/home/alexv/Projects/crypy/crypy/euc/init.py", line 51, in import mpmath File "/home/alexv/Projects/crypy/submodules/mpmath/mpmath/init.py", line 2, in version = pkg_resources.get_distribution(name).version File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/init.py", line 479, in get_distribution dist = get_provider(dist) File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/init.py", line 355, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/init.py", line 898, in require needed = self.resolve(parse_requirements(requirements)) File "/home/alexv/.local/share/virtualenvs/crypy-PletnYfd/lib/python3.7/site-packages/pkg_resources/init.py", line 784, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'mpmath' distribution was not found and is required by the application

because the package has not been installed. I havent tested but I'd probably get the same error, if I just cloned the repository on the side and open it with my IDE (Pycharm), which will add it to the PYTHONPATH.

So in my usecase, I need a way to import directly from source, that means a way to get a version number without installing, without involving setuptools at all.

I think this means that the version number should be in the source (as it was before #422 https://github.com/fredrik-johansson/mpmath/pull/422), to minimize dependencies to other systems around (installer, version control, etc.)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fredrik-johansson/mpmath/issues/443#issuecomment-470868489, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWgxifeLr3Remp4yAxLPt-B1XkTCkEuks5vUjE1gaJpZM4bTB_d .

fredrik-johansson avatar Mar 08 '19 11:03 fredrik-johansson

It forces a dependency on setuptools. is also known to have a lot of issues.

setuptools is a standard, see https://packaging.python.org/ sympy has a lot of issues. Should people use sympy?

I would recommend using something like versioneer

versioneer - is not a standard package.

I m trying to import mpmath from source (a cloned worktree on my filesystem, via sys.path hacking, to easily work on my project, yet also be able to modify my fork of mpmath), and I get

What prevents you from installing mpmath (or any project you develop)?

python3 -m venv for-mpmath
. for-mpmath/bin/activate
git clone ...
cd mpmath
pip installl -e .[tests]

Just run everything from a cloned worktree, without installing - eventually will turn the project into the nightmare of bundled external libraries, as SymPy developers did (the mpmath is a notable exception, perhaps temporary). And working in this way, especially, is bad for development, when usually you want to test several environments (different CPython versions, PyPy, with or without optional requirements like gmpy, etc). So, I think that using virtual environments & installing is a must do scenario.

But in fact, you can do what you are trying, with a minimal setup:

I havent tested but I'd probably get the same error, if I just cloned the repository on the side and open it with my IDE (Pycharm), which will add it to the PYTHONPATH.

No. You will not get such an error (this was tested on pre-#446):

$ PYTHONPATH=src/mpmath python3
Python 3.7.2+ (default, Feb 27 2019, 15:41:59) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mpmath
>>> mpmath.__version__
'1.1.1.dev40+g1e80ccb'

I'd be happy to have it in the source again.

@fredrik-johansson, what does solve #446? @asmeurer didn't show here any case of the real problem. setuptools - is a kinda standard for python packaging, it's hard to see some python installation without setuptools. Example of @asmodehn fails due to trivial user error: running outside of the mpmath worktree with empty PYTHONPATH. I doubt, that you should encourage the bad practice of bundling mpmath (as user did in this example).

Now you have a static version in __init__.py and version in setup.py (a different one), thanks to #446. I think this - now a real problem. So, if you want to revert everything back, up to the ancient static version handling - just revert everything, related to the setup.py/setup.cfg from #422. I can do this for you. Should I? But, please, think a little. I believe - there was no issue at all (well, maybe we should better document something somewhere) and #446 should be reverted.

skirpichev avatar Mar 20 '19 10:03 skirpichev

@fredrik-johansson, obviously, this can be closed too.

skirpichev avatar Mar 26 '21 22:03 skirpichev