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

AttributeError: Requirement instance has no attribute 'name' #416

Closed
znerol opened this issue Jun 26, 2019 · 5 comments
Closed

AttributeError: Requirement instance has no attribute 'name' #416

znerol opened this issue Jun 26, 2019 · 5 comments

Comments

@znerol
Copy link

znerol commented Jun 26, 2019

When lexicon is installed via epel-repos on centos, it currently crashes with an AttributeError when attempting to discover provider requirements with the following stack trace:

$ lexicon --help
Traceback (most recent call last):
  File "/usr/bin/lexicon", line 9, in <module>
    load_entry_point('dns-lexicon==3.2.6', 'console_scripts', 'lexicon')()
  File "/usr/lib/python2.7/site-packages/lexicon/cli.py", line 100, in main
    parsed_args = generate_cli_main_parser().parse_args()
  File "/usr/lib/python2.7/site-packages/lexicon/parser.py", line 53, in generate_cli_main_parser
    for provider, available in discovery.find_providers().items():
  File "/usr/lib/python2.7/site-packages/lexicon/discovery.py", line 25, in find_providers
    for provider in providers_list}
  File "/usr/lib/python2.7/site-packages/lexicon/discovery.py", line 25, in <dictcomp>
    for provider in providers_list}
  File "/usr/lib/python2.7/site-packages/lexicon/discovery.py", line 46, in _resolve_requirements
    pkg_resources.get_distribution(requirement.name)
AttributeError: Requirement instance has no attribute 'name'

Dockerfile for reproduction:

FROM centos:7

ENV container docker

RUN yum install -y epel-release
RUN yum install -y python2-dns-lexicon

Instructions to build/run:

  1. Place Dockerfile from above into an empty directory and cd into it.
  2.  docker build -t centos-lexicon-attributeerror-repro .
     docker run -it --rm centos-lexicon-attributeerror-repro lexicon --help
    

This stopps happening when reverting 1f8b377

@adferrand
Copy link
Collaborator

Hello @znerol! Thanks a lot for your report, it is always difficult to correctly track compatibility over all LTS distributions, because of their wide lifetime.

Could you confirm that if you revert 1f8b377, Lexicon is still able to recognize that a given provider with extra dependencies has not these dependencies fulfilled with the bare Lexicon installation?

@znerol
Copy link
Author

znerol commented Jun 26, 2019

Regrettably another fix is necessary in order to make this installable from source due to a very old requests package.

$ cat centos7.patch 
diff --git a/lexicon/discovery.py b/lexicon/discovery.py
index cc4ab27..9613f59 100644
--- a/lexicon/discovery.py
+++ b/lexicon/discovery.py
@@ -43,7 +43,7 @@ def _resolve_requirements(provider, distribution):
         # Extra is defined
         try:
             for requirement in requirements:
-                pkg_resources.get_distribution(requirement.name)
+                pkg_resources.get_distribution(requirement)
         except (pkg_resources.DistributionNotFound, pkg_resources.VersionConflict):
             # At least one extra requirement is not fulfilled
             return False
