Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition from using setup.py to pyproject.toml to specify project metadata #766

Merged
merged 13 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install invoke rundoc .
python -m pip install tomli
python -m pip install packaging
- name: Run the README.md
run: invoke readme
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ coverage: ## check code coverage quickly with the default Python

.PHONY: dist
dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
python rdt/transformers/addons/addons_setup.py
python -m build --wheel --sdist
ls -l dist

.PHONY: publish-confirm
Expand Down
138 changes: 138 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'

[project]
name = 'rdt'
description = 'Reversible Data Transforms'
authors = [{ name = 'DataCebo, Inc.', email = '[email protected]' }]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: Free for non-commercial use',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
]
keywords = ['machine learning', 'synthetic data generation', 'benchmark', 'generative models']
version = '1.9.3.dev0'
license = { text = 'BSL-1.1' }
requires-python = '>=3.8,<3.12'
readme = 'README.md'
dependencies = [
"numpy>=1.20.0,<2;python_version<'3.10'",
"numpy>=1.23.3,<2;python_version>='3.10'",
"pandas>=1.1.3;python_version<'3.10'",
"pandas>=1.3.4;python_version>='3.10' and python_version<'3.11'",
"pandas>=1.5.0;python_version>='3.11'",
"scipy>=1.5.4,<2;python_version<'3.10'",
"scipy>=1.9.2,<2;python_version>='3.10'",
"scikit-learn>=0.24,<2;python_version<'3.10'",
"scikit-learn>=1.1.0;python_version>='3.10' and python_version<'3.11'",
"scikit-learn>=1.1.3,<2;python_version>='3.11'",
'Faker>=17,<20',
]

[project.urls]
"Source Code"= "https://github.com/sdv-dev/RDT/"
"Issue Tracker" = "https://github.com/sdv-dev/RDT/issues"
"Changes" = "https://github.com/sdv-dev/RDT/blob/main/HISTORY.md"
"Twitter" = "https://twitter.com/sdv_dev"
"Chat" = "https://bit.ly/sdv-slack-invite"

[project.entry-points]
rdt = { main = 'rdt.cli.__main__:main' }

[project.optional-dependencies]
copulas = ['copulas>=0.10.0,<0.11',]
test = [
'rdt[copulas]',

'pytest>=3.4.2',
'pytest-cov>=2.6.0',
'jupyter>=1.0.0,<2',
'rundoc>=0.4.3,<0.5',
'pytest-subtests>=0.5,<1.0',
'pytest-runner >= 2.11.1',
'tomli>=2.0.0,<3',
]
dev = [
'rdt[test]',

# general
'bumpversion>=0.5.3,<0.6',
'pip>=9.0.1',
'watchdog>=0.8.3,<0.11',

# style check
'pycodestyle<2.8.0,>=2.7.0',
'pyflakes<2.4.0,>=2.3.0',
'flake8>=3.7.7,<4',
'flake8-absolute-import>=1.0,<2',
'flake8-builtins>=1.5.3,<1.6',
'flake8-comprehensions>=3.6.1,<3.7',
'flake8-debugger>=4.0.0,<4.1',
'flake8-docstrings>=1.5.0,<2',
'flake8-mock>=0.3,<0.4',
'flake8-variables-names>=0.0.4,<0.1',
'dlint>=0.11.0,<0.12', # code security addon for flake8
'flake8-fixme>=1.1.1,<1.2',
'flake8-eradicate>=1.1.0,<1.2',
'flake8-mutable>=1.2.0,<1.3',
'flake8-print>=4.0.0,<4.1',
'isort>=4.3.4,<5',
'pylint>=2.5.3,<3',
'pandas-vet>=0.2.3,<0.3',
'flake8-multiline-containers>=0.0.18,<0.1',
'flake8-pytest-style>=1.5.0,<2',
'flake8-quotes>=3.3.0,<4',
'flake8-expression-complexity>=0.0.9,<0.1',
'pep8-naming>=0.12.1,<0.13',
'pydocstyle>=6.1.1,<6.2',
'flake8-sfs>=0.0.3,<0.1',

# fix style issues
'autoflake>=1.1,<2',
'autopep8>=1.4.3,<1.6',

# distribute on PyPI
'twine>=1.10.0,<4',
'wheel>=0.30.0',

# Advanced testing
'coverage>=4.5.1,<6',
'tox>=2.9.1,<4',
'tabulate>=0.8.9,<1',

# Invoking test commands
'invoke'
]

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
include = ['rdt', 'rdt.*']
namespaces = false

