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

Remove need for distutils.util (distutils now deprecated) #99

Merged
merged 2 commits into from
Dec 31, 2024

Conversation

cdtomkins
Copy link
Contributor

@cdtomkins cdtomkins commented Dec 31, 2024

Use setuptools to provide distutils.util (distutils deprecated w/ python >=3.12)

Tested with Getting Started steps, briefly:

  • Edited env files
  • poetry shell
  • poetry lock
  • poetry install
  • invoke build start

Before:

Traceback (most recent call last):
  File "/home/chris/.cache/pypoetry/virtualenvs/nautobot-docker-compose-67IBQzlA-py3.12/bin/invoke", line 8, in <module>
    sys.exit(program.run())
             ^^^^^^^^^^^^^
  File "/home/chris/.cache/pypoetry/virtualenvs/nautobot-docker-compose-67IBQzlA-py3.12/lib/python3.12/site-packages/invoke/program.py", line 387, in run
    self.parse_collection()
  File "/home/chris/.cache/pypoetry/virtualenvs/nautobot-docker-compose-67IBQzlA-py3.12/lib/python3.12/site-packages/invoke/program.py", line 479, in parse_collection
    self.load_collection()
  File "/home/chris/.cache/pypoetry/virtualenvs/nautobot-docker-compose-67IBQzlA-py3.12/lib/python3.12/site-packages/invoke/program.py", line 716, in load_collection
    module, parent = loader.load(coll_name)
                     ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/chris/.cache/pypoetry/virtualenvs/nautobot-docker-compose-67IBQzlA-py3.12/lib/python3.12/site-packages/invoke/loader.py", line 91, in load
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/chris/repos/nautobot-docker-compose/tasks.py", line 3, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils'

After:

#22 [nautobot] resolving provenance for metadata file
 Service nautobot  Built
#22 DONE 0.0s
Starting Nautobot in detached mode...
Running docker compose command "up --detach"
 Network nautobot-docker-compose_default  Creating
 Network nautobot-docker-compose_default  Created
 Container nautobot-docker-compose-redis-1  Creating
 Container nautobot-docker-compose-db-1  Creating
 Container nautobot-docker-compose-db-1  Created
 Container nautobot-docker-compose-redis-1  Created
 Container nautobot-docker-compose-nautobot-1  Creating
 Container nautobot-docker-compose-nautobot-1  Created
 Container nautobot-docker-compose-celery_beat-1  Creating
 Container nautobot-docker-compose-celery_worker-1  Creating
 Container nautobot-docker-compose-celery_worker-1  Created
 Container nautobot-docker-compose-celery_beat-1  Created
 Container nautobot-docker-compose-redis-1  Starting
 Container nautobot-docker-compose-db-1  Starting
 Container nautobot-docker-compose-redis-1  Started
 Container nautobot-docker-compose-db-1  Started
 Container nautobot-docker-compose-nautobot-1  Starting
 Container nautobot-docker-compose-nautobot-1  Started
 Container nautobot-docker-compose-nautobot-1  Waiting
 Container nautobot-docker-compose-nautobot-1  Waiting
 Container nautobot-docker-compose-nautobot-1  Healthy
 Container nautobot-docker-compose-celery_beat-1  Starting
 Container nautobot-docker-compose-nautobot-1  Healthy
 Container nautobot-docker-compose-celery_worker-1  Starting
 Container nautobot-docker-compose-celery_beat-1  Started
 Container nautobot-docker-compose-celery_worker-1  Started

@cdtomkins cdtomkins self-assigned this Dec 31, 2024
@cdtomkins cdtomkins linked an issue Dec 31, 2024 that may be closed by this pull request
@smk4664
Copy link

smk4664 commented Dec 31, 2024

Thanks for the PR! I am not sure if you want to change this, but we have moved away from strtobool in other tasks.py and opted for the following code:

def is_truthy(arg):
    """Convert "truthy" strings into Booleans.

    Examples:
        >>> is_truthy('yes')
        True
    Args:
        arg (str): Truthy string (True values are y, yes, t, true, on and 1; false values are n, no,
        f, false, off and 0. Raises ValueError if val is anything else.
    """
    if isinstance(arg, bool):
        return arg

    val = str(arg).lower()
    if val in ("y", "yes", "t", "true", "on", "1"):
        return True
    elif val in ("n", "no", "f", "false", "off", "0"):
        return False
    else:
        raise ValueError(f"Invalid truthy value: `{arg}`")

@cdtomkins
Copy link
Contributor Author

cdtomkins commented Dec 31, 2024

Thanks @smk4664! I prefer your solution; one less dependency, and distutils wasn't used anywhere else. Everything seems to work fine after testing again. I've updated the branch.

Also this better meets the migration advice in PEP 632 and the new implementation meets the original spec

@cdtomkins cdtomkins changed the title Use setuptools to provide distutils.util (distutils now deprecated) Remove need for distutils.util (distutils now deprecated) Dec 31, 2024
Copy link

@smk4664 smk4664 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Glad to have this repo updated to work with Python 3.12

@smk4664 smk4664 merged commit 5fff525 into main Dec 31, 2024
2 checks passed
@smk4664 smk4664 deleted the cdtomkins-remove-distutils-dep branch December 31, 2024 15:28
laurencc1112 pushed a commit to laurencc1112/nautobot-docker-compose-copy that referenced this pull request Feb 27, 2025
* Use setuptools to provide distutils.util (distutils deprecated w/ python >=3.12)

* Improved implementation - no need for setuptools either
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.

distutils package is removed in python version 3.12
2 participants