Skip to content

Commit

Permalink
Support running setup.py from other directories.
Browse files Browse the repository at this point in the history
This incorporates changes from pyocd#753 by @jsiverskog.
  • Loading branch information
flit committed Feb 21, 2020
1 parent 6bfe9e7 commit a150b56
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pyOCD debugger
# Copyright (c) 2012-2019 Arm Limited
# Copyright (c) 2012-2020 Arm Limited
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,22 +19,28 @@
from setuptools import setup, find_packages
import zipfile

# Get the directory containing this setup.py. Even though full paths are used below, we must
# chdir in order for setuptools-scm to successfully pick up the version.
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
os.chdir(SCRIPT_DIR)

# Read the readme file using UTF-8 encoding.
open_args = { 'mode': 'r' }
if sys.version_info[0] > 2:
# Python 3.x version requires explicitly setting the encoding.
# Python 2.x version of open() doesn't support the encoding parameter.
open_args['encoding'] = 'utf-8'

with open('README.md', **open_args) as f:
readme_path = os.path.join(SCRIPT_DIR, "README.md")
with open(readme_path, **open_args) as f:
readme = f.read()

# Build zip of SVD files.
#
# The SVD files are stored individually in the data/ directory only in the repo. For both sdist and
# wheel, the svd_data.zip file is used rather than including the data directory. Thus, this setup
# script needs to skip building svd_data.zip if the data/ directory is not present.
svd_dir_path = os.path.join(os.path.dirname(__file__), "pyocd", "debug", "svd")
svd_dir_path = os.path.join(SCRIPT_DIR, "pyocd", "debug", "svd")
svd_data_dir_path = os.path.join(svd_dir_path, "data")
svd_zip_path = os.path.join(svd_dir_path, "svd_data.zip")
if os.path.exists(svd_data_dir_path):
Expand Down

0 comments on commit a150b56

Please sign in to comment.