setup.py: black and otherwise s/'/"/g pass

This commit is contained in:
Athanasius 2022-03-12 14:10:41 +00:00
parent 3cf7b765fb
commit 20d784ae09

142
setup.py
View File

@ -21,14 +21,14 @@ try:
verstr = mo.group(1) verstr = mo.group(1)
except EnvironmentError: except EnvironmentError:
print(f'unable to find version in {VERSIONFILE}') print(f"unable to find version in {VERSIONFILE}")
raise RuntimeError(f'if {VERSIONFILE} exists, it is required to be well-formed') raise RuntimeError(f"if {VERSIONFILE} exists, it is required to be well-formed")
# Read environment-specific settings # Read environment-specific settings
########################################################################### ###########################################################################
# Enforce the git status being "branch 'live' checked out, at its HEAD" # Enforce the git status being "branch "live" checked out, at its HEAD"
# if setup_env.py says this is the live environment. # if setup_env.py says this is the live environment.
# #
# The idea is to have the `live` branch, *which includes documentation* # The idea is to have the `live` branch, *which includes documentation*
@ -39,13 +39,11 @@ except EnvironmentError:
########################################################################### ###########################################################################
cwd = os.getcwd() cwd = os.getcwd()
# e.g. /home/eddn/live/EDDN.git # e.g. /home/eddn/live/EDDN.git
if setup_env.EDDN_ENV == 'live': if setup_env.EDDN_ENV == "live":
try: try:
git_cmd = subprocess.Popen( git_cmd = subprocess.Popen(
'git symbolic-ref -q --short HEAD'.split(), "git symbolic-ref -q --short HEAD".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
) )
out, err = git_cmd.communicate() out, err = git_cmd.communicate()
@ -53,47 +51,37 @@ if setup_env.EDDN_ENV == 'live':
print(f"Couldn't run git command to check branch: {e}") print(f"Couldn't run git command to check branch: {e}")
else: else:
branch = out.decode().rstrip('\n') branch = out.decode().rstrip("\n")
# - For any other branch checked out at its HEAD this will be a # - For any other branch checked out at its HEAD this will be a
# different name. # different name.
# - For any 'detached HEAD' (i.e. specific commit ID, or tag) it # - For any "detached HEAD" (i.e. specific commit ID, or tag) it
# will be empty. # will be empty.
if branch != 'live': if branch != "live":
print(f"EDDN_ENV is '{setup_env.EDDN_ENV}' (and CWD is '{cwd}'), but branch is '{branch}', aborting!") print(f"EDDN_ENV is '{setup_env.EDDN_ENV}' (and CWD is '{cwd}'), but branch is '{branch}', aborting!")
sys.exit(-1) sys.exit(-1)
########################################################################### ###########################################################################
# Location of start-eddn-service script and its config file # Location of start-eddn-service script and its config file
START_SCRIPT_BIN = pathlib.Path(f'{os.environ["HOME"]}/.local/bin') START_SCRIPT_BIN = pathlib.Path(f"{os.environ['HOME']}/.local/bin")
# Location of web files # Location of web files
SHARE_EDDN_FILES = pathlib.Path(f'{os.environ["HOME"]}/.local/share/eddn/{setup_env.EDDN_ENV}') SHARE_EDDN_FILES = pathlib.Path(f"{os.environ['HOME']}/.local/share/eddn/{setup_env.EDDN_ENV}")
setup( setup(
name='eddn', name="eddn",
version=verstr, version=verstr,
description='Elite: Dangerous Data Network', description="Elite: Dangerous Data Network",
long_description="""\ long_description="""\
The Elite Dangerous Data Network allows ED players to share data. Not affiliated with Frontier Developments. The Elite Dangerous Data Network allows ED players to share data. Not affiliated with Frontier Developments.
""", """,
author='EDCD (https://edcd.github.io/)', author="EDCD (https://edcd.github.io/)",
author_email='edcd@miggy.org', author_email="edcd@miggy.org",
url='https://github.com/EDCD/EDDN', url="https://github.com/EDCD/EDDN",
packages=find_packages("src", exclude=["*.tests"]),
packages=find_packages( package_dir={"": "src"},
'src',
exclude=["*.tests"]
),
package_dir={'': 'src'},
# This includes them for the running code, but that doesn't help # This includes them for the running code, but that doesn't help
# serve them up for reference. # serve them up for reference.
data_files=[ data_files=[("eddn/schemas", glob.glob("schemas/*.json"))],
(
'eddn/schemas', glob.glob("schemas/*.json")
)
],
# Yes, we pin versions. With python2.7 the latest pyzmq will NOT # Yes, we pin versions. With python2.7 the latest pyzmq will NOT
# work, for instance. # work, for instance.
install_requires=[ install_requires=[
@ -104,26 +92,25 @@ setup(
"jsonschema", "jsonschema",
"pyzmq", "pyzmq",
"simplejson", "simplejson",
"mysql-connector-python" "mysql-connector-python",
], ],
entry_points={ entry_points={
'console_scripts': [ "console_scripts": [
'eddn-gateway = eddn.Gateway:main', "eddn-gateway = eddn.Gateway:main",
'eddn-relay = eddn.Relay:main', "eddn-relay = eddn.Relay:main",
'eddn-monitor = eddn.Monitor:main', "eddn-monitor = eddn.Monitor:main",
'eddn-bouncer = eddn.Bouncer:main', "eddn-bouncer = eddn.Bouncer:main",
], ],
} },
) )
def open_file_perms_recursive(dirname: pathlib.Path) -> None: def open_file_perms_recursive(dirname: pathlib.Path) -> None:
"""Open up file perms on the given directory and its contents.""" """Open up file perms on the given directory and its contents."""
print(f'open_file_perms_recursive: {dirname}') print(f"open_file_perms_recursive: {dirname}")
for name in dirname.glob('*'): for name in dirname.glob("*"):
print(f'open_file_perms_recursive: {name}') print(f"open_file_perms_recursive: {name}")
if name.is_dir(): if name.is_dir():
name.chmod(0o755) name.chmod(0o755)
open_file_perms_recursive(name) open_file_perms_recursive(name)
@ -133,10 +120,12 @@ def open_file_perms_recursive(dirname: pathlib.Path) -> None:
# Ensure the systemd-required start files are in place # Ensure the systemd-required start files are in place
print(""" print(
"""
****************************************************************************** ******************************************************************************
Ensuring start script and its config file are in place... Ensuring start script and its config file are in place...
""") """
)
try: try:
START_SCRIPT_BIN.mkdir(mode=0o700, parents=True, exist_ok=True) START_SCRIPT_BIN.mkdir(mode=0o700, parents=True, exist_ok=True)
@ -144,33 +133,28 @@ except Exception as e:
print(f"{START_SCRIPT_BIN} can't be created, aborting!!!\n{e!r}") print(f"{START_SCRIPT_BIN} can't be created, aborting!!!\n{e!r}")
exit(-1) exit(-1)
shutil.copy( shutil.copy(f"systemd/eddn_{setup_env.EDDN_ENV}_config", START_SCRIPT_BIN / f"eddn_{setup_env.EDDN_ENV}_config")
f'systemd/eddn_{setup_env.EDDN_ENV}_config',
START_SCRIPT_BIN / f'eddn_{setup_env.EDDN_ENV}_config'
)
# NB: We copy to a per-environment version so that, e.g.live use won't break # NB: We copy to a per-environment version so that, e.g.live use won't break
# due to changes in the other environments. # due to changes in the other environments.
shutil.copy( shutil.copy("systemd/start-eddn-service", START_SCRIPT_BIN / f"start-eddn-{setup_env.EDDN_ENV}-service")
'systemd/start-eddn-service',
START_SCRIPT_BIN / f'start-eddn-{setup_env.EDDN_ENV}-service'
)
# Ensure the service log file archiving script is in place # Ensure the service log file archiving script is in place
print(""" print(
"""
****************************************************************************** ******************************************************************************
Ensuring the service log file archiving script is in place Ensuring the service log file archiving script is in place
""") """
shutil.copy(
'contrib/eddn-logs-archive',
START_SCRIPT_BIN
) )
shutil.copy("contrib/eddn-logs-archive", START_SCRIPT_BIN)
# Ensure the latest monitor files are in place # Ensure the latest monitor files are in place
old_umask = os.umask(0o22) old_umask = os.umask(0o22)
print(f""" print(
f"""
****************************************************************************** ******************************************************************************
Ensuring {SHARE_EDDN_FILES} exists... Ensuring {SHARE_EDDN_FILES} exists...
""") """
)
try: try:
SHARE_EDDN_FILES.mkdir(mode=0o700, parents=True, exist_ok=True) SHARE_EDDN_FILES.mkdir(mode=0o700, parents=True, exist_ok=True)
@ -178,59 +162,67 @@ except Exception as e:
print(f"{SHARE_EDDN_FILES} can't be created, aborting!!!\n{e!r}") print(f"{SHARE_EDDN_FILES} can't be created, aborting!!!\n{e!r}")
exit(-1) exit(-1)
print(""" print(
"""
****************************************************************************** ******************************************************************************
Ensuring latest monitor files are in place... Ensuring latest monitor files are in place...
""") """
)
# Copy the monitor (Web page) files # Copy the monitor (Web page) files
try: try:
shutil.rmtree(SHARE_EDDN_FILES / 'monitor') shutil.rmtree(SHARE_EDDN_FILES / "monitor")
except OSError: except OSError:
pass pass
shutil.copytree( shutil.copytree(
'contrib/monitor', "contrib/monitor",
SHARE_EDDN_FILES / 'monitor', SHARE_EDDN_FILES / "monitor",
copy_function=shutil.copyfile, # type: ignore copy_function=shutil.copyfile, # type: ignore
) )
# And a copy of the schemas too # And a copy of the schemas too
print(""" print(
"""
****************************************************************************** ******************************************************************************
Ensuring latest schema files are in place for web access... Ensuring latest schema files are in place for web access...
""") """
)
try: try:
shutil.rmtree(SHARE_EDDN_FILES / 'schemas') shutil.rmtree(SHARE_EDDN_FILES / "schemas")
except OSError: except OSError:
pass pass
shutil.copytree( shutil.copytree(
'schemas', "schemas",
SHARE_EDDN_FILES / 'schemas', SHARE_EDDN_FILES / "schemas",
copy_function=shutil.copyfile, # type: ignore copy_function=shutil.copyfile, # type: ignore
) )
print(""" print(
"""
****************************************************************************** ******************************************************************************
Opening up permissions on monitor and schema files... Opening up permissions on monitor and schema files...
""") """
)
os.chmod(SHARE_EDDN_FILES, 0o755) os.chmod(SHARE_EDDN_FILES, 0o755)
open_file_perms_recursive(SHARE_EDDN_FILES) open_file_perms_recursive(SHARE_EDDN_FILES)
# You still need to make an override config file # You still need to make an override config file
if not (SHARE_EDDN_FILES / 'config.json').is_file(): if not (SHARE_EDDN_FILES / "config.json").is_file():
shutil.copy('docs/config-EXAMPLE.json', SHARE_EDDN_FILES) shutil.copy("docs/config-EXAMPLE.json", SHARE_EDDN_FILES)
print(f""" print(
f"""
****************************************************************************** ******************************************************************************
There was no config.json file in place, so docs/config-EXAMPLE.json was There was no config.json file in place, so docs/config-EXAMPLE.json was
copied into: copied into:
{SHARE_EDDN_FILES} {SHARE_EDDN_FILES}
Please review, edit and rename this file to 'config.json' so that this Please review, edit and rename this file to "config.json" so that this
software will actually work. software will actually work.
See docs/Running-this-software.md for guidance. See docs/Running-this-software.md for guidance.
****************************************************************************** ******************************************************************************
""") """
)
os.umask(old_umask) os.umask(old_umask)