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

Use PEP 440 style requirements #5673

Merged
merged 11 commits into from
Jul 25, 2022
Merged

Use PEP 440 style requirements #5673

merged 11 commits into from
Jul 25, 2022

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Jul 17, 2022

This adds support for PEP 440 requirements instead of using the pip-specific VCS format.
see: https://peps.python.org/pep-0440/#direct-references

This facilitates using newer tooling that does not support using the legacy pip VCS format.

Summary of changes:

  • *requirements.txt: reformat 6 requirements repeated across 11 files (this is the primary part of the PR, everything else supports it)
  • Python: add 6 lines to 19 copies of dist_utils.py
  • Python: add 8 lines and change 1 line in scripts/fixate-requirements.py

*requirements.txt

So, this change moves from this legacy pip VCS format:

st2/requirements.txt

Lines 23 to 25 in be437e9

git+/~https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file
git+/~https://github.com/StackStorm/st2-auth-ldap.git@master#egg=st2-auth-ldap
git+/~https://github.com/StackStorm/st2-rbac-backend.git@master#egg=st2-rbac-backend

to this PEP 440 direct reference format:

st2/requirements.txt

Lines 69 to 71 in 4d46a28

st2-auth-backend-flat-file@ git+/~https://github.com/StackStorm/st2-auth-backend-flat-file.git@master
st2-auth-ldap@ git+/~https://github.com/StackStorm/st2-auth-ldap.git@master
st2-rbac-backend@ git+/~https://github.com/StackStorm/st2-rbac-backend.git@master

logshipper is one of the VCS requirements that we convert to PEP 440. It is linux-only and cannot be installed on MacOS X. So, this also adds platform_system=="Linux" to the logshipper dep (which was already done for logshipper's pyinotify dep) to allow building a virtualenv on MacOS X. That looks like this:

logshipper@ git+/~https://github.com/StackStorm/logshipper.git@stackstorm_patched ; platform_system=="Linux"

And it standardizes the markers format (space before and after ;) of the pyinotify dep which is required by logshipper.

dist_utils.py

I adjusted the dist_utils.py functions to maintain the same functionality. Note however that I plan to use pants to replace all the python packaging bits, including dist_utils.py. So the dist_utils.py changes are a stop-gap to keep things working until we get the rest of the pants changes in. I added these lines to 20 copies of the dist_utils.py file:

st2/scripts/dist_utils.py

Lines 125 to 130 in 2b0cd75

elif vcs_prefix in line and line.count("@") == 2:
# PEP 440 direct reference: <package name>@ <url>@version
req_name, link = line.split("@", 1)
req_name = req_name.strip()
link = f"{link.strip()}#egg={req_name}"
return link, req_name

fixate-requirements.py

I also had to make a slight adjustment to fixate-requirements.py. This codepath is only used on CircleCI during package build when rpmbuild runs a make target that runs fixate-requirements. It does not run normally because we use pip 20, but rpmbuild runs the script before pipis updated from 19 to 20. So, this makes that corner case in our circleci workflow work like everywhere else we run fixate-requirements. Here is the new code in fixate-requirements.py:

if hasattr(req, "req") and req.req and str(req.req).count("@") == 2:
# PEP 440 direct reference
rline = str(linkreq.req)
# Also write out environment markers
if linkreq.markers:
rline += " ; {}".format(str(linkreq.markers))
else:
rline = str(linkreq.link)


This depends on StackStorm/st2-packages#722

This adds support for PEP 440 requirements instead of using the
pip-specific VCS format.
see: https://peps.python.org/pep-0440/#direct-references

This facilitates using newer tooling that does not support using the
legacy pip VCS format.

I adjusted the dist_utils.py functions to maintain the same functionality.
Note however that I plan to use pants to replace all the python packaging
bits, including dist_utils.py. So the dist_utils.py changes are a stop-gap
to keep things working until we get the rest of the pants changes in.
Adding `platform_system=="Linux"` makes some development on MacOS X possible.
It at least makes it possible to build a virtualenv.
@cognifloyd cognifloyd added this to the 3.8.0 milestone Jul 17, 2022
@cognifloyd cognifloyd added external dependency no changelog No Changelog.rst needed for this PR refactor labels Jul 17, 2022
@cognifloyd cognifloyd self-assigned this Jul 17, 2022
@cognifloyd cognifloyd requested a review from a team July 17, 2022 01:27
@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Jul 17, 2022
@cognifloyd cognifloyd marked this pull request as draft July 17, 2022 01:30
This is not needed during `make wheelhouse` in st2-packages.
But, rpmbuild runs fixate-requirements again when running build_os_package.sh
in a new rpmbuild venv that does not have pip-20 yet.
So, this makes that corner case in our circleci workflow work like.
@cognifloyd cognifloyd marked this pull request as ready for review July 18, 2022 05:27
@cognifloyd cognifloyd removed the no changelog No Changelog.rst needed for this PR label Jul 18, 2022
Copy link
Member

@rush-skills rush-skills left a comment

Choose a reason for hiding this comment

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

LGTM

@cognifloyd cognifloyd requested a review from a team July 19, 2022 19:26
Copy link
Contributor

@amanda11 amanda11 left a comment

Choose a reason for hiding this comment

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

LGTM

@cognifloyd cognifloyd merged commit eb403c4 into master Jul 25, 2022
@cognifloyd cognifloyd deleted the pep-440-reqs branch July 25, 2022 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external dependency pantsbuild refactor size/L PR that changes 100-499 lines. Requires some effort to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants