Skip to content

Commit

Permalink
Struggling to get pyproject.toml to work the same
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoRoos committed Sep 23, 2024
1 parent 54c1f5b commit f148c37
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,17 @@ jobs:

steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install package (with dependencies)
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest==7.4.4 coverage coveralls pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build adslib
run: |
python setup.py build
- name: Install package
run: |
python setup.py develop
pip install .[tests,dev]
- name: Test with pytest
run: |
pytest -v --cov pyads
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install build twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
python -m build
twine upload dist/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ build/
*.egg-info/
.eggs/
venv/
.venv/
venv_*/

*.tox
deploy.py
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ tests = [
]
dev = [
"build",
"flake8",
"pytest==7.4.4",
"coverage",
"coveralls",
]

[project.urls]
Repository = "https://github.com/MrLeeh/pyads"
Repository = "https://github.com/stlehmann/pyads"
Documentation = "https://pyads.readthedocs.io"

[build-system]
Expand All @@ -45,7 +49,7 @@ build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["pyads", "pyads.testserver"]
package-dir = { ""= "src" }
package-dir = { "" = "src" }
include-package-data = false

[tool.setuptools.package-data]
Expand Down
93 changes: 85 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,101 @@
from setuptools import setup
from setuptools.command.build import build

import glob
import os
import sys
import shutil
import subprocess
import functools
import operator
from setuptools import setup
from setuptools.command.install import install as _install
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.command.sdist import sdist as _sdist


def platform_is_linux():
return sys.platform.startswith("linux") or sys.platform.startswith("darwin")


class PyadsBuild(build):
def get_files_rec(directory):
res = []
for path, directory, filenames in os.walk(directory):
files = [os.path.join(path, fn) for fn in filenames]
res.append((path, files))
return res


def create_binaries():
subprocess.call(["make", "-C", "adslib"])


def remove_binaries():
"""Remove all binary files in the adslib directory."""
patterns = (
"adslib/*.a",
"adslib/*.o",
"adslib/obj/*.o",
"adslib/*.bin",
"adslib/*.so",
)

for f in functools.reduce(operator.iconcat, [glob.glob(p) for p in patterns]):
os.remove(f)


def copy_sharedlib():
try:
shutil.copy("adslib/adslib.so", "src/pyads/adslib.so")
except OSError:
pass


def remove_sharedlib():
try:
os.remove("adslib.so")
except OSError:
pass


class build(_build):
def run(self):
if platform_is_linux():
remove_binaries()
create_binaries()
copy_sharedlib()
remove_binaries()
_build.run(self)


class clean(_clean):
def run(self):
if platform_is_linux():
remove_binaries()
remove_sharedlib()
_clean.run(self)


class sdist(_sdist):
def run(self):
if platform_is_linux():
subprocess.call(["make", "-C", "adslib"])
remove_binaries()
_sdist.run(self)

build.run(self) # Avoid `super()` here for legacy

class install(_install):
def run(self):
if platform_is_linux():
create_binaries()
copy_sharedlib()
_install.run(self)


# noinspection PyTypeChecker
setup(
cmdclass={
"build": PyadsBuild,
}
"build": build,
"clean": clean,
# "sdist": sdist,
"install": install,
},
data_files=get_files_rec("adslib"), # Maybe necessary?
)

0 comments on commit f148c37

Please sign in to comment.