-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathsetup.py
113 lines (91 loc) · 3.28 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Setup script for the dataproc_templates package
It extends the bdist_egg command to allow renaming of the output .egg artifact.
Usage: `python setup.py bdist_egg --output=my-custom-artifact-name.egg`
"""
from typing import Optional
import shutil
import io
import os
import logging
from setuptools import setup, find_packages
from setuptools.command.bdist_egg import bdist_egg
class BdistEggCustomEggName(bdist_egg):
"""
Create an "egg" distrubution, optionally renaming the output .egg file
This custom command extends the bdist_egg command. It adds the
`--output` argument for specifying the name of the output .egg file.
If it's provided, the egg artifact is renamed after it's built.
"""
description: str = 'create an "egg" distrubution, optionally renaming the output .egg file'
user_options = [('output=', 'o', 'output file name')] + \
bdist_egg.user_options
def __init__(self, *args, **kwargs):
self.output: Optional[str] = None
super().__init__(*args, **kwargs)
def initialize_options(self):
"""Initialize command options"""
super().initialize_options()
self.output = None
def run(self):
"""
Run the command
First execute `bdist_egg` as usual. Then, rename the .egg file
if the `--output` argument was specified.
"""
super().run()
built_egg_path: str = self.get_outputs()[0]
if self.output is not None:
logging.info(
'Will rename output .egg file from %s to %s',
built_egg_path,
self.output
)
shutil.move(src=built_egg_path, dst=self.output)
dependencies = [
"pyspark>=3.2.0",
"google-cloud-bigquery>=3.4.0",
"google-cloud-secret-manager>=2.19.0"
]
package_root = os.path.abspath(os.path.dirname(__file__))
version = {}
with open(
os.path.join(package_root, "version.py")
) as fp:
exec(fp.read(), version)
version = version["__version__"]
readme_filename = os.path.join(package_root, "README.md")
with io.open(readme_filename, encoding="utf-8") as readme_file:
readme = readme_file.read()
setup(
name="google-dataproc-templates",
version=version,
description="Google Dataproc templates written in Python",
long_description_content_type="text/markdown",
long_description=readme,
license="Apache 2.0",
url="https://github.com/GoogleCloudPlatform/dataproc-templates",
packages=find_packages(exclude=['test']),
install_requires=dependencies,
# Override the bdist_egg command with our extension
cmdclass={
'bdist_egg': BdistEggCustomEggName
},
platforms="Posix; MacOS X; Windows",
python_requires=">=3.7"
)