[tool.isort]
line_length = 99
lines_between_types = 0
multi_line_output = 4
not_skip = ['__init__.py']
use_parentheses = true

[tool.pydocstyle]
convention = 'google'
add-ignore = ['D107', 'D407', 'D417']

[tool.pytest.ini_options]
collect_ignore = ['pyproject.toml']

[tool.coverage.report]
exclude_lines = ['NotImplementedError()']

86 changes: 0 additions & 86 deletions rdt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@
__email__ = '[email protected]'
__version__ = '1.9.3.dev0'


import sys
import warnings
from operator import attrgetter
from types import ModuleType

import numpy as np
import pandas as pd
from pkg_resources import iter_entry_points

from rdt import transformers
from rdt.hyper_transformer import HyperTransformer
Expand Down Expand Up @@ -94,82 +87,3 @@ def get_demo(num_rows=5):
'dollars_spent': dollars_spent
})
], ignore_index=True)


def _get_addon_target(addon_path_name):
"""Find the target object for the add-on.

Args:
addon_path_name (str):
The add-on's name. The add-on's name should be the full path of valid Python
identifiers (i.e. importable.module:object.attr).

Returns:
tuple:
* object:
The base module or object the add-on should be added to.
* str:
The name the add-on should be added to under the module or object.
"""
module_path, _, object_path = addon_path_name.partition(':')
module_path = module_path.split('.')

if module_path[0] != __name__:
msg = f"expected base module to be '{__name__}', found '{module_path[0]}'"
raise AttributeError(msg)

target_base = sys.modules[__name__]
for submodule in module_path[1:-1]:
target_base = getattr(target_base, submodule)

addon_name = module_path[-1]
if object_path:
if len(module_path) > 1 and not hasattr(target_base, module_path[-1]):
msg = f"cannot add '{object_path}' to unknown submodule '{'.'.join(module_path)}'"
raise AttributeError(msg)

if len(module_path) > 1:
target_base = getattr(target_base, module_path[-1])

split_object = object_path.split('.')
addon_name = split_object[-1]

if len(split_object) > 1:
target_base = attrgetter('.'.join(split_object[:-1]))(target_base)

return target_base, addon_name


def _find_addons():
"""Find and load all RDT add-ons.

If the add-on is a module, we add it both to the target module and to
``system.modules`` so that they can be imported from the top of a file as follows:

from top_module.addon_module import x
"""
group = 'rdt_modules'
for entry_point in iter_entry_points(group=group):
try:
addon = entry_point.load()
except Exception: # pylint: disable=broad-exception-caught
msg = f'Failed to load "{entry_point.name}" from "{entry_point.module_name}".'
warnings.warn(msg)
continue

try:
addon_target, addon_name = _get_addon_target(entry_point.name)
except AttributeError as error:
msg = f"Failed to set '{entry_point.name}': {error}."
warnings.warn(msg)
continue

if isinstance(addon, ModuleType):
addon_module_name = f'{addon_target.__name__}.{addon_name}'
if addon_module_name not in sys.modules:
sys.modules[addon_module_name] = addon

setattr(addon_target, addon_name, addon)


_find_addons()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has to stay! 😅 Otherwise enterprise addons won't work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! Updated in f332d2d

18 changes: 0 additions & 18 deletions rdt/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import importlib
import inspect
import json
import sys
from collections import defaultdict
from copy import deepcopy
from functools import lru_cache
from pathlib import Path

from rdt.transformers.base import BaseMultiColumnTransformer, BaseTransformer
from rdt.transformers.boolean import BinaryEncoder
Expand Down Expand Up @@ -49,21 +46,6 @@
]


def _import_addons():
"""Import all the addon modules."""
addons_path = Path(__file__).parent / 'addons'
for addon_json_path in addons_path.glob('*/*.json'):
with open(addon_json_path, 'r', encoding='utf-8') as addon_json_file:
transformers = json.load(addon_json_file).get('transformers', [])
for transformer in transformers:
module = transformer.rsplit('.', 1)[0]
if module not in sys.modules:
importlib.import_module(module)


_import_addons()


def get_transformer_name(transformer):
"""Return the fully qualified path of the transformer.

Expand Down
37 changes: 0 additions & 37 deletions rdt/transformers/addons/README.md

This file was deleted.

Loading
Loading