Skip to content

Instantly share code, notes, and snippets.

@lmazuel
Created January 27, 2023 23:37
Show Gist options
  • Save lmazuel/7a7269035afba658c76aea268ffcfe74 to your computer and use it in GitHub Desktop.
Save lmazuel/7a7269035afba658c76aea268ffcfe74 to your computer and use it in GitHub Desktop.
Setup.py to pyproject.toml
# Just having fun, don't take this to seriously :p
import sys
import importlib
def new_module(mod_name):
spec = importlib.machinery.ModuleSpec(mod_name,None)
return importlib.util.module_from_spec(spec)
def create_module(mod_name, object_list):
mod = new_module(mod_name)
for obj in object_list:
setattr(mod,obj.__name__, obj)
return mod
_SAVED_KWARGS = {}
def do_stuf():
def setup(*args, **kwargs):
global _SAVED_KWARGS
_SAVED_KWARGS = kwargs
def find_packages(*args, **kwargs):
return "list"
return create_module("setuptools", [
setup,
find_packages
])
from setuptools import find_packages, setup
sys.modules['setuptools'] = do_stuf()
###########
import setup # Import the local file
HEADER = """[build-system]
requires = ["setuptools ~= 58.0"]
[project]
"""
print(HEADER)
for name, value in _SAVED_KWARGS.items():
print(f"{name} = {value}")
@lmazuel
Copy link
Author

lmazuel commented Jan 27, 2023

First version does something like:

[build-system]
requires = ["setuptools ~= 58.0"]

[project]

name = azure-core
version = 1.26.3
include_package_data = True
description = Microsoft Azure Core Library for Python
long_description = 
# Azure Core shared client library for Python

Azure core provides shared exceptions and modules for Python SDK client libraries.
These libraries follow the [Azure SDK Design Guidelines for Python](https://azure.github.io/azure-sdk/python/guidelines/index.html) .

long_description_content_type = text/markdown
license = MIT License
author = Microsoft Corporation
author_email = azpysdkhelp@microsoft.com
url = https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core
classifiers = ['Development Status :: 5 - Production/Stable', 'Programming Language :: Python', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'License :: OSI Approved :: MIT License']
zip_safe = False
packages = list
package_data = {'pytyped': ['py.typed']}
python_requires = >=3.7
install_requires = ['requests>=2.18.4', 'six>=1.11.0', 'typing-extensions>=4.0.1']
extras_require = {'aio': ['aiohttp>=3.0']}

Which is not that bad for 10 minutes of hacking around

@scbedd
Copy link

scbedd commented Jan 28, 2023

This is a really excellent starting point @lmazuel . Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment