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 Python 2 support from CLI #5512

Merged
merged 8 commits into from
Jan 21, 2020
Merged

Remove Python 2 support from CLI #5512

merged 8 commits into from
Jan 21, 2020

Conversation

ofek
Copy link
Contributor

@ofek ofek commented Jan 17, 2020

@codecov
Copy link

codecov bot commented Jan 17, 2020

Codecov Report

Merging #5512 into master will decrease coverage by 3.22%.
The diff coverage is 94.28%.

Impacted Files Coverage Δ
...checks_dev/datadog_checks/dev/tooling/constants.py 96.15% <0%> (-0.15%) ⬇️
...v/datadog_checks/dev/tooling/configuration/core.py 100% <100%> (ø) ⬆️
...tadog_checks/dev/tooling/configuration/template.py 100% <100%> (ø) ⬆️
...cks/dev/tooling/configuration/consumers/example.py 100% <100%> (ø) ⬆️
...og_checks_dev/datadog_checks/dev/tooling/create.py 76.11% <100%> (ø) ⬆️
...tadog_checks_dev/datadog_checks/dev/tooling/git.py 93.84% <100%> (ø) ⬆️
...v/datadog_checks/dev/tooling/configuration/spec.py 100% <100%> (ø) ⬆️
.../datadog_checks/dev/tooling/configuration/utils.py 100% <100%> (ø) ⬆️
...cks_dev/datadog_checks/dev/tooling/requirements.py 72.64% <50%> (ø) ⬆️
datadog_checks_dev/datadog_checks/dev/compat.py 50% <0%> (-50%) ⬇️
... and 823 more

Copy link
Contributor

@therve therve left a comment

Choose a reason for hiding this comment

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

Looks good, one small change. There is a unicode_literals import to remove too. Do we need the ensure_unicode calls, or can we replace by by a direct encode?

