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

tools/read-version refactors and unit tests #4268

Merged
merged 4 commits into from
Jul 24, 2023

Conversation

TheRealFalcon
Copy link
Member

Proposed Commit Message

tools/read-version refactors and unit tests

* Refactor script into importable functions
* Replace 'which' function with shutils
* Remove unused "use_long" option
* Add unit tests for read-version and add them to default pytest
* Move some utility functions out of setup.py so they can be imported
  and tested

* Refactor script into importable functions
* Replace 'which' function with shutils
* Remove unused "use_long" option
* Add unit tests for read-version and add them to default pytest
* Move some utility functions out of setup.py so they can be imported
  and tested
Copy link
Member

@holmanb holmanb left a comment

Choose a reason for hiding this comment

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

This looks good to me. I left a couple of comments inline, but I don't feel strongly about any of them.

@@ -21,6 +21,20 @@
from setuptools.command.egg_info import egg_info
from setuptools.command.install import install

sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
Copy link
Member

Choose a reason for hiding this comment

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

Could we please add a comment explaining why?


validate_version = setuptools.dist.Distribution._validate_version # type: ignore # noqa: E501

# Since read-version has a '-' and no .py extension, we have to do this
Copy link
Member

Choose a reason for hiding this comment

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

Oof - nice workaround.

@@ -290,7 +290,7 @@ per-file-ignores =

[pytest]
# TODO: s/--strict/--strict-markers/ once pytest version is high enough
testpaths = tests/unittests
testpaths = tests/unittests tools
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to add this to github actions (py3 environment, for example)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Our tox environment builds our package and then run tests against it. The tools directory isn't included in the package, so it isn't seen by the tox environment.

arg_use_tags = "--tags" in sys.argv or bool(os.environ.get("CI_RV_TAGS"))
arg_output_json = "--json" in sys.argv
output = main(arg_use_tags, arg_output_json)
sys.stdout.write(output + "\n")
Copy link
Member

Choose a reason for hiding this comment

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

Why not just print(output)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I thought there might be a good reason so I left it, but print can do the job.

@@ -19,25 +22,6 @@ def tiny_p(cmd):
)


def which(program):
Copy link
Member

Choose a reason for hiding this comment

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

nice refactor

@TheRealFalcon TheRealFalcon merged commit 1f1ca55 into canonical:main Jul 24, 2023
25 checks passed
@TheRealFalcon TheRealFalcon deleted the read-version-updates branch July 24, 2023 21:15
TheRealFalcon added a commit to TheRealFalcon/cloud-init that referenced this pull request Jul 26, 2023
* Refactor script into importable functions
* Replace 'which' function with shutils
* Remove unused "use_long" option
* Add unit tests for read-version and add them to default pytest
* Move some utility functions out of setup.py so they can be imported
  and tested
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.

2 participants