Skip to content

Add workflow to deploy DALiuGE to PyPI on Release #311

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

Merged
merged 19 commits into from
Feb 21, 2025
Merged

Conversation

myxie
Copy link
Collaborator

@myxie myxie commented Feb 20, 2025

JIRA Ticket

Type

  • Feature (addition)
  • Bug fix
  • Refactor (change)
  • Documentation

Problem/Issue

We would like to setup Continuous Deployment (CD) to PyPI for DALiuGE releases, to avoid having to do so manually.

We have not released for quite some time (~10 months), which means that some updates we've made to improve some things have broken our ability to build/push to PyPI. We have also been reliant on some direct installation links, which are not supported by PyPI.

This PR aims to address these issues at the same time as providing a minimal viable workflow that builds and pushes the daliuge modules to PyPI.

Solution

I have decided to make the PyPI run when we create a Release on GitHub. This is different to running the pipeline whenever we push a new tagged version, and (currently) requires a small amount of manual intervention (i.e. creating a Release through the GitHub UI). We do not have any "releases" on GitHub.

I have done this for a couple of reasons:

  • Whilst the workflow is in early-use, manually releasing older versions of DALiUGE tags will help us iron out any issues without resulting in lots of new tags + PyPI uploads.
  • We do not have a consistent release process at the moment, so this gives us time to get used to releasing and deploying more consistently
  • We do not need to push new releases to PyPI for every tagged version of the code

The work included in this PR includes:

  • Added the new publish_to_pypi.yml workflow file.

    • This is run on published releases (as above)
    • This has been previously tested and run on TestPyPI. See the 4.8.1 versions at common, engine, translator. To test, I had this as on: push.
  • In response to LIU-449 Improved installation info #307 (comment) I have added string-literal VERSION files for daliuge-engine and daliuge-translator. This is to ensure that we are not relying on any dynamic version numbering at runtime.

  • Updated our merklelib install to the newly released np-merklelib fork on PyPI.

  • Added the source code from PyExt to our code base and added the relevant tests/licenses, including a fix currently in a PR on the inactive repository.

  • Removed the redundant test-requirements.txt file, which serves only to obfuscate the test requirements for the daliuge-translator module. Test dependencies are now tracked in the extra_requires dictionary.

Checklist

  • Unittests added
    • Reason for not adding unittests (remove this line if added)
  • Documentation added
    • Reason for not adding documentation (remove this line if added)

Summary by Sourcery

This pull request introduces a CI workflow to automatically build and publish the daliuge-common, daliuge-engine, and daliuge-translator packages to TestPyPI upon a push event. It also updates the build process to use the build package and standardizes versioning across all packages.

New Features:

  • Adds a GitHub Actions workflow to automatically build and publish the daliuge-common, daliuge-engine, and daliuge-translator packages to TestPyPI upon a push event.

Enhancements:

  • Updates the build process to use the build package instead of setuptools directly.
  • Updates the versioning scheme to extract the version from a VERSION file, ensuring consistency across all packages.
  • Removes the dependency on daliuge-common during the installation of daliuge-engine and daliuge-translator.
  • Replaces the direct git dependency on merklelib with np-merklelib in daliuge-common.
  • Removes the direct git dependency on pyext in daliuge-engine and includes the code directly in the repository.

Build:

  • Adds a workflow to build and publish the packages to TestPyPI.
  • Updates the Makefile to write the version to a VERSION file for each package.
  • Updates setup.py to read the version from the VERSION file.

CI:

  • Adds a CI workflow to automatically build and publish the packages to TestPyPI upon a push event.

Chores:

  • Adds a VERSION file to each package to store the version number.
  • Adds a .gitignore file to exclude unwanted files from the repository.

Copy link
Contributor

sourcery-ai bot commented Feb 20, 2025

Reviewer's Guide by Sourcery

This pull request introduces a CI workflow to automatically build and publish the daliuge-common, daliuge-engine, and daliuge-translator packages to TestPyPI upon a release event. It also updates the build process to use the build package and standardizes versioning across all packages. Additionally, the pyext library is now included directly in the daliuge-engine repository.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Introduces a CI workflow to automatically build and publish the daliuge-common, daliuge-engine, and daliuge-translator packages to TestPyPI upon a release event.
  • Adds a new GitHub Actions workflow file publish_to_pypi.yml to handle the build and publishing process.
  • The workflow is triggered on release events with the published type.
  • The workflow defines separate jobs for building each package (daliuge-common, daliuge-engine, daliuge-translator).
  • Each build job checks out the code, sets up Python, installs build, builds the package, and uploads the distribution packages as artifacts.
  • Separate publish jobs are defined for each package, which download the artifacts and publish the package to TestPyPI using pypa/gh-action-pypi-publish.
  • The publish jobs require id-token: write permissions for trusted publishing.
  • The publish jobs use a PyPI environment with a specified URL for each package.
.github/workflows/publish_to_pypi.yml
Updates the build process to use the build package instead of setuptools directly and standardizes versioning across all packages.
  • Replaces direct git dependency on merklelib with np-merklelib in daliuge-common.
  • Removes the direct git dependency on pyext in daliuge-engine and includes the code directly in the repository.
  • Adds a VERSION file to each package to store the version number.
  • Updates the Makefile to write the version to the VERSION file for each package during the release process.
  • Updates setup.py in each package to read the version from the VERSION file.
  • Removes the dependency on daliuge-common during the installation of daliuge-engine and daliuge-translator.
