summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-21 15:21:43 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-21 15:21:43 -0400
commit2147523a89156236a3f70c2ac70e2c8304e295f3 (patch)
treec837cab0272dbaa5fb12471c14f3ca18fee3d3fa
downloadpurge_path-2147523a89156236a3f70c2ac70e2c8304e295f3.tar.gz
Initial commit
-rw-r--r--.gitignore2
-rw-r--r--LICENSE.txt27
-rw-r--r--purge_path/__init__.py0
-rw-r--r--purge_path/extern/__init__.py0
-rw-r--r--purge_path/extern/version.py114
-rwxr-xr-xpurge_path/purge_path.py16
-rw-r--r--setup.py42
7 files changed, 201 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9fccfcd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*__pycache__*
+*.swp
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..17dbf64
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,27 @@
+Copyright (c) 2015, Joseph Hunkeler
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of [project] nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/purge_path/__init__.py b/purge_path/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/purge_path/__init__.py
diff --git a/purge_path/extern/__init__.py b/purge_path/extern/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/purge_path/extern/__init__.py
diff --git a/purge_path/extern/version.py b/purge_path/extern/version.py
new file mode 100644
index 0000000..8e775c6
--- /dev/null
+++ b/purge_path/extern/version.py
@@ -0,0 +1,114 @@
+# -*- coding: utf-8 -*-
+# Author: Douglas Creager <dcreager@dcreager.net>
+# This file is placed into the public domain.
+
+# Calculates the current version number. If possible, this is the
+# output of “git describe”, modified to conform to the versioning
+# scheme that setuptools uses. If “git describe” returns an error
+# (most likely because we're in an unpacked copy of a release tarball,
+# rather than in a git working copy), then we fall back on reading the
+# contents of the RELEASE-VERSION file.
+#
+# To use this script, simply import it your setup.py file, and use the
+# results of get_git_version() as your package version:
+#
+# from version import *
+#
+# setup(
+# version=get_git_version(),
+# .
+# .
+# .
+# )
+#
+# This will automatically update the RELEASE-VERSION file, if
+# necessary. Note that the RELEASE-VERSION file should *not* be
+# checked into git; please add it to your top-level .gitignore file.
+#
+# You'll probably want to distribute the RELEASE-VERSION file in your
+# sdist tarballs; to do this, just create a MANIFEST.in file that
+# contains the following line:
+#
+# include RELEASE-VERSION
+from __future__ import print_function
+from subprocess import Popen, PIPE
+import sys
+
+__all__ = ("get_git_version")
+
+PY3 = sys.version_info[0] == 3
+
+
+def call_git_describe(abbrev=4):
+ line = ''
+ try:
+ p = Popen(['git', 'describe', '--abbrev=%d' % abbrev],
+ stdout=PIPE, stderr=PIPE)
+ p.stderr.close()
+ if PY3:
+ line = p.stdout.readlines()[0].decode()
+ else:
+ line = p.stdout.readlines()[0]
+ return line.strip()
+
+ except:
+ return None
+
+
+def read_release_version():
+ try:
+ f = open("RELEASE-VERSION", "r")
+
+ try:
+ if PY3:
+ version = f.readlines()[0].decode()
+ else:
+ version = f.readlines()[0]
+ return version.strip()
+
+ finally:
+ f.close()
+
+ except:
+ return None
+
+
+def write_release_version(version):
+ f = open("RELEASE-VERSION", "w")
+ f.write("%s\n" % version)
+ f.close()
+
+
+def get_git_version(abbrev=4):
+ # Read in the version that's currently in RELEASE-VERSION.
+
+ release_version = read_release_version()
+
+ # First try to get the current version using “git describe”.
+
+ version = call_git_describe(abbrev)
+
+ # If that doesn't work, fall back on the value that's in
+ # RELEASE-VERSION.
+
+ if version is None:
+ version = release_version
+
+ # If we still don't have anything, that's an error.
+
+ if version is None:
+ raise ValueError("Cannot find the version number!")
+
+ # If the current version is different from what's in the
+ # RELEASE-VERSION file, update the file to be current.
+
+ if version != release_version:
+ write_release_version(version)
+
+ # Finally, return the current version.
+
+ return version
+
+
+if __name__ == "__main__":
+ print(get_git_version())
diff --git a/purge_path/purge_path.py b/purge_path/purge_path.py
new file mode 100755
index 0000000..b752da4
--- /dev/null
+++ b/purge_path/purge_path.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ in '__main__':
+ ARGS = sys.argv[1:]
+ PATH = os.environ['PATH']
+ PATH_NEW = []
+
+ for arg in ARGS:
+ for path in PATH.split(':'):
+ if arg in path:
+ continue
+ PATH_NEW.append(path)
+
+ print("{0}".format(":".join(PATH_NEW)))
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..cf3f9fe
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,42 @@
+import os
+from setuptools import setup, find_packages
+from purge_path.extern.version import get_git_version
+
+entry_points = {}
+package_data = {}
+
+entry_points['console_scripts'] = [
+ 'purge_path = purge_path:main',
+]
+
+package_data[''] = ['*.txt', '*.md']
+version_py = os.path.join('purge_path', 'version.py')
+
+#Omit git hash and let setuptools add a valid build number
+git_version = get_git_version()
+if git_version.rfind('-') != -1:
+ git_version = git_version[:git_version.rfind('-')]
+
+
+with open(version_py, 'w+') as version_data:
+ version_data.write('__version__ = "{0}"\n'.format(git_version))
+
+NAME = 'purge_path'
+VERSION = git_version
+
+setup(
+ name=NAME,
+ version=VERSION,
+ description='A small PATH manipulator',
+ requires=[''],
+ provides=[NAME],
+ author='Joseph Hunkeler',
+ author_email='jhunk@stsci.edu',
+ license='BSD',
+ url='http://bitbucket.org/jhunkeler/purge_path',
+ download_url='',
+ use_2to3=True,
+ packages=find_packages(),
+ entry_points=entry_points,
+ package_data=package_data,
+)