repo = 'datadog-agent' if repo_choice == 'agent' else 'integrations-{}'.format(repo_choice)
echo_warning('`{}` directory `{}` does not exist, defaulting to the current location.'.format(repo, root))
repo = 'datadog-agent' if repo_choice == 'agent' else f'integrations-{repo_choice}'
echo_warning(f'`{repo}` directory `{root}` does not exist, defaulting to the current location.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: another way to show "this is the output of a string" than using backticks is the !r specifier, e.g. f"some {string!r}" is formatted as some 'string'... We could consider migrating to that as a follow-up PR? 😄

datadog_checks_dev/datadog_checks/dev/tooling/create.py Outdated Show resolved Hide resolved
datadog_checks_dev/setup.py Show resolved Hide resolved
@ofek ofek merged commit 4c22dea into master Jan 21, 2020
@ofek ofek deleted the ofek/d3 branch January 21, 2020 01:12
AlexandreYang pushed a commit that referenced this pull request Jan 30, 2020
* Remove Python 2 support from CLI

* oops

* Update tox.ini

* test all

* .

* ok

* address

* nice
@fmpro12
Copy link

fmpro12 commented May 27, 2020

Hey, can be same issue in agent version 7.19?

@ofek
Copy link
Contributor Author

ofek commented May 27, 2020

@fmpro12 Hello! Yes Agent 7.x is Python 3-only. You may use Agent 6 if you cannot immediately update custom checks to support Python 3.

Was that your question?

@fmpro12
Copy link

fmpro12 commented May 27, 2020

Okay, let me explain issue on high level.
I'm trying to install integrations-extras package on top of the latest agent, during installation I got the error:

root@ip-172-31-42-147:~/dd# ddev config set repo extras
Traceback (most recent call last):
File "/usr/local/bin/ddev", line 7, in
from datadog_checks.dev.tooling.cli import ddev
File "/usr/local/lib/python2.7/dist-packages/datadog_checks/dev/tooling/cli.py", line 39
echo_warning(f'Unable to create config file located at {CONFIG_FILE}. Please check your permissions.')
^
SyntaxError: invalid syntax

How I can fix that?

@ofek
Copy link
Contributor Author

ofek commented May 27, 2020

You'll need to use Python 3.

@fmpro12
Copy link

fmpro12 commented May 28, 2020

And hot exactly to do that?

I'm following this instruction - https://docs.datadoghq.com/integrations/ping/.

See commands I'm running on my ubuntu 18.04:

sudo apt update
sudo apt install python3.8
sudo apt-get install python3-pip -y
sudo apt-get install python3.8-dev
sudo python3.8 -m pip install "datadog-checks-dev[cli]"
sudo mkdir $HOME/dd && cd $HOME/dd
sudo git clone https://github.com/DataDog/integrations-extras.git

Then #ddev config set extras ./integrations-extras and i got:

Traceback (most recent call last):
File "/usr/local/bin/ddev", line 7, in
from datadog_checks.dev.tooling.cli import ddev
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/cli.py", line 6, in
from .commands import ALL_COMMANDS
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/init.py", line 6, in
from .clean import clean
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/clean.py", line 42, in
def clean(ctx, check, compiled_only, all_matches, force, verbose):
File "/usr/lib/python3/dist-packages/click/decorators.py", line 151, in decorator
_param_memo(f, ArgumentClass(param_decls, **attrs))
File "/usr/lib/python3/dist-packages/click/core.py", line 1699, in init
Parameter.init(self, param_decls, required=required, **attrs)
TypeError: init() got an unexpected keyword argument 'autocompletion'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in
import apt
File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/local/bin/ddev", line 7, in
from datadog_checks.dev.tooling.cli import ddev
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/cli.py", line 6, in
from .commands import ALL_COMMANDS
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/init.py", line 6, in
from .clean import clean
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/clean.py", line 42, in
def clean(ctx, check, compiled_only, all_matches, force, verbose):
File "/usr/lib/python3/dist-packages/click/decorators.py", line 151, in decorator
_param_memo(f, ArgumentClass(param_decls, **attrs))
File "/usr/lib/python3/dist-packages/click/core.py", line 1699, in init
Parameter.init(self, param_decls, required=required, **attrs)
TypeError: init() got an unexpected keyword argument 'autocompletion'
root@ip-172-31-17-211:~/dd# ddev config set extras ./integrations-extras
Traceback (most recent call last):
File "/usr/local/bin/ddev", line 7, in
from datadog_checks.dev.tooling.cli import ddev
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/cli.py", line 6, in
from .commands import ALL_COMMANDS
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/init.py", line 6, in
from .clean import clean
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/clean.py", line 42, in
def clean(ctx, check, compiled_only, all_matches, force, verbose):
File "/usr/lib/python3/dist-packages/click/decorators.py", line 151, in decorator
_param_memo(f, ArgumentClass(param_decls, **attrs))
File "/usr/lib/python3/dist-packages/click/core.py", line 1699, in init
Parameter.init(self, param_decls, required=required, **attrs)
TypeError: init() got an unexpected keyword argument 'autocompletion'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in
import apt
File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/local/bin/ddev", line 7, in
from datadog_checks.dev.tooling.cli import ddev
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/cli.py", line 6, in
from .commands import ALL_COMMANDS
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/init.py", line 6, in
from .clean import clean
File "/usr/local/lib/python3.8/dist-packages/datadog_checks/dev/tooling/commands/clean.py", line 42, in
def clean(ctx, check, compiled_only, all_matches, force, verbose):
File "/usr/lib/python3/dist-packages/click/decorators.py", line 151, in decorator
_param_memo(f, ArgumentClass(param_decls, **attrs))
File "/usr/lib/python3/dist-packages/click/core.py", line 1699, in init
Parameter.init(self, param_decls, required=required, **attrs)
TypeError: init() got an unexpected keyword argument 'autocompletion'

@therve
Copy link
Contributor

therve commented May 28, 2020

It looks like you're using an outdated version of click. Maybe try to uninstall the package and install it using pip. It would make some sense to use a virtualenv too.

It may be worth pursuing this discussion in an issue too. Thanks!

@fmpro12
Copy link

fmpro12 commented May 28, 2020

Thanks for your response, indeed updating of click fixed the issue.

However now I stuck on:

ddev -e release build ping
Building ping...
Traceback (most recent call last):
File "setup.py", line 4, in
from setuptools import setup
ImportError: No module named setuptools

I installed setuptools but still, get this error.

@fmpro12
Copy link

fmpro12 commented Jun 1, 2020

Okay, I was able to fix that wasn't so simple, but the working procedure is below:

apt update
apt-get install python3-pip -y
git clone https://github.com/DataDog/integrations-extras.git
pip3 install "datadog-checks-dev[cli]"
pip3 install "click" --upgrade
cd /usr/bin/
ln -fs python3.6 python
cd /home/ubuntu/
ddev config set extras ./integrations-extras
ddev -e release build ping

There is a mistake in your procedure:

https://docs.datadoghq.com/developers/integrations/new_check_howto/?tab=configurationfile#developer-toolkit

  1. It's should be pip3 install and not pip install - because of python3.

  2. Additionally to pip3 need to upgrade click to version 7

  3. Need to connect create a link between python and python 3.6

ofek added a commit that referenced this pull request Jun 1, 2020
ofek added a commit that referenced this pull request Jun 1, 2020
* no more validation for py3 nor logos

* update Click range #5512 (comment)

* ensure non-ancient appdirs https://pypi.org/project/appdirs/#history
@ofek
Copy link
Contributor Author

ofek commented Jun 3, 2020

This should be fixed in 3.8.0 https://pypi.org/project/datadog-checks-dev/3.8.0/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants