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

Add setup_helper.py with duplicate_package_info #26

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ Ska Package Helpers
.. automodule:: ska_helpers
:members:

Logging
-------

.. automodule:: ska_helpers.logging
:members:


Retry
-----

.. automodule:: ska_helpers.retry
:members:


Setup Helpers
-------------

.. automodule:: ska_helpers.setup_helper
:members:


Utilities
---------

Expand Down
23 changes: 23 additions & 0 deletions ska_helpers/setup_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

def duplicate_package_info(vals, name_in, name_out):
"""
Duplicate a list or dict of values inplace, replacing ``name_in`` with ``name_out``.

Normally used in setup.py for making a namespace package that copies a flat one.
For an example see setup.py in the ska_sun or Ska.Sun repo.

:param vals: list or dict of values
:param name_in: string to replace at start of each value
:param name_out: output string
"""
import re

for name in list(vals):
new_name = re.sub(f"^{name_in}", name_out, name)
if isinstance(vals, dict):
vals[new_name] = vals[name]
else:
vals.append(new_name)