AbdealiLoKo / pytest-attrib

A pytest plugin that mimics the working of nose-attrib
MIT License
3 stars 1 forks source link

Importing from package during installation causes failure #5

Closed jayvdb closed 8 years ago

jayvdb commented 8 years ago

setup.py should never import from the package it is installing. i.e. do not do this:

from pytest_attrib import __version__

An example of one of the problems it can cause: https://ci.appveyor.com/project/wikimedia/pywikibot-core/build/job/k3qjk8ygkdw99lj1

A simple approach that I quite like for small packages like this is https://github.com/legoktm/jsonchecker/commit/5afe98dd5c9cc1f68655edae02570306dd157e4b

AbdealiLoKo commented 8 years ago

Agree, this is bad coding mainly because I was lazy. I don't like the method done by legoktm in jsonchecker very much either, because it parses a file. (Which I find hacky) I've made my own solution, a VERSION file which just contains the version number. So I'm using that.

jayvdb commented 8 years ago

This is still broken, only now broken worse than before, as it no longer works on Travis. https://travis-ci.org/jayvdb/pywikibot-core/jobs/132423013

Golden rule: never import your own modules/packages in the setup.py.

AbdealiLoKo commented 8 years ago

Fixed it now. made a dev package 0.1.3.dev0 to test it too. Here is a successful pywikibot-core travis build which uses this dev package https://travis-ci.org/AbdealiJK/pywikibot-core/jobs/132529624 where the installation worked. I'll be making 0.1.3 next to fix this after a bit more testing to ensure this doesn't happen again.

AbdealiLoKo commented 8 years ago

I've added an extra step in the CI which actually created the sdist and also installs the package from the sdist to test it out. So, hopefully this will never regress again.

This is done on appveyor and travis

jayvdb commented 8 years ago

I see you are still importing pytest_attrib . IIRC, this will fail with older versions of setuptools and pip. You will definitely find that you have stale imports at times. http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-stale-bytecode-file-trap Anyway, one way to learn is to do .. the school of hard knocks.

AbdealiLoKo commented 8 years ago

:3 Sorry It's just that I find this a more "neater" solution that parsing source code.

On your suggestion I tested it with pip==6.0 and setuptools==5.5.1 and it seemed to work:

$ python -c "import pip; print pip.__version__"
6.0
$ python -c "import setuptools; print setuptools.__version__"
5.5.1
$ pip install pytest-attrib
You are using pip version 6.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pytest-attrib
  Using cached pytest-attrib-0.1.3.tar.gz
Requirement already satisfied (use --upgrade to upgrade): pytest>=2.2 in /home/ajk/Documents/wiki/venv/lib/python2.7/site-packages (from pytest-attrib)
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.29 in /home/ajk/Documents/wiki/venv/lib/python2.7/site-packages (from pytest>=2.2->pytest-attrib)
Installing collected packages: pytest-attrib
  Running setup.py install for pytest-attrib
Successfully installed pytest-attrib

Both of which came out ~2014. I think that's old enough ^^

jayvdb commented 8 years ago

This is still what people use: http://packages.ubuntu.com/search?suite=precise&searchon=names&keywords=python-pip http://packages.ubuntu.com/search?suite=precise&searchon=names&keywords=python-setuptools

AbdealiLoKo commented 8 years ago

Sigh ... sometimes I hate those LTS releases ...

Anyway, it works with pip==1.0 and setuptools==0.6rc11 too. (I had to use setuptools rc11 because 0.6.24 isn't in pip and pip==1.0 doesnt have __version__ so i can't print that...)

$ python -c "import setuptools; print setuptools.__version__"
0.6c11
$ pip install pytest-attrib
Downloading/unpacking pytest-attrib
  Downloading pytest-attrib-0.1.3.tar.gz
  Running setup.py egg_info for package pytest-attrib

Downloading/unpacking pytest>=2.2 (from pytest-attrib)
  Downloading pytest-2.9.1.tar.gz (700Kb): 700Kb downloaded
  Running setup.py egg_info for package pytest

    warning: no previously-included files found matching '_pytest/impl'
    warning: no previously-included files matching '*.pyc' found under directory '*'
    warning: no previously-included files matching '*.pyo' found under directory '*'
    warning: no previously-included files found matching 'appveyor/install.ps1'
    warning: no previously-included files found matching 'appveyor.yml'
    warning: no previously-included files found matching 'appveyor'
    warning: no previously-included files found matching 'ISSUES.txt'
    warning: no previously-included files found matching 'HOWTORELEASE.rst'
Downloading/unpacking py>=1.4.29 (from pytest>=2.2->pytest-attrib)
  Downloading py-1.4.31.tar.gz (192Kb): 192Kb downloaded
  Running setup.py egg_info for package py

Installing collected packages: pytest-attrib, pytest, py
  Running setup.py install for pytest-attrib

  Running setup.py install for pytest

    warning: no previously-included files found matching '_pytest/impl'
    warning: no previously-included files matching '*.pyc' found under directory '*'
    warning: no previously-included files matching '*.pyo' found under directory '*'
    warning: no previously-included files found matching 'appveyor/install.ps1'
    warning: no previously-included files found matching 'appveyor.yml'
    warning: no previously-included files found matching 'appveyor'
    warning: no previously-included files found matching 'ISSUES.txt'
    warning: no previously-included files found matching 'HOWTORELEASE.rst'
    Installing py.test script to /home/ajk/Documents/wiki/venv/bin
    Installing py.test-2.7 script to /home/ajk/Documents/wiki/venv/bin
  Running setup.py install for py

Successfully installed pytest-attrib pytest py
Cleaning up...
$ python -c "import pytest_attrib; print pytest_attrib.__version__"
0.1.3