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

Modernize install #76021

Merged
merged 52 commits into from
Oct 19, 2021
Merged

Modernize install #76021

merged 52 commits into from
Oct 19, 2021

Conversation

sivel
Copy link
Member

@sivel sivel commented Oct 12, 2021

SUMMARY

This PR:

  • modernizes our install, reducing dynamic code in setup.py, addition of setup.cfg
  • drops dependencies on distutils in setup.py
  • Switches to entry_points console_scripts instead of symlinked bin files
  • deprecates ansible.module_utils.ansible_release
    • This is done to largely remove symlinks within lib/, although it needed to be done anyway
    • Reverted, out of scope for this PR
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

setup.cfg

ADDITIONAL INFORMATION

TODO:

  • test symlinks

@ansibot ansibot added affects_2.13 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. networking Network category support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Oct 12, 2021
lib/ansible/cli/scripts/ansible_cli_stub.py Show resolved Hide resolved
setup.cfg Outdated
@@ -0,0 +1,54 @@
# Minimum target setuptools 39.0.1 to cover Ubuntu 18.04
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this comment (and the one below it) further?

Are they related to our minimum setuptools version in the Makefile?

$(PYTHON) -c 'import setuptools, sys; sys.exit(int(not (tuple(map(int, setuptools.__version__.split("."))) > (39, 2, 0))))'

Copy link
Member Author

Choose a reason for hiding this comment

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

That entry in the Makefile is interesting, I didn't even know it was there. I added this comment operating off of the assumption that the community team will package ansible-core 2.13 for Ubuntu 18.04. However, Ubuntu 18.04 only has setuptools 39.0.1. Which means that I needed to target the minimum feature level to what was accessible in 39.0.1.

Copy link
Member

Choose a reason for hiding this comment

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

Given that this check is here, can we raise our minimum setuptools version?

setup.cfg Show resolved Hide resolved
test/integration/targets/entry_points/runme.sh Outdated Show resolved Hide resolved
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Oct 12, 2021
@mattclay
Copy link
Member

The _PY38_MIN = sys.version_info[:2] >= (3, 8) check could be simplified to _PY38_MIN = sys.version_info >= (3, 8).

@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Oct 12, 2021
name = ansible-core
version = attr: lib.ansible.release.__version__
description = Radically simple IT automation
long_description = file: README.rst
Copy link
Member

Choose a reason for hiding this comment

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

Wild idea: why not add some changelog pointers too?

Suggested change
long_description = file: README.rst
long_description = file: README.rst, docs/docsite/rst/porting_guides/porting_guide_core_2.13.rst

Here's an example project doing this: https://pypi.org/project/attrs/#release-information.

dist = distribution('ansible-core')
ep_map = {ep.name: ep for ep in dist.entry_points if ep.group == 'console_scripts'}

parser = argparse.ArgumentParser(prog='python -m ansible', add_help=False)
Copy link
Member

Choose a reason for hiding this comment

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

It's not going to always be python. Sometimes it's python3.10 or python3 or ./path/to/venv/bin/python.
Maybe it could be something along the lines of

Suggested change
parser = argparse.ArgumentParser(prog='python -m ansible', add_help=False)
mod_path = Path(__file__)
if mod_path.parts[-1] == '__main__.py':
mod_path = f'{sys.executable} -m {(mod_path / "..").resolve().parts[-1]}'
parser = argparse.ArgumentParser(prog=str(mod_path), add_help=False)

Copy link
Member Author

Choose a reason for hiding this comment

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

meh, it's close enough for me. I'd rather not do gymnastics to figure it out.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not going to push for this. Just remembered one case where pip (with a Fedora patch on top) used __main__.py in their output and that was rather confusing.

display = Display()
except Exception as e:
print('ERROR: %s' % e, file=sys.stderr)
sys.exit(5)
Copy link
Member

Choose a reason for hiding this comment

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

Mind putting this magic value into a constant with a descriptive name?
I'd read much better if it was

Suggested change
sys.exit(5)
sys.exit(RC_CLI_INIT_FAILURE)

or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I might defer this to another PR later. I don't necessarily exactly know what rc 5 is supposed to indicate. I just copied it from the previous file. I know there is another PR attempting to better define the exit codes.

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Oct 19, 2021
pyproject.toml Outdated Show resolved Hide resolved
base_dir="$(dirname "$(dirname "$(dirname "$(dirname "${OUTPUT_DIR}")")")")"
bin_dir="$(dirname "$(command -v pip)")"

# deps are already installed, using --no-deps to avoid re-installing them
Copy link
Member

Choose a reason for hiding this comment

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

They won't be reinstalled without --no-deps either, unless there are conflicts or you also add -U. The only thing this will skip is the dependency tree resolution.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the problem we ran into, is that the venv is created with --system-site-packages and even though they are accessible that way, pip still tries to install them into the venv, as if they weren't satisfied. The problem comes about with crazy dances we have to do in code to install the correct version of cryptography.

Copy link
Member

Choose a reason for hiding this comment

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

ouch

bin_dir="$(dirname "$(command -v pip)")"

# deps are already installed, using --no-deps to avoid re-installing them
pip install "${base_dir}" --disable-pip-version-check --no-deps
Copy link
Member

Choose a reason for hiding this comment

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

Consider using pip wheel or python -m build to create a dist and then pip install that, instead of installing from dir which is not something the end-users will trigger in the wild.

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
bin/ansible Show resolved Hide resolved
lib/ansible/cli/__init__.py Outdated Show resolved Hide resolved
lib/ansible/cli/adhoc.py Outdated Show resolved Hide resolved
# * https://github.com/pypa/setuptools/commit/bd110264
from distutils.command.build_scripts import build_scripts as BuildScripts
from distutils.command.sdist import sdist as SDist
install_requires = (here / 'requirements.txt').read_text(encoding='utf-8').splitlines()
Copy link
Member

Choose a reason for hiding this comment

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

FYI, IIRC this is one of the things that would break in a zipfile where you'd have to move to pkgutil.get_data or some other managed package data access...

Copy link
Member

Choose a reason for hiding this comment

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

setup.py Outdated Show resolved Hide resolved
@sivel sivel merged commit 66a8331 into ansible:devel Oct 19, 2021
@ansible ansible locked and limited conversation to collaborators Nov 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.13 ci_verified Changes made in this PR are causing tests to fail. core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants