Browse Source

update setup.py to work with hg or git

tags/v2019.9.0
adam j hartz 1 year ago
parent
commit
3cf0127d72
5 changed files with 70 additions and 29 deletions
  1. +1
    -1
      .hgignore
  2. +2
    -1
      MANIFEST.in
  3. +3
    -3
      catsoop/main.py
  4. +58
    -21
      setup.py
  5. +6
    -3
      website/preload.py

+ 1
- 1
.hgignore View File

@@ -1,7 +1,7 @@
syntax:glob

# Git hash from installing
catsoop/dev.githash
catsoop/dev.hash

# Byte-compiled / optimized / DLL files
__pycache__/


+ 2
- 1
MANIFEST.in View File

@@ -3,6 +3,7 @@ recursive-include catsoop/__HANDLERS__ *
recursive-include catsoop/__QTYPES__ *
recursive-include catsoop/__STATIC__ *
recursive-include catsoop/__UTIL__ *
include README
include LICENSE
include requirements.txt
include catsoop/dev.githash
include catsoop/dev.hash

+ 3
- 3
catsoop/main.py View File

@@ -29,12 +29,12 @@ def command_line_interface(args=None, arglist=None):

version = pkg_resources.require("catsoop")[0].version
if "dev" in version:
gitfile = os.path.join(os.path.dirname(__file__), "dev.githash")
gitfile = os.path.join(os.path.dirname(__file__), "dev.hash")
if os.path.isfile(gitfile):
with open(gitfile, "r") as f:
try:
hash_, date = f.read().split("|")
version = "%s\nGit revision: %s\n%s" % (version, hash_, date)
vcs, hash_, date = f.read().split("|")
version = "%s\n%s revision: %s\n%s" % (version, vcs, hash_, date)
except:
pass



+ 58
- 21
setup.py View File

@@ -41,13 +41,7 @@ VERSION_FNAME = os.path.join(os.path.dirname(__file__), "catsoop", "__init__.py"
ORIGINAL_VERSION = None


def dirty_version():
"""
If install/sdist is run from a git directory, add a devN suffix to reported
version number and write a gitignored file that holds the git hash of the
current state of the repo.
"""
global CS_VERSION, ORIGINAL_VERSION
def dev_number_git():
try:
last_version = subprocess.check_output(
["git", "describe", "--tags", "--match", "v*"]
@@ -61,24 +55,68 @@ def dirty_version():
except ValueError: # tag name may contain "-"
print("failed to parse git version", file=sys.stderr)
return

# if we get to this point, we are not at a particular tag. we'll modify
# the __version__ from catsoop/__init__.py to include a .devN suffix.
sha = sha.lstrip("g")
CS_VERSION = CS_VERSION + ".dev%s" % (N,)
_cmd = ["git", "show", "-s", "--format=%cD", sha]
try:
_cmd = ["git", "show", "-s", "--format=%cD", sha]
_date = subprocess.check_output(_cmd)
_date = _date.decode("ascii")
# remove weekday name for a shorter string
_date = "".join(_date.split(" ", 1)[1:])
except:
_date = ""
print("failed to get commit date", file=sys.stderr)
with open(
os.path.join(os.path.dirname(__file__), "catsoop", "dev.githash"), "w"
) as f:
f.write("{}|{}".format(sha, _date))
print("failed to get git commit date", file=sys.stderr)
return ("Git", sha, N, _date)


def _version_sort(x):
return tuple(map(int, x[1:].split("."))) if x.startswith("v") else (float("-inf"),)


def dev_number_hg():
try:
tags = subprocess.check_output(["hg", "tags"]).decode("ascii")
tags = dict(i.strip().split() for i in tags.splitlines())
tags = {k: v.split(":") for k, v in tags.items()}
except Exception:
print("failed to find hg tags", file=sys.stderr)
raise
return
sha = tags["tip"][1]
N = int(tags["tip"][0]) - int(tags[max(tags, key=_version_sort)][0])
if N == 0:
return
try:
_cmd = ["hg", "log", "-r", "tip"]
_info = subprocess.check_output(_cmd).decode("ascii")
_info = dict(i.strip().split(" ", 1) for i in _info.strip().splitlines())
_date = _info["date:"].strip()
except Exception:
_date = ""
print("failed to get hg commit date", file=sys.stderr)
return ("Mercurial", sha, N, _date)


def dev_number():
return dev_number_hg() or dev_number_git()


def dirty_version():
"""
If install/sdist is run from a git directory, add a devN suffix to reported
version number and write an ignored file that holds info about the current
state of the repo.
"""
global CS_VERSION, ORIGINAL_VERSION

dev_num = dev_number()
if not dev_num:
return
vcs, sha, N, _date = dev_num

# if we get to this point, we are not at a particular tag. we'll modify
# the __version__ from catsoop/__init__.py to include a .devN suffix.
sha = sha.lstrip("g")
CS_VERSION = CS_VERSION + ".dev%s" % (N,)
with open(os.path.join(os.path.dirname(__file__), "catsoop", "dev.hash"), "w") as f:
f.write("{}|{}|{}".format(vcs, sha, _date))
with open(VERSION_FNAME, "r") as f:
ORIGINAL_VERSION = f.read()
with open(VERSION_FNAME, "w") as f:
@@ -112,11 +150,10 @@ def main():
"catsoop.scripts",
],
scripts=[],
url="https://catsoop.mit.edu",
url="https://catsoop.org",
license="AGPLv3+",
description="CAT-SOOP is a tool for automatic collection and assessment of online exercises.",
long_description=readme,
long_description_content_type="text/markdown",
include_package_data=True,
entry_points={
"console_scripts": ["catsoop = catsoop.main:command_line_interface"]


+ 6
- 3
website/preload.py View File

@@ -1,7 +1,10 @@
cs_auth_required = False
cs_long_name = "CAT-SOOP Website"

TOR_STRING = lambda n: ('torsocks %s' % n) if 'onion' in cs_url_root else n
TOR_STRING = lambda n: ("torsocks %s" % n) if "onion" in cs_url_root else n

cs_footer = """<a href="http://creativecommons.org/licenses/by-sa/4.0/" rel="license"><img alt="Creative Commons License" src="COURSE/cc-by-sa.png" style="border-width:0"></a><br/>The contents of this page are Copyright &copy; 2016-2019 by the CAT-SOOP Developers.<br/>They are licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.<br/>The original form of this web site is source code in the CAT-SOOP specification
format.<br/>The source code is available in the Mercurial repository at <a href="/repo/catsoop">%s/repo/catsoop</a>.<br/><hr width="300" style="background-color:#000000;border-color:#000000" />""" % cs_url_root
cs_footer = (
"""<a href="http://creativecommons.org/licenses/by-sa/4.0/" rel="license"><img alt="Creative Commons License" src="COURSE/cc-by-sa.png" style="border-width:0"></a><br/>The contents of this page are Copyright &copy; 2016-2019 by the CAT-SOOP Developers.<br/>They are licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.<br/>The original form of this web site is source code in the CAT-SOOP specification
format.<br/>The source code is available in the Mercurial repository at <a href="/repo/catsoop">%s/repo/catsoop</a>.<br/><hr width="300" style="background-color:#000000;border-color:#000000" />"""
% cs_url_root
)

Loading…
Cancel
Save