From 16b0c052daca07a26e1956ff77f2d4d731a67650 Mon Sep 17 00:00:00 2001 From: glados-verma Date: Thu, 24 Oct 2024 15:20:45 -0700 Subject: [PATCH] Overhaul the build system to be per modern conventions (#1175) * Remove setup.py and cfg, relying on pyproject.toml * Update CONTRIBUTING.md, fixed readme path --- .github/workflows/continuous_integration.yml | 31 ++-- CONTRIBUTING.md | 20 +- MANIFEST.in | 2 + pyproject.toml | 52 +++++- setup.cfg | 2 - setup.py | 184 ------------------- test_reqs.txt | 2 - tox.ini | 1 - 8 files changed, 78 insertions(+), 216 deletions(-) create mode 100644 MANIFEST.in delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 test_reqs.txt diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index b60d5712b..cd14d168f 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -29,27 +29,26 @@ jobs: python-version: ["3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Install build prerequisites run: | - python -m pip install --upgrade pip - python -m pip install tox tox-gh-actions - wget https://github.com/protocolbuffers/protobuf/releases/download/v21.6/protoc-21.6-linux-x86_64.zip - unzip protoc-21.6-linux-x86_64.zip - sudo cp bin/protoc /usr/bin/protoc && sudo chmod 777 /usr/bin/protoc - sudo cp -r include/. /usr/include && sudo chmod -R +r /usr/include/google - protoc --version + python -m pip install --upgrade build pip sudo apt-get install -y libusb-1.0-0-dev libprotobuf-dev swig libevent-dev - - name: Build protobufs - run: python setup.py build_proto + - name: Setup protoc + uses: arduino/setup-protoc@v3 + - name: Create OpenHTF package + run: | + python -m build - name: Test with tox - run: tox + run: | + python -m pip install tox tox-gh-actions + tox - name: Publish to Coveralls with GitHub Action - uses: coverallsapp/github-action@v2.3.0 + uses: coverallsapp/github-action@v2 with: parallel: true flag-name: python-${{ matrix.python-version }} @@ -60,8 +59,8 @@ jobs: run: working-directory: openhtf/output/web_gui steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 - run: npm install - run: npm run build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7217c5a0..7cbb7e0be 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -231,11 +231,15 @@ virtualenv venv # Activate the new virtualenv. . venv/bin/activate -# Update setuptools. -pip install setuptools --upgrade +# Update build (run setuptools). +pip install build --upgrade # Install openhtf into the virtualenv in dev mode. -python setup.py develop +pip install --editable . + +# Install tox and run unit tests. +pip install tox +tox ``` ### MacOS @@ -268,7 +272,7 @@ virtualenv venv . venv/bin/activate # Install openhtf into the virtualenv in dev mode. -python setup.py develop +pip install --editable . ``` If you're having issues with the python setup, it's possible that the problem is due to El Capitan not including ssl headers. This [link](http://adarsh.io/bundler-failing-on-el-capitan/) may help you in that regard. @@ -318,12 +322,8 @@ npm start ``` Now you've got the frontend building, but you still need to serve it. The -frontend server is started as a runnable module. In a terminal where your Python -virtual environment (set up above) is active, start the server with: - -```bash -python -m openhtf.output.web_gui -``` +frontend server is started as a runnable module. See the associated +[readme](openhtf/output/web_gui/README.md). If you want the server to automatically restart when changes are detected, use the `--dev` flag. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..179921378 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include openhtf/output/proto/*.proto + diff --git a/pyproject.toml b/pyproject.toml index 21c15292b..74eef29fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,53 @@ [build-system] -requires = ["setuptools>=40.8.0", "wheel>=0.29.0"] +requires = ["setuptools", "setuptools-protobuf"] build-backend = "setuptools.build_meta" + +[project] +name = "openhtf" +version = "1.6.0" +authors = [ + { name="The OpenHTF Authors"}, +] +description = "OpenHTF, the open hardware testing framework." +readme = "README.md" +requires-python = ">=3.9" +dependencies = [ + "attrs>=19.3.0", + "colorama>=0.4.6", + "contextlib2>=21.6.0", + "inflection>=0.5.1", + "google-auth>=1.34.0", + "mutablerecords>=0.4.1", + "protobuf>=5.28.2", + "PyYAML>=6.0.2", + "pyOpenSSL>=17.1.0", + "requests>=2.27.1", + "sockjs_tornado>=1.0.7", + "tornado>=4.3,<5.0", + "typing_extensions>=4.12.2", +] +license = {file = "LICENSE"} + +[project.optional-dependencies] +usb_plugs = [ + "libusb1>=3.1.0", + "M2Crypto>=0.42.0", +] +update_units = ["xlrd>=1.0.0"] +serial_collection_plug = ["pyserial>=3.5"] +examples = ["pandas>=2.2.3"] + +[project.urls] +Homepage = "https://github.com/google/openhtf" + +[tool.setuptools.packages] +find = {} + +[tool.setuptools-protobuf] +protobufs = [ + "openhtf/output/proto/assembly_event.proto", + "openhtf/output/proto/guzzle.proto", + "openhtf/output/proto/mfg_event.proto", + "openhtf/output/proto/test_runs.proto", +] + diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2a9acf13d..000000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index 0b1c4837a..000000000 --- a/setup.py +++ /dev/null @@ -1,184 +0,0 @@ -# Copyright 2022 Google Inc. All Rights Reserved. - -# 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 OpenHTF.""" - -import errno -import glob -import os -import platform -import subprocess -import sys - -# pylint: disable=g-importing-member,g-bad-import-order -from distutils.command.build import build -from distutils.command.clean import clean -from distutils.cmd import Command -from setuptools import find_packages -from setuptools import setup - - -class CleanCommand(clean): - """Custom logic for the clean command.""" - - def run(self): - clean.run(self) - targets = [ - './dist', - './*.egg-info', - './openhtf/output/proto/*_pb2.py', - './openhtf/**/*.pyc', - ] - os.system('shopt -s globstar; rm -vrf %s' % ' '.join(targets)) - - -class BuildProtoCommand(Command): - """Custom setup command to build protocol buffers.""" - description = 'Builds the proto files into python files.' - user_options = [('protoc=', None, 'Path to the protoc compiler.'), - ('protodir=', None, 'Path to protobuf install.'), - ('indir=', 'i', 'Directory containing input .proto files.'), - ('outdir=', 'o', 'Where to output .py files.')] - - def initialize_options(self): - self.skip_proto = False - try: - prefix = subprocess.check_output( - 'pkg-config --variable prefix protobuf'.split()).strip().decode( - 'utf-8') - except (subprocess.CalledProcessError, OSError): - if platform.system() == 'Linux': - # Default to /usr? - prefix = '/usr' - elif platform.system() in ['Mac', 'Darwin']: - # Default to /usr/local for Homebrew - prefix = '/usr/local' - else: - print('Warning: mfg-inspector output is not fully implemented for ' - 'Windows. OpenHTF will be installed without it.') - self.skip_proto = True - - maybe_protoc = os.path.join(prefix, 'bin', 'protoc') - if os.path.isfile(maybe_protoc) and os.access(maybe_protoc, os.X_OK): - self.protoc = maybe_protoc - else: - print('Warning: protoc not found at %s' % maybe_protoc) - print('setup will attempt to run protoc with no prefix.') - self.protoc = 'protoc' - - self.protodir = os.path.join(prefix, 'include') - self.indir = os.getcwd() - self.outdir = os.getcwd() - - def finalize_options(self): - pass - - def run(self): - if self.skip_proto: - print('Skipping building protocol buffers.') - return - - # Build regular proto files. - protos = glob.glob( - os.path.join(self.indir, 'openhtf', 'output', 'proto', '*.proto')) - - if protos: - print('Attempting to build proto files:\n%s' % '\n'.join(protos)) - cmd = [ - self.protoc, - '--proto_path', - self.indir, - '--proto_path', - self.protodir, - '--python_out', - self.outdir, - ] + protos - try: - subprocess.check_call(cmd) - except OSError as e: - if e.errno == errno.ENOENT: - print('Could not find the protobuf compiler at \'%s\'' % self.protoc) - if sys.platform.startswith('linux'): - print('On many Linux systems, this is fixed by installing the ' - '"protobuf-compiler" and "libprotobuf-dev" packages.') - elif sys.platform == 'darwin': - print('On Mac, protobuf is often installed via homebrew.') - raise - except subprocess.CalledProcessError: - print('Could not build proto files.') - print('This could be due to missing helper files. On many Linux ' - 'systems, this is fixed by installing the ' - '"libprotobuf-dev" package.') - raise - else: - print('Found no proto files to build.') - - -# Make building protos part of building overall. -build.sub_commands.insert(0, ('build_proto', None)) - -INSTALL_REQUIRES = [ - 'attrs>=19.3.0', - 'colorama>=0.3.9', - 'contextlib2>=0.5.1', - 'inflection', - 'google-auth>=1.34.0', - 'mutablerecords>=0.4.1', - 'protobuf>=3.6.0', - 'PyYAML>=3.13', - 'pyOpenSSL>=17.1.0', - 'requests>=2.27.1', - 'sockjs-tornado>=1.0.3', - 'tornado>=4.3,<5.0', - 'typing-extensions', -] - - -_README_PATH = os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'README.md') -with open(_README_PATH, 'rb') as fp: - LONG_DESCRIPTION = fp.read().decode('utf-8') - - -setup( - name='openhtf', - version='1.5.2', - description='OpenHTF, the open hardware testing framework.', - url='https://github.com/google/openhtf', - author='The OpenHTF Authors', - long_description=LONG_DESCRIPTION, - long_description_content_type='text/markdown', - packages=find_packages(), - package_data={ - 'openhtf': [ - 'output/proto/*.proto', 'output/web_gui/dist/*.*', - 'output/web_gui/dist/css/*', 'output/web_gui/dist/js/*', - 'output/web_gui/dist/img/*', 'output/web_gui/*.*' - ] - }, - python_requires='>=3.9', - cmdclass={ - 'build_proto': BuildProtoCommand, - 'clean': CleanCommand, - }, - install_requires=INSTALL_REQUIRES, - extras_require={ - 'usb_plugs': [ - 'libusb1>=1.3.0', - 'M2Crypto>=0.22.3', - ], - 'update_units': ['xlrd>=1.0.0',], - 'serial_collection_plug': ['pyserial>=3.3.0',], - 'examples': ['pandas>=0.22.0',], - }, -) diff --git a/test_reqs.txt b/test_reqs.txt deleted file mode 100644 index 14a60609b..000000000 --- a/test_reqs.txt +++ /dev/null @@ -1,2 +0,0 @@ -# We want everything as specified by setup.py --e . diff --git a/tox.ini b/tox.ini index 2ff9d4ee3..0f9c369c9 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,6 @@ python = [testenv] deps = - -r{toxinidir}/test_reqs.txt absl-py>=0.10.0 pandas>=0.22.0 numpy