daliuge-translator/setup.py
daliuge-engine/setup.py
Makefile
daliuge-common/setup.py
daliuge-common/VERSION
daliuge-engine/VERSION
daliuge-translator/VERSION
Includes pyext library directly into the daliuge-engine repository.
  • Adds pyext.py to daliuge-engine/dlg/pyext/.
  • Adds LICENSE to daliuge-engine/dlg/pyext/.
  • Adds __init__.py to daliuge-engine/dlg/pyext/.
  • Adds test_pyext.py to daliuge-engine/test/pyext/.
  • Adds LICENSE to daliuge-engine/test/pyext/.
  • Removes direct git dependency on pyext.
daliuge-engine/dlg/pyext/pyext.py
daliuge-engine/dlg/pyext/LICENSE
daliuge-engine/dlg/pyext/__init__.py
daliuge-engine/test/pyext/test_pyext.py
daliuge-engine/test/pyext/LICENSE
Minor changes and cleanup.
  • Adds .gitignore file to exclude unwanted files from the repository.
  • Updates run-unit-tests.yml to remove pip install -r test-requirements.txt under daliuge-translator.
  • Updates test_drop_ports.py to increase the timeout and skip a test.
  • Updates dlg/named_port_utils.py to decode utf8.
  • Updates dlg/version_helper.py to check for .git in the parent directory.
  • Updates dlg/apps/pyfunc.py to import pyext.
.gitignore
.github/workflows/run-unit-tests.yml
daliuge-engine/test/test_drop_ports.py
daliuge-engine/dlg/named_port_utils.py
daliuge-common/dlg/version_helper.py
daliuge-engine/dlg/apps/pyfunc.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coveralls
Copy link

coveralls commented Feb 21, 2025

Coverage Status

coverage: 78.596%. first build
when pulling b64f7cc on DLG_PyPI_Deployment
into 989f07e on master.

@myxie myxie marked this pull request as ready for review February 21, 2025 04:25
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @myxie - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a single workflow file to build and publish all three packages to reduce duplication.
  • Instead of skipping the test_bash_shell_ports test, try to fix it.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +387 to +389
if inspect.stack()[1][3] == f.__name__:
if (spec and spec(args)) or not spec:
raise TailRecursion(args, kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Merge nested if conditions (merge-nested-ifs)

Suggested change
if inspect.stack()[1][3] == f.__name__:
if (spec and spec(args)) or not spec:
raise TailRecursion(args, kwargs)
if inspect.stack()[1][3] == f.__name__ and ((spec and spec(args)) or not spec):
raise TailRecursion(args, kwargs)


ExplanationToo much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.

Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two if conditions can be combined using
and is an easy win.


def test_switch():
with pyext.switch('x'):
if case('x'): x = 4
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

def test_switch():
with pyext.switch('x'):
if case('x'): x = 4
if case('b'): x = 2
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

with pyext.switch('x'):
if case('x'): x = 4
if case('b'): x = 2
if case(1): x = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

if case('x'): x = 4
if case('b'): x = 2
if case(1): x = 3
if case('a'): x = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid conditionals in tests. (no-conditionals-in-tests)

ExplanationAvoid complex code, like conditionals, in test functions.

Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:

  • loops
  • conditionals

Some ways to fix this:

  • Use parametrized tests to get rid of the loop.
  • Move the complex logic into helpers.
  • Move the complex part into pytest fixtures.

Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.

Software Engineering at Google / Don't Put Logic in Tests

Comment on lines +248 to +258
if len(kw) == 0:
cargs = args
elif len(kw) == 1 and 'is_cls' in kw and kw['is_cls']:
cargs = args[1:]
else:
raise ValueError('Invalid keyword args specified')
types = _gettypes(cargs)
if types not in overloads:
raise TypeError(\
"No overload of function '%s' that takes: %s" % (
f.__name__, types))
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

Comment on lines +440 to +441
if len(args) >= 1:
f.__annotations__['return'] = args[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Simplify sequence length comparison (simplify-len-comparison)

Comment on lines +491 to +498
vsplit = list(map(str.strip, varname.split('.')))
fvars = dict(fd, **fl)
if vsplit[0] not in fvars:
raise NameError('Unknown object: %s' % vsplit[0])
base = fvars[vsplit[0]]
for x in vsplit[1:-1]:
base = getattr(base, x)
setattr(base, vsplit[-1], value)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

def f(a): return str
@pyext.overload.args()
def f(): return
assert f() == None
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Use x is None rather than x == None (none-compare)

Comment on lines +66 to +67
if case('x'): x = 4
if case('x'): x = 2; case.quit()
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Merge repeated if statements into single if (merge-repeated-ifs)

Suggested change
if case('x'): x = 4
if case('x'): x = 2; case.quit()
if case('x'):
x = 4
x = 2
case.quit()

@@ -68,7 +68,7 @@ def _create_and_run_graph_spec_from_lgt(self, logical_graph_name: str):
roots = graph_loader.createGraphFromDropSpecList(appDropSpec)
# drops = [v for d,v in drops.items()]
leafs = droputils.getLeafNodes(roots)
with droputils.DROPWaiterCtx(self, leafs, timeout=3):
with droputils.DROPWaiterCtx(self, leafs, timeout=600):
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the timeout really need to be that long? If, for some reason this gets into a hanging state, the test suite will sit there for 10 min before it continues. I had that a few times through vscode and it is really not helpful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It absolutely does not - I did this for debugging purposes but accidentally committed the edit. I will revert these changes.

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
Copy link
Contributor

Choose a reason for hiding this comment

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

fairly old version of Python

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I will update to 3.10.

Copy link
Contributor

@awicenec awicenec left a comment

Choose a reason for hiding this comment

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

Apart from the old PPython version I think this is finally addressing a long overdue issue with the overall development and release of the packages.

@myxie myxie merged commit 789ee83 into master Feb 21, 2025
25 checks passed
@myxie myxie deleted the DLG_PyPI_Deployment branch June 13, 2025 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants