Skip to content

Commit

Permalink
Migrate to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Nov 26, 2024
1 parent badb70a commit c3a2789
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 107 deletions.
Empty file added __init__.py
Empty file.
5 changes: 4 additions & 1 deletion openfisca_survey_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

log = logging.getLogger(__name__)


default_config_files_directory = None
openfisca_survey_manager_location = Path(__file__).parent.parent


Expand Down Expand Up @@ -70,3 +70,6 @@
default_config_files_directory = BaseDirectory.save_config_path('openfisca-survey-manager')

log.debug(f'Using default_config_files_directory = {default_config_files_directory}')


assert default_config_files_directory is not None
5 changes: 4 additions & 1 deletion openfisca_survey_manager/scripts/build_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def build_survey_collection(
data_directory_path_by_survey_suffix = None,
source_format = 'sas',
keep_original_parquet_file = False,
encoding = None,
):

assert collection_name is not None
Expand Down Expand Up @@ -153,7 +154,7 @@ def build_survey_collection(
for survey in survey_collection.surveys:
if survey.name.endswith(str(survey_suffix)) and survey.name.startswith(collection_name):
surveys.append(survey)
survey_collection.fill_store(source_format = source_format, surveys = surveys, overwrite = replace_data, keep_original_parquet_file = keep_original_parquet_file)
survey_collection.fill_store(source_format = source_format, surveys = surveys, overwrite = replace_data, keep_original_parquet_file = keep_original_parquet_file, encoding = encoding)
return survey_collection


Expand Down Expand Up @@ -207,6 +208,7 @@ def main():
parser.add_argument('-s', '--survey', help = 'name of survey to build or update (default = all)')
parser.add_argument('-k', '--keep_original_parquet_file', action = 'store_true', default = False, help = "Keep original and point to original parquet files")
parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity")
parser.add_argument('-e', '--encoding', default = None, help = "encoding to be used")

args = parser.parse_args()
logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)
Expand Down Expand Up @@ -242,6 +244,7 @@ def main():
source_format = 'sas',
config_files_directory = config_files_directory,
keep_original_parquet_file = args.keep_original_parquet_file,
encoding = args.encoding,
)
except Exception as e:
log.info(e)
Expand Down
4 changes: 2 additions & 2 deletions openfisca_survey_manager/survey_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def dump(self, config_files_directory = None, json_file_path = None):
with codecs.open(self.json_file_path, 'w', encoding = 'utf-8') as _file:
json.dump(self.to_json(), _file, ensure_ascii = False, indent = 2)

def fill_store(self, source_format = None, surveys = None, tables = None, overwrite = False, keep_original_parquet_file = False):
def fill_store(self, source_format = None, surveys = None, tables = None, overwrite = False, keep_original_parquet_file = False, encoding = None):
if surveys is None:
surveys = self.surveys
for survey in surveys:
survey.fill_store(source_format = source_format, tables = tables, overwrite = overwrite, keep_original_parquet_file = keep_original_parquet_file)
survey.fill_store(source_format = source_format, tables = tables, overwrite = overwrite, keep_original_parquet_file = keep_original_parquet_file, encoding = encoding)
self.dump()

def get_survey(self, survey_name):
Expand Down
3 changes: 2 additions & 1 deletion openfisca_survey_manager/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def dump(self):
self.survey_collection.dump()

def fill_store(self, source_format = None, tables = None, overwrite = True, keep_original_parquet_file = False,
store_format = "hdf5"):
encoding = None, store_format = "hdf5"):
"""
Convert data from the source files to store format either hdf5 or parquet.
If the source is in parquet, the data is not converted.
Expand Down Expand Up @@ -161,6 +161,7 @@ def fill_store(self, source_format = None, tables = None, overwrite = True, keep
data_file,
clean = True,
overwrite = overwrite if isinstance(overwrite, bool) else table.name in overwrite,
encoding = encoding,
)
self.dump()

Expand Down
104 changes: 104 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[project]
name = "OpenFisca-Survey-Manager"
version = "2.3.5"
description = "A tool for managing survey/administrative data and import them in OpenFisca"
readme = "README.md"
keywords = ["microsimulation", "tax", "benefit", "rac", "rules-as-code", "survey", "data"]
authors = [
{name = "OpenFisca Team", email = "contact@openfisca.fr"},
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Information Analysis",
]
requires-python = ">= 3.9"
dependencies = [
'chardet >=5.1.0, < 6.0',
'configparser >= 5.3.0, < 8.0',
'humanize >=4.6.0, < 5.0',
'numpy >=1.24.2, <2.0',
'openfisca-core >=43.0.0, <44.0.0',
'pandas >=2.0.3, < 3.0',
'pyarrow >= 13.0.0, < 19.0.0',
'pyxdg >=0.28, < 0.29',
'PyYAML >=6.0, < 7.0',
'tables >=3.8.0, < 4.0',
'tabulate >=0.9.0, < 0.10.0',
'weightedcalcs >=0.1.2, < 0.2.0',
'wquantiles >=0.6, < 0.7',
]

[project.urls]
Homepage = "https://github.com/openfisca/openfisca-survey-manager"
Repository = "https://github.com/openfisca/openfisca-survey-manager"
Issues = "https://github.com/openfisca/openfisca-survey-manager/issues"
Changelog = "https://github.com/openfisca/openfisca-survey-manager/blob/main/CHANGELOG.md"

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"


[project.scripts]
# Command-line scripts
build-collection = "openfisca_survey_manager.scripts.build_collection:main"


[project.optional-dependencies]
matching = [
'feather',
'rpy2 >=3.5.10, < 4.0',
]
dev = [
'autopep8 >=2.0.2, < 3',
'flake8 >= 6.0.0, < 8.0',
'flake8-bugbear >= 23.3.12, < 25.0',
'flake8-docstrings >=1.7.0, < 2.0',
'flake8-print >=5.0.0, < 6.0',
'flake8-rst-docstrings >=0.3.0, < 0.4.0',
'openfisca-country-template >=7.1.5, <8.0.0',
'pytest >=8.3.3, < 9.0',
'pytest-cov >= 4.0.0, < 7.0',
'scipy >=1.10.1, < 2.0',
'pytest-order >=1.1.0, <2.0',
]
casd = [
'autopep8 >=2.0.2, < 3',
'flake8 >= 6.0.0, < 8.0',
'pycodestyle >=2.10.0, < 3.0',
'pytest >=7.2.2, < 8.0',
'scipy >=1.10.1, < 2.0',
]
sas = [
'pyreadstat >=1.2.1, < 2.0',
'sas7bdat >=2.2.3, < 3.0',
]

[tool.flake8]
# ; E128/133: We prefer hang-closing visual indents
# ; E251: We prefer `function(x = 1)` over `function(x=1)`
# ; E501: We do not enforce a maximum line length
# ; F403/405: We ignore * imports
# ; W503/504: We break lines before binary operators (Knuth's style)
hang-closing = true
ignore = ["E128","E251","F403","F405","E501","W503", ]
docstring-quotes = "single"
inline-quotes = "single"
multiline-quotes = "single"

[tool.pep8]
hang-closing = true
ignore = ["E128","E251","F403","F405","E501","W503"]
in-place = true

[tool.pytest.ini_options]
addopts = "--doctest-modules --disable-pytest-warnings --showlocals"
testpaths = "openfisca_survey_manager"
doctest_optionflags = "ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE"
python_files = "**/*.py"
102 changes: 0 additions & 102 deletions setup.py

This file was deleted.

0 comments on commit c3a2789

Please sign in to comment.