Skip to content

setuptools_scm does not work with setup.cfg #181

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

Closed
1oglop1 opened this issue Sep 6, 2017 · 17 comments · Fixed by #364
Closed

setuptools_scm does not work with setup.cfg #181

1oglop1 opened this issue Sep 6, 2017 · 17 comments · Fixed by #364

Comments

@1oglop1
Copy link

1oglop1 commented Sep 6, 2017

I was debuging the behaviour of setuptools_scm because I received exception from function version_keyword

File "/home/oglop/.virtualenvs/b/lib/python3.6/site-packages/setuptools_scm/integration.py", line 22, in version_keyword
    dist.metadata.version = get_version(**value)

in setuptools file config.py, all options go through parser except additional options like use_scm_version, I guess this should be handled by setuptools_scm
file : setuptools/config.py

class ConfigOptionsHandler(ConfigHandler):

    section_prefix = 'options'

    @property
    def parsers(self):
        """Metadata item name to parser function mapping."""
        parse_list = self._parse_list
        parse_list_semicolon = partial(self._parse_list, separator=';')
        parse_bool = self._parse_bool
        parse_dict = self._parse_dict

        return {
            'zip_safe': parse_bool,
            'use_2to3': parse_bool,
            'include_package_data': parse_bool,
            'package_dir': parse_dict,
            'use_2to3_fixers': parse_list,
            'use_2to3_exclude_fixers': parse_list,
            'convert_2to3_doctests': parse_list,
            'scripts': parse_list,
            'eager_resources': parse_list,
            'dependency_links': parse_list,
            'namespace_packages': parse_list,
            'install_requires': parse_list_semicolon,
            'setup_requires': parse_list_semicolon,
            'tests_require': parse_list_semicolon,
            'packages': self._parse_packages,
            'entry_points': self._parse_file,
            'py_modules': parse_list,
        }

in setuptools_scm
something goes wrong here:

[distutils.setup_keywords]
        use_scm_version = setuptools_scm.integration:version_keyword

because function version_keyword receives parameter value as str but that function expects bool - because the value did not go through the parsing process

what I do not know is how that version_keyword is called

@RonnyPfannschmidt
Copy link
Contributor

thats pretty much a setuptools bug,
to fix it it would require a additional setting for the parsers, as such its not something we can fix directly and it has to stay in setup.py

@RonnyPfannschmidt
Copy link
Contributor

@jaraco how would that one best be integrated?

@webknjaz
Copy link
Member

@idlesign could you also take a look at this plz?

@idlesign
Copy link
Member

@1oglop1 Please show your setup.py and setup.cfg.

I've tried the following, and it seems to work:

[metadata]
version = attr: setuptools_scm.get_version

@webknjaz
Copy link
Member

@idlesign you probably misunderstood the problem:

  1. To integrate setuptools_scm one needs to pass use_scm_version = True, setup_requires = ['setuptools_scm'] when calling setup() (and omit version = argument)
  2. There's possibility to declare static setup() arguments via setup.cfg instead of setup.py, so it would be:
[options]
use_scm_version = True
setup_requires =
    setuptools_scm
  1. setuptools.config reads setup.cfg and it parses type(use_scm_version) == str, which is then passed to setuptools_scm as is. The problem is that setuptools_scm expects boolean use_scm_version argument, not string.

I'd suggest adding type specifiers to the config reader in setuptools, so that one could write use_scm_version = bool: True in setup.cfg, at least for unknown (non-reserved) option names

@idlesign
Copy link
Member

idlesign commented Sep 19, 2017

To integrate setuptools_scm one needs to pass [...]

What kind of integration? I undertand the ultimate goal of setuptools_scm is getting version based on vcs data. This one is intuitively achieved with attr: setuptools_scm.get_version, as I already mentioned. There is a problem with that though: attr is not lazy enough to honor setup_requires.

@webknjaz
Copy link
Member

AFAICS, the description above is the official way of enabling setuptools_scm to do the work. And it works if put into setup.py. The goal is to make it work the same way with setup.cfg approach.

@idlesign
Copy link
Member

May be I'm missing some use case, but as it is I see no reason to complicate things.

@RonnyPfannschmidt, anything that prevents your users from using attr:, given that there will hardly be a way to pass custom params to get_version() when in setup.cfg?

@webknjaz
Copy link
Member

Okay.. But what about lazy loading of attrs? I guess this must be solved before it's usable, right?

@idlesign
Copy link
Member

idlesign commented Sep 19, 2017

Almost. It's usable already if you're lucky to have setuptools_scm available beforehand.

Yet, I have some tweaks in mind for attr: to implement in a week or so, and I'll try to put lazyness in the list.

@webknjaz
Copy link
Member

thanks, I'll be waiting for lazyness updates :)

@RonnyPfannschmidt
Copy link
Contributor

@idlesign the main problem is lack of support in setuptools, until it is added no can do,

@benoit-pierre
Copy link
Member

benoit-pierre commented Sep 19, 2017

With an additional patch to pypa/setuptools#1150:

 setuptools/dist.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git i/setuptools/dist.py w/setuptools/dist.py
index b51e9cb2..a2a4406a 100644
--- i/setuptools/dist.py
+++ w/setuptools/dist.py
@@ -369,7 +367,7 @@ class Distribution(Distribution_parse_config_files, _Distribution):
             None in (self.dependency_links, self.setup_requires)
         ):
             dist = self.__class__()
-            dist.parse_config_files()
+            dist.parse_config_files(ignore_option_errors=True)
             if self.setup_requires is None:
                 self.setup_requires = dist.setup_requires
             if self.dependency_links is None:
@@ -445,14 +443,15 @@ class Distribution(Distribution_parse_config_files, _Distribution):
         req.marker = None
         return req
 
-    def parse_config_files(self, filenames=None):
+    def parse_config_files(self, filenames=None, ignore_option_errors=False):
         """Parses configuration files from various levels
         and loads configuration.
 
         """
         _Distribution.parse_config_files(self, filenames=filenames)
 
-        parse_configuration(self, self.command_options)
+        parse_configuration(self, self.command_options,
+                            ignore_option_errors=ignore_option_errors)
         self._finalize_requires()
 
     def parse_command_line(self):
@@ -515,7 +514,7 @@ class Distribution(Distribution_parse_config_files, _Distribution):
         """Fetch an egg needed for building"""
         from setuptools.command.easy_install import easy_install
         dist = self.__class__({'script_args': ['easy_install']})
-        dist.parse_config_files()
+        dist.parse_config_files(ignore_option_errors=True)
         opts = dist.get_option_dict('easy_install')
         keep = (
             'find_links', 'site_dirs', 'index_url', 'optimize',

This seem to work:

from setuptools import setup
setup(name='project')
[metadata]
version = attr: setuptools_scm.get_version
[options]
setup_requires =
    setuptools_scm

@benoit-pierre
Copy link
Member

I amended pypa/setuptools#1150 to support the above use-case.

@RonnyPfannschmidt
Copy link
Contributor

@benoit-pierre kinda a complete no-go at first glance

@webknjaz
Copy link
Member

webknjaz commented Oct 5, 2018

Any updates on this?

@RonnyPfannschmidt
Copy link
Contributor

@webknjaz nothing about this has happened on the setuptools side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
@idlesign @RonnyPfannschmidt @webknjaz @benoit-pierre @1oglop1 and others