|
1 | | -#!/usr/bin/env python |
2 | | -# -*- coding: utf-8 -*- |
3 | | - |
4 | | -# Note: To use the 'upload' functionality of this file, you must: |
5 | | -# $ pip install twine |
6 | | - |
7 | | -import io, json |
8 | | -import os |
9 | | -import sys |
10 | | -import glob |
11 | | -from shutil import rmtree |
12 | | - |
13 | | -from setuptools import find_packages, setup, Command |
14 | | - |
15 | | - |
16 | | -def read(fname): |
17 | | - with open(fname, mode="r", encoding="utf-8") as f: |
18 | | - src = f.read() |
19 | | - return src |
20 | | - |
21 | | - |
22 | | -def package_files(package, directory): |
23 | | - os.chdir(package) |
24 | | - paths = glob.glob(directory + "/**", recursive=True) |
25 | | - os.chdir("..") |
26 | | - return paths |
27 | | - |
28 | | - |
29 | | -codemeta_json = "codemeta.json" |
30 | | - |
31 | | -# Let's pickup as much metadata as we need from codemeta.json |
32 | | -with open(codemeta_json, mode="r", encoding="utf-8") as f: |
33 | | - src = f.read() |
34 | | - meta = json.loads(src) |
35 | | - |
36 | | -# Let's make our symvar string |
37 | | -version = meta["version"] |
38 | | - |
39 | | -# Now we need to pull and format our author, author_email strings. |
40 | | -author = "" |
41 | | -author_email = "" |
42 | | -for obj in meta["author"]: |
43 | | - given = obj.get("givenName", "") |
44 | | - family = obj.get("familyName", "") |
45 | | - email = obj.get("email", "") |
46 | | - if len(author) == 0: |
47 | | - author = given + " " + family |
48 | | - else: |
49 | | - author = author + ", " + given + " " + family |
50 | | - if len(author_email) == 0: |
51 | | - author_email = email |
52 | | - else: |
53 | | - author_email = author_email + ", " + email |
54 | | -description = meta["description"] |
55 | | -url = meta["codeRepository"] |
56 | | -download = meta["downloadUrl"] |
57 | | -license = meta["license"] |
58 | | -name = meta["name"] |
59 | | - |
60 | | -REQUIRES_PYTHON = ">=3.6.0" |
61 | | - |
62 | | -# What packages are required for this module to be executed? |
63 | | -REQUIRED = [ |
64 | | - "requests", |
65 | | - "datacite>1.1.0", |
66 | | - "tqdm>=4.62.3", |
67 | | - "pyyaml", |
68 | | - "s3fs", |
69 | | - "cryptography", |
70 | | - "s3cmd", |
71 | | -] |
72 | | - |
73 | | -# What packages are optional? |
74 | | -EXTRAS = { |
75 | | - # 'fancy feature': ['django'], |
76 | | -} |
77 | | - |
78 | | -files = package_files("caltechdata_api", "vocabularies") |
79 | | -files.append("vocabularies.yaml") |
80 | | - |
81 | | -# The rest you shouldn't have to touch too much :) |
82 | | -# ------------------------------------------------ |
83 | | -# Except, perhaps the License and Trove Classifiers! |
84 | | -# If you do change the License, remember to change the Trove Classifier for that! |
85 | | - |
86 | | -here = os.path.abspath(os.path.dirname(__file__)) |
87 | | - |
88 | | -# Import the README and use it as the long-description. |
89 | | -# Note: this will only work if 'README.md' is present in your MANIFEST.in file! |
90 | | -try: |
91 | | - with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f: |
92 | | - long_description = "\n" + f.read() |
93 | | -except FileNotFoundError: |
94 | | - long_description = description |
95 | | - |
96 | | -# Load the package's __version__.py module as a dictionary. |
97 | | -about = {} |
98 | | -if not version: |
99 | | - with open(os.path.join(here, NAME, "__version__.py")) as f: |
100 | | - exec(f.read(), about) |
101 | | -else: |
102 | | - about["__version__"] = version |
103 | | - |
104 | | - |
105 | | -class UploadCommand(Command): |
106 | | - """Support setup.py upload.""" |
107 | | - |
108 | | - description = "Build and publish the package." |
109 | | - user_options = [] |
110 | | - |
111 | | - @staticmethod |
112 | | - def status(s): |
113 | | - """Prints things in bold.""" |
114 | | - print("\033[1m{0}\033[0m".format(s)) |
115 | | - |
116 | | - def initialize_options(self): |
117 | | - pass |
118 | | - |
119 | | - def finalize_options(self): |
120 | | - pass |
121 | | - |
122 | | - def run(self): |
123 | | - try: |
124 | | - self.status("Removing previous builds…") |
125 | | - rmtree(os.path.join(here, "dist")) |
126 | | - except OSError: |
127 | | - pass |
128 | | - |
129 | | - self.status("Building Source and Wheel distribution…") |
130 | | - os.system("{0} setup.py sdist bdist_wheel ".format(sys.executable)) |
131 | | - |
132 | | - self.status("Uploading the package to PyPI via Twine…") |
133 | | - os.system("twine upload dist/*") |
134 | | - |
135 | | - sys.exit() |
136 | | - |
137 | | - |
138 | | -# Where the magic happens: |
139 | | -setup( |
140 | | - name=name, |
141 | | - version=about["__version__"], |
142 | | - description=description, |
143 | | - long_description=long_description, |
144 | | - long_description_content_type="text/markdown", |
145 | | - author=author, |
146 | | - author_email=author_email, |
147 | | - python_requires=REQUIRES_PYTHON, |
148 | | - url=url, |
149 | | - packages=find_packages(exclude=("tests",)), |
150 | | - # If your package is a single module, use this instead of 'packages': |
151 | | - # py_modules=['mypackage'], |
152 | | - # entry_points={ |
153 | | - # 'console_scripts': ['mycli=mymodule:cli'], |
154 | | - # }, |
155 | | - install_requires=REQUIRED, |
156 | | - extras_require=EXTRAS, |
157 | | - include_package_data=True, |
158 | | - package_data={name: files}, |
159 | | - license=license, |
160 | | - classifiers=[ |
161 | | - # Trove classifiers |
162 | | - # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers |
163 | | - "License :: OSI Approved :: BSD License", |
164 | | - "Programming Language :: Python", |
165 | | - "Programming Language :: Python :: 3", |
166 | | - "Programming Language :: Python :: 3.7", |
167 | | - "Programming Language :: Python :: Implementation :: CPython", |
168 | | - "Programming Language :: Python :: Implementation :: PyPy", |
169 | | - ], |
170 | | - # $ setup.py publish support. |
171 | | - cmdclass={ |
172 | | - "upload": UploadCommand, |
173 | | - }, |
174 | | - entry_points={ |
175 | | - "console_scripts": [ |
176 | | - "caltechdata_api=caltechdata_api.cli:main", |
177 | | - ], |
178 | | - }, |
179 | | -) |
| 1 | +from setuptools import setup |
| 2 | +setup() |
0 commit comments