Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python 

2import os.path 

3import errno 

4import urllib.request 

5from setuptools import setup 

6 

7 

8version = "0.1.0" 

9with open("./python/lsst/daf/butler/version.py", "w") as f: 

10 print(f""" 

11__all__ = ("__version__", ) 

12__version__='{version}'""", file=f) 

13 

14# The purpose of this setup.py is to build enough of the system to 

15# allow testing. Not to distribute on PyPI. 

16# One impediment is the dependency on lsst.utils. 

17# if that package is missing we download the two files we need 

18# and include them in our distribution 

19urls = {} 

20try: 

21 import lsst.utils # noqa: F401 

22except ImportError: 

23 urls = {"doImport.py": 

24 "https://raw.githubusercontent.com/lsst/utils/master/python/lsst/utils/doImport.py", 

25 "tests.py": 

26 "https://raw.githubusercontent.com/lsst/utils/master/python/lsst/utils/tests.py"} 

27 

28if urls: 

29 utils_dir = "python/lsst/utils" 

30 if not os.path.exists(utils_dir): 

31 try: 

32 os.makedirs(utils_dir) 

33 except OSError as e: 

34 # Don't fail if directory exists due to race 

35 if e.errno != errno.EEXIST: 

36 raise e 

37 failed = False 

38 for file, url in urls.items(): 

39 outpath = os.path.join(utils_dir, file) 

40 # Do not redownload if the file is there 

41 if os.path.exists(outpath): 

42 continue 

43 try: 

44 contents = urllib.request.urlopen(url).read() 

45 print(f"Successfully read from {url}: {len(contents)} bytes ({type(contents)})") 

46 if isinstance(contents, bytes): 

47 contents = contents.decode() 

48 except Exception as e: 

49 print(f"Unable to download url {url}: {e}") 

50 failed = True 

51 else: 

52 with open(outpath, "w") as fh: 

53 print(contents, file=fh) 

54 # Write a simple __init__.py 

55 if not failed: 

56 init_path = os.path.join(utils_dir, "__init__.py") 

57 if not os.path.exists(init_path): 

58 with open(init_path, "w") as fh: 

59 print("from .doImport import *", file=fh) 

60 

61# read the contents of our README file 

62this_directory = os.path.abspath(os.path.dirname(__file__)) 

63with open(os.path.join(this_directory, "README.md"), encoding='utf-8') as f: 

64 long_description = f.read() 

65 

66setup( 

67 version=f"{version}", 

68 long_description=long_description, 

69 long_description_content_type="text/markdown" 

70)