Skip to content

Conversation

@2-5
Copy link
Contributor

@2-5 2-5 commented Oct 10, 2014

Added version attr to package so that scripts that check local
packages to see if newer versions are available can work.

Almost all Python packages have a version attr, and the vast majority of
them name it "version"

Added __version__ attr to package so that scripts that check local
packages to see if newer versions are available can work.

Almost all Python packages have a version attr, and the vast majority of
them name it "__version__"
@sigmavirus24
Copy link
Member

Alternatively you can simply use setuptools/distutils to do this. The metadata should be provided when you install the package. This seems like an unnecessary duplication

@sigmavirus24
Copy link
Member

5 of those are exactly the same and work under the same conditions (pip, setuptools, wheel, OS package manager, manual installation via python setup.py install). The fact is that using pkg_resources.working_set is almost certainly going to be more reliable than checking for a module level attribute that's not necessary. The only thing this might not cover is if you're manually copying and pasting the files into the directories. I haven't tested it, but I suspect conda + pkg_resources will work just fine. And the more dependencies you run into, the more you will find modules without a version attribute so you should just be using the packaging tools provided to you instead of writing fragile scripts to do this.

@sigmavirus24
Copy link
Member

Further, even if we wanted to add this attribute, we would then have the version declared in two places and one or the other would be guaranteed to fall out of sync and in all likelihood it would be the __version__ attribute you've created meaning your script would always tell you an update was available.

@2-5
Copy link
Contributor Author

2-5 commented Oct 10, 2014

By manual installation I meant unzipping the package in the right place, not setup.py install

Some projects do this in setup.py:

  import certifi
  VERSION = certifi.__version__

Others generate a certifi/version.py file when setup.py is run with __version__ in it and import that from certifi/__init__.py:

  from certifi.version import __version__

__version__ itself can be generated itself from git describe --tags for example

@sigmavirus24
Copy link
Member

By manual installation I meant unzipping the package in the right place, not setup.py install

Yeah. Don't do that.

Some projects do this in setup.py:

Except that is very fragile. Import errors could then easily trigger a failure to install the package.

Others generate a certifi/version.py file when setup.py is run with version in it and import that from certifi/init.py:

We could certainly generate a certifi/version.py file but there's no way we're going to break the package in the case where we cannot create the file during installation. If we do that, then there's no way to use certifi without an import error. In other words, we could create a version.py file on install but we're not going to auto-import it for anyone. Anyone who wants to use it will need to do from certifi.version import __version__.

The other thing is to note the fact that certifi carries no metadata on the module itself. There's no precedent for adding this except to allow users of bad practice to continue using their bad practices.

@kennethreitz
Copy link
Contributor

Requests has always had __version__/

@Lukasa Lukasa merged commit 27d76ef into certifi:master May 17, 2015
@Lukasa
Copy link
Member

Lukasa commented May 17, 2015

This is really not worth arguing about. =) I merged this by hand so I could update the __version__ attribute to the latest release. Thanks @adalq! 🍰 ✨ 🍪

@Lukasa
Copy link
Member

Lukasa commented May 17, 2015

To be clear, you won't actually find this in certifi until we push a new release. I'm going to be avoiding pushing updates to certifi unless the bundle actually changes, to avoid panicking people. =)

@2-5 2-5 deleted the version branch October 17, 2015 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants