Skip to content

Commit

Permalink
Move __version__ into __init__.py
Browse files Browse the repository at this point in the history
A little bit of clean parsing code in setup.py and the enforcement
from `black`, and it becomes possible to ditch a file which only held
a single value. Similarly update the version parsing in the makefile.
  • Loading branch information
sirosen committed Jul 16, 2022
1 parent a669131 commit 908cc6f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: lint test docs build release clean

NOSE2_VERSION=$(shell grep '^__version__' nose2/_version.py | cut -d '"' -f2)
NOSE2_VERSION=$(shell grep '^__version__' nose2/__init__.py | cut -d '"' -f2)

lint:
tox -e lint
Expand Down
3 changes: 2 additions & 1 deletion nose2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from nose2._version import __version__
from nose2.main import discover, main

__version__ = "0.12.0"

__all__ = ("__version__", "discover", "main")
7 changes: 0 additions & 7 deletions nose2/_version.py

This file was deleted.

15 changes: 13 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import os
import re

from setuptools import find_packages, setup

VERSION = open("nose2/_version.py").readlines()[-1].split()[-1].strip("\"'")

def read_version(filename):
# use of " over ' will be enforced by "black"
version_pattern = re.compile(r'__version__ = "([^"]*)"')
with open(filename) as fp:
for line in fp:
m = version_pattern.match(line)
if m:
return m.group(1)
raise Exception("could not parse version from {}".format(filename))


MAINTAINER = "Stephen Rosen"
MAINTAINER_EMAIL = "[email protected]"
Expand All @@ -11,7 +22,7 @@

setup(
name="nose2",
version=VERSION,
version=read_version("nose2/__init__.py"),
packages=find_packages(),
extras_require={
"coverage_plugin": ["coverage"],
Expand Down

0 comments on commit 908cc6f

Please sign in to comment.