mdawar / rq-exporter

Prometheus metrics exporter for Python RQ (Redis Queue).
MIT License
65 stars 28 forks source link

package in requirements.txt? #12

Closed labeneator closed 3 years ago

labeneator commented 3 years ago

Hi, I am adding rq-exporter to my dh-virtualenv package to enable it to be bundled into a deb. However, I'm getting build errors due to a missing requirements.txt. Could it be included please?

Please see the log below

Collecting rq-exporter
  Created temporary directory: /tmp/pip-unpack-zqh9eel1
  Looking up "https://files.pythonhosted.org/packages/9e/24/51c7a5c6182c09e80a1d7c033e25c7ec0636a56980bf6d73befb2b73e582/rq-exporter-1.7.0.tar.gz" in the cache
  Current age based on date: 1096
  Ignoring unknown cache-control directive: immutable
  Freshness lifetime from max-age: 365000000
  The response is "fresh", returning cached response
  365000000 > 1096
  Using cached rq-exporter-1.7.0.tar.gz (13 kB)
  Added rq-exporter from https://files.pythonhosted.org/packages/9e/24/51c7a5c6182c09e80a1d7c033e25c7ec0636a56980bf6d73befb2b73e582/rq-exporter-1.7.0.tar.gz#sha256=ba04d06995c1e8c80034e5a1338602698e4168947eb8b636db3faa5e02fd5890 (from -r ./requirements.txt (line 48)) to build tracker '/tmp/pip-req-tracker-bfed8oje'
    Running setup.py (path:/tmp/pip-install-sbgw6_s7/rq-exporter_5cb720af2376430982edde4deffb2779/setup.py) egg_info for package rq-exporter
    Created temporary directory: /tmp/pip-pip-egg-info-tkk93zi2
    Running command python setup.py egg_info
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-sbgw6_s7/rq-exporter_5cb720af2376430982edde4deffb2779/setup.py", line 19, in <module>
        with open(os.path.join(cwd, 'requirements.txt'), 'r') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-sbgw6_s7/rq-exporter_5cb720af2376430982edde4deffb2779/requirements.txt'
WARNING: Discarding https://files.pythonhosted.org/packages/9e/24/51c7a5c6182c09e80a1d7c033e25c7ec0636a56980bf6d73befb2b73e582/rq-exporter-1.7.0.tar.gz#sha256=ba04d06995c1e8c80034e5a1338602698e4168947eb8b636db3faa5e02fd5890 (from https://pypi.org/simple/rq-exporter/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Created temporary directory: /tmp/pip-unpack-hgngpqso
  Looking up "https://files.pythonhosted.org/packages/0b/74/23930e7273410a85f0cad92e6e5916f3d70a82b847d9401e7fd7b4c6f5f3/rq-exporter-1.6.0.tar.gz" in the cache
  No cache entry available
  Starting new HTTPS connection (1): files.pythonhosted.org:443
  https://files.pythonhosted.org:443 "GET /packages/0b/74/23930e7273410a85f0cad92e6e5916f3d70a82b847d9401e7fd7b4c6f5f3/rq-exporter-1.6.0.tar.gz HTTP/1.1" 200 13357
  Downloading rq-exporter-1.6.0.tar.gz (13 kB)
  Ignoring unknown cache-control directive: immutable
  Updating cache with response from "https://files.pythonhosted.org/packages/0b/74/23930e7273410a85f0cad92e6e5916f3d70a82b847d9401e7fd7b4c6f5f3/rq-exporter-1.6.0.tar.gz"
  Caching due to etag
  Added rq-exporter from https://files.pythonhosted.org/packages/0b/74/23930e7273410a85f0cad92e6e5916f3d70a82b847d9401e7fd7b4c6f5f3/rq-exporter-1.6.0.tar.gz#sha256=7e90bcbf5d9939ec33379788d3179136dd31ebb669e3aa265befcbffb76ce4e6 (from -r ./requirements.txt (line 48)) to build tracker '/tmp/pip-req-tracker-bfed8oje'
    Running setup.py (path:/tmp/pip-install-sbgw6_s7/rq-exporter_8aac3f9b0ecd44b7aa6b5d5b8f75fb3e/setup.py) egg_info for package rq-exporter
    Created temporary directory: /tmp/pip-pip-egg-info-ge3qcjgc
    Running command python setup.py egg_info
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-sbgw6_s7/rq-exporter_8aac3f9b0ecd44b7aa6b5d5b8f75fb3e/setup.py", line 19, in <module>
        with open(os.path.join(cwd, 'requirements.txt'), 'r') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-sbgw6_s7/rq-exporter_8aac3f9b0ecd44b7aa6b5d5b8f75fb3e/requirements.txt'
labeneator commented 3 years ago

Had a look at this again. I think the problem arises from these lines in setup.py

# Requirements
requirements = []
with open(os.path.join(cwd, 'requirements.txt'), 'r') as f:
    requirements = [l.strip() for l in f.readlines()]

That means that dh-virtualenv will try to read these lines when it tries to build the package. That may fail.

Additionally, the deps versions are baked in. Since this can be used as a library, it may interfere with other deps pulled in by other packages. As an example, I'm using prometheus client elsewhere in the project. The hard code for version 0.8.0 as per the requirements.txt file causes a downgrade.

❯❯❯ ./bin/pip  install setproctitle rq-exporter
Requirement already satisfied: setproctitle in /opt/venvs/project/lib/python3.7/site-packages (1.2.2)
Requirement already satisfied: rq-exporter in /opt/venvs/project/lib/python3.7/site-packages (1.7.0)
Requirement already satisfied: redis==3.5.3 in /opt/venvs/project/lib/python3.7/site-packages (from rq-exporter) (3.5.3)
Collecting prometheus-client==0.8.0
  Using cached prometheus_client-0.8.0-py2.py3-none-any.whl (53 kB)
Requirement already satisfied: rq==1.8.0 in /opt/venvs/project/lib/python3.7/site-packages (from rq-exporter) (1.8.0)
Requirement already satisfied: click>=5.0.0 in /opt/venvs/project/lib/python3.7/site-packages (from rq==1.8.0->rq-exporter) (7.1.2)
Installing collected packages: prometheus-client
  Attempting uninstall: prometheus-client
    Found existing installation: prometheus-client 0.10.1
    Uninstalling prometheus-client-0.10.1:
      Successfully uninstalled prometheus-client-0.10.1
Successfully installed prometheus-client-0.8.0

I believe the better solution is to state the minimum version acceptable for a dep and let the package manager figure it out as per: https://packaging.python.org/discussions/install-requires-vs-requirements/

Also, moving in the install deps directly into setup.py would fix the issue raised in this ticket

mdawar commented 3 years ago

Hi,

Thank you for reporting this issue and for submitting a fix, I prefer to keep the requirements in one file so I have fixed this issue and published a new version 1.8.0, please try it out and feel free to reopen this issue if you still have any problems.

Thank you again.