diff --git a/setup.py b/setup.py
index 16dddf6..846e5f1 100644
--- a/setup.py
+++ b/setup.py
@@ -111,7 +111,7 @@ setup(
     # requirements files see:
     # https://packaging.python.org/en/latest/requirements.html
     install_requires=[
-        'requests[security]',
+        'requests',
         'tldextract',
         'future',
         'cryptography',

Build docker image with patch applied:

$ cat Dockerfile
FROM centos:7

ENV container docker

RUN yum install -y git epel-release python2-setuptools
RUN yum install -y python2-dns-lexicon
RUN yum remove -y python2-dns-lexicon

RUN git clone https://github.com/AnalogJ/lexicon /dns-lexicon
WORKDIR /dns-lexicon
COPY centos7.patch centos7.patch
RUN git apply centos7.patch

RUN python setup.py install
$ docker build -t lexicon-git .
[...]

Output of lexicon --help:

$ docker run -it --rm lexicon-git lexicon --help
usage: lexicon [-h] [--version] [--delegated DELEGATED]
               [--config-dir CONFIG_DIR]
               
               {powerdns,cloudxns,sakuracloud,memset,dnspark,zonomi,hover,hetzner,zilore,dnspod,vultr,gehirn,dnsimple,ovh,nfsn,namecheap,route53,linode,exoscale,plesk,googleclouddns,transip,cloudns,cloudflare,pointhq,localzone,glesys,rackspace,nsone,infoblox,auto,aurora,online,conoha,onapp,easyname,namesilo,godaddy,subreg,aliyun,rage4,inwx,gandi,henet,easydns,luadns,internetbs,softlayer,zeit,dnsmadeeasy,netcup,constellix,linode4,digitalocean,azure,gratisdns,yandex}
               ...

Create, Update, Delete, List DNS entries

positional arguments:
  {powerdns,cloudxns,sakuracloud,memset,dnspark,zonomi,hover,hetzner,zilore,dnspod,vultr,gehirn,dnsimple,ovh,nfsn,namecheap,route53,linode,exoscale,plesk,googleclouddns,transip,cloudns,cloudflare,pointhq,localzone,glesys,rackspace,nsone,infoblox,auto,aurora,online,conoha,onapp,easyname,namesilo,godaddy,subreg,aliyun,rage4,inwx,gandi,henet,easydns,luadns,internetbs,softlayer,zeit,dnsmadeeasy,netcup,constellix,linode4,digitalocean,azure,gratisdns,yandex}
                        specify the DNS provider to use
    powerdns            powerdns provider
    cloudxns            cloudxns provider
    sakuracloud         sakuracloud provider
    memset              memset provider
    dnspark             dnspark provider
    zonomi              zonomi provider
    hover               hover provider
    hetzner             hetzner provider
    zilore              zilore provider
    dnspod              dnspod provider
    vultr               vultr provider
    gehirn              gehirn provider
    dnsimple            dnsimple provider
    ovh                 ovh provider
    nfsn                nfsn provider
    namecheap           namecheap provider
    route53             route53 provider
    linode              linode provider
    exoscale            exoscale provider
    plesk               plesk provider
    googleclouddns      googleclouddns provider
    transip             transip provider
    cloudns             cloudns provider
    cloudflare          cloudflare provider
    pointhq             pointhq provider
    localzone           localzone provider
    glesys              glesys provider
    rackspace           rackspace provider
    nsone               nsone provider
    infoblox            infoblox provider
    auto                auto provider
    aurora              aurora provider
    online              online provider
    conoha              conoha provider
    onapp               onapp provider
    easyname            easyname provider
    namesilo            namesilo provider
    godaddy             godaddy provider
    subreg              subreg provider
    aliyun              aliyun provider
    rage4               rage4 provider
    inwx                inwx provider
    gandi               gandi provider
    henet               henet provider
    easydns             easydns provider
    luadns              luadns provider
    internetbs          internetbs provider
    softlayer           softlayer provider
    zeit                zeit provider
    dnsmadeeasy         dnsmadeeasy provider
    netcup              netcup provider
    constellix          constellix provider
    linode4             linode4 provider
    digitalocean        digitalocean provider
    azure               azure provider
    gratisdns           gratisdns provider
    yandex              yandex provider

optional arguments:
  -h, --help            show this help message and exit
  --version             show the current version of lexicon
  --delegated DELEGATED
                        specify the delegated domain
  --config-dir CONFIG_DIR
                        specify the directory where to search lexicon.yml and
                        lexicon_[provider].yml configuration files (default:
                        current directory).

@adferrand
Copy link
Collaborator

adferrand commented Jun 26, 2019

Thanks for your effort. I am reproducing your steps with the branch I am about to integrate on master, to confirm the fix is supported.

@adferrand
Copy link
Collaborator

adferrand commented Jun 26, 2019

Ok, I have just confirmed that it is working on master. I am preparing the retro-fix for the EPEL package.

znerol added a commit to certhub/certhub that referenced this issue Jul 3, 2019
@znerol
Copy link
Author

znerol commented Jul 14, 2019

This has landed downstream, python2-dns-lexicon 3.2.8 is now available in EPEL/el7.

@znerol znerol closed this as completed Jul 14, 2019
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

No branches or pull requests

2 participants