From 6050f5361738831a12debd373b9016a077e930df Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 05:09:23 +0000 Subject: Added support for defining command aliases in distutils configuration files, under the "[aliases]" section. To prevent recursion and to allow aliases to call the command of the same name, a given alias can be expanded only once per command-line invocation. You can define new aliases with the "alias" command, either for the local, global, or per-user configuration. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041094 --- setuptools/command/alias.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 setuptools/command/alias.py (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py new file mode 100755 index 00000000..42d6b2fc --- /dev/null +++ b/setuptools/command/alias.py @@ -0,0 +1,39 @@ +import distutils, os +from setuptools import Command +from distutils.util import convert_path +from distutils import log +from distutils.errors import * +from setuptools.command.setopt import edit_config, option_base + +class alias(option_base): + """Abstract base class for commands that mess with config files""" + + description = "set an option in setup.cfg or another config file" + + user_options = [ + ('alias=', 'a', 'the name of the new pseudo-command'), + ('command=', 'c', 'command(s) and options to invoke when used'), + ('remove', 'r', 'remove (unset) the alias'), + ] + option_base.user_options + + boolean_options = option_base.boolean_options + ['remove'] + + def initialize_options(self): + option_base.initialize_options(self) + self.alias = None + self.command = None + self.remove = None + + def finalize_options(self): + option_base.finalize_options(self) + if self.alias is None: + raise DistutilsOptionError("Must specify name (--alias/-a)") + if self.command is None and not self.remove: + raise DistutilsOptionError("Must specify --command or --remove") + + def run(self): + edit_config( + self.filename, {'aliases': {self.alias:self.command}}, + self.dry_run + ) + -- cgit v1.2.1 From 5eec64a05733986216d87dbdc52c78615ac3cda3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 05:11:20 +0000 Subject: Fix a couple of command descriptions. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041095 --- setuptools/command/alias.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 42d6b2fc..76daae7f 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -6,9 +6,9 @@ from distutils.errors import * from setuptools.command.setopt import edit_config, option_base class alias(option_base): - """Abstract base class for commands that mess with config files""" + """Define a shortcut that invokes one or more commands""" - description = "set an option in setup.cfg or another config file" + description = "define a shortcut to invoke one or more commands" user_options = [ ('alias=', 'a', 'the name of the new pseudo-command'), -- cgit v1.2.1 From ef617190807f0c5387b8151f0c08c6777b1c2b28 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 15:11:19 +0000 Subject: Restructured the 'alias' command to take arguments instead of options, and to display the definition of the named alias or of all aliases. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041096 --- setuptools/command/alias.py | 69 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 76daae7f..b184589f 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -3,37 +3,80 @@ from setuptools import Command from distutils.util import convert_path from distutils import log from distutils.errors import * -from setuptools.command.setopt import edit_config, option_base +from setuptools.command.setopt import edit_config, option_base, config_file class alias(option_base): """Define a shortcut that invokes one or more commands""" description = "define a shortcut to invoke one or more commands" + command_consumes_arguments = True user_options = [ - ('alias=', 'a', 'the name of the new pseudo-command'), - ('command=', 'c', 'command(s) and options to invoke when used'), ('remove', 'r', 'remove (unset) the alias'), ] + option_base.user_options boolean_options = option_base.boolean_options + ['remove'] + def initialize_options(self): option_base.initialize_options(self) - self.alias = None - self.command = None + self.args = None self.remove = None + def finalize_options(self): option_base.finalize_options(self) - if self.alias is None: - raise DistutilsOptionError("Must specify name (--alias/-a)") - if self.command is None and not self.remove: - raise DistutilsOptionError("Must specify --command or --remove") + if self.remove and len(self.args)<>1: + raise DistutilsOptionError( + "Must specify exactly one argument (the alias name) when " + "using --remove" + ) + + + + + + + def run(self): - edit_config( - self.filename, {'aliases': {self.alias:self.command}}, - self.dry_run - ) + aliases = self.distribution.get_option_dict('aliases') + + if not self.args: + print "Command Aliases" + print "---------------" + for alias in aliases: + print "setup.py alias", format_alias(alias, aliases) + return + + elif len(self.args)==1: + alias, = self.args + if self.remove: + command = None + elif alias in aliases: + print "setup.py alias", format_alias(alias, aliases) + return + else: + print "No alias definition found for %r" % alias + return + else: + alias = self.args[0] + command = ' '.join(map(repr,self.args[1:])) + + edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run) + + +def format_alias(name, aliases): + source, command = aliases[name] + if source == config_file('global'): + source = '--global-config ' + elif source == config_file('user'): + source = '--user-config ' + elif source == config_file('local'): + source = '' + else: + source = '--filename=%r' % source + return source+name+' '+command + + -- cgit v1.2.1 From 1d7b59f5172a215ad9961e2eb8bbd1756b941a5f Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 8 Jul 2005 15:49:53 +0000 Subject: Cleaner argument quoting in command aliases. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041098 --- setuptools/command/alias.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index b184589f..f5368b29 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -5,6 +5,15 @@ from distutils import log from distutils.errors import * from setuptools.command.setopt import edit_config, option_base, config_file +def shquote(arg): + """Quote an argument for later parsing by shlex.split()""" + for c in '"', "'", "\\", "#": + if c in arg: return repr(arg) + if arg.split()<>[arg]: + return repr(arg) + return arg + + class alias(option_base): """Define a shortcut that invokes one or more commands""" @@ -17,13 +26,11 @@ class alias(option_base): boolean_options = option_base.boolean_options + ['remove'] - def initialize_options(self): option_base.initialize_options(self) self.args = None self.remove = None - def finalize_options(self): option_base.finalize_options(self) if self.remove and len(self.args)<>1: @@ -32,13 +39,6 @@ class alias(option_base): "using --remove" ) - - - - - - - def run(self): aliases = self.distribution.get_option_dict('aliases') @@ -61,7 +61,7 @@ class alias(option_base): return else: alias = self.args[0] - command = ' '.join(map(repr,self.args[1:])) + command = ' '.join(map(shquote,self.args[1:])) edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run) -- cgit v1.2.1 From 58a658b26d1c95b31d02050dcccd648d2e4ce27b Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 20 Jun 2011 22:55:16 +0100 Subject: Changes to support 2.x and 3.x in the same codebase. --HG-- branch : distribute extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071 --- setuptools/command/alias.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index f5368b29..52384e1a 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -9,7 +9,7 @@ def shquote(arg): """Quote an argument for later parsing by shlex.split()""" for c in '"', "'", "\\", "#": if c in arg: return repr(arg) - if arg.split()<>[arg]: + if arg.split() != [arg]: return repr(arg) return arg @@ -33,7 +33,7 @@ class alias(option_base): def finalize_options(self): option_base.finalize_options(self) - if self.remove and len(self.args)<>1: + if self.remove and len(self.args) != 1: raise DistutilsOptionError( "Must specify exactly one argument (the alias name) when " "using --remove" @@ -43,10 +43,10 @@ class alias(option_base): aliases = self.distribution.get_option_dict('aliases') if not self.args: - print "Command Aliases" - print "---------------" + print("Command Aliases") + print("---------------") for alias in aliases: - print "setup.py alias", format_alias(alias, aliases) + print("setup.py alias", format_alias(alias, aliases)) return elif len(self.args)==1: @@ -54,10 +54,10 @@ class alias(option_base): if self.remove: command = None elif alias in aliases: - print "setup.py alias", format_alias(alias, aliases) + print("setup.py alias", format_alias(alias, aliases)) return else: - print "No alias definition found for %r" % alias + print("No alias definition found for %r" % alias) return else: alias = self.args[0] -- cgit v1.2.1 From a31410a54b0e756c3ee27f2bcfe2dd6301968c77 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 Feb 2014 18:41:55 -0500 Subject: Remove excess whitespace and unused imports. --- setuptools/command/alias.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 52384e1a..465d6ae4 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,7 +1,3 @@ -import distutils, os -from setuptools import Command -from distutils.util import convert_path -from distutils import log from distutils.errors import * from setuptools.command.setopt import edit_config, option_base, config_file @@ -11,17 +7,17 @@ def shquote(arg): if c in arg: return repr(arg) if arg.split() != [arg]: return repr(arg) - return arg + return arg class alias(option_base): """Define a shortcut that invokes one or more commands""" - + description = "define a shortcut to invoke one or more commands" command_consumes_arguments = True user_options = [ - ('remove', 'r', 'remove (unset) the alias'), + ('remove', 'r', 'remove (unset) the alias'), ] + option_base.user_options boolean_options = option_base.boolean_options + ['remove'] @@ -77,6 +73,3 @@ def format_alias(name, aliases): else: source = '--filename=%r' % source return source+name+' '+command - - - -- cgit v1.2.1 From 0eacd77e0ebd6a0a4e0672fbd1c77663f3507966 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 Feb 2014 18:42:42 -0500 Subject: Remove import * --- setuptools/command/alias.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 465d6ae4..05c0766b 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,4 +1,5 @@ -from distutils.errors import * +from distutils.errors import DistutilsOptionError + from setuptools.command.setopt import edit_config, option_base, config_file def shquote(arg): -- cgit v1.2.1 From 8e3f9d3253d1d0fb820dad4249d5110d017595c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 18 Jun 2014 20:31:05 +0300 Subject: Fixed PEP 8 compliancy of the setuptools.command package --- setuptools/command/alias.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 05c0766b..452a9244 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -2,10 +2,12 @@ from distutils.errors import DistutilsOptionError from setuptools.command.setopt import edit_config, option_base, config_file + def shquote(arg): """Quote an argument for later parsing by shlex.split()""" for c in '"', "'", "\\", "#": - if c in arg: return repr(arg) + if c in arg: + return repr(arg) if arg.split() != [arg]: return repr(arg) return arg @@ -18,7 +20,7 @@ class alias(option_base): command_consumes_arguments = True user_options = [ - ('remove', 'r', 'remove (unset) the alias'), + ('remove', 'r', 'remove (unset) the alias'), ] + option_base.user_options boolean_options = option_base.boolean_options + ['remove'] @@ -46,7 +48,7 @@ class alias(option_base): print("setup.py alias", format_alias(alias, aliases)) return - elif len(self.args)==1: + elif len(self.args) == 1: alias, = self.args if self.remove: command = None @@ -58,9 +60,9 @@ class alias(option_base): return else: alias = self.args[0] - command = ' '.join(map(shquote,self.args[1:])) + command = ' '.join(map(shquote, self.args[1:])) - edit_config(self.filename, {'aliases': {alias:command}}, self.dry_run) + edit_config(self.filename, {'aliases': {alias: command}}, self.dry_run) def format_alias(name, aliases): @@ -73,4 +75,4 @@ def format_alias(name, aliases): source = '' else: source = '--filename=%r' % source - return source+name+' '+command + return source + name + ' ' + command -- cgit v1.2.1 From 8af3b6ef5b4173a0d0d6735147c98c882ae98344 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:54:00 -0500 Subject: Always use Python 3 version of map --- setuptools/command/alias.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 452a9244..4532b1cc 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,5 +1,7 @@ from distutils.errors import DistutilsOptionError +from setuptools.extern.six.moves import map + from setuptools.command.setopt import edit_config, option_base, config_file -- cgit v1.2.1 From ff371f18f0076bc63da05334f7e551c1cc29e10d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 22:34:28 -0500 Subject: Strip out vendored packages and require them instead. Ref #581. --- setuptools/command/alias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 4532b1cc..35ece78d 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,6 +1,6 @@ from distutils.errors import DistutilsOptionError -from setuptools.extern.six.moves import map +from six.moves import map from setuptools.command.setopt import edit_config, option_base, config_file -- cgit v1.2.1 From 3d0cc355fb5e8012cb8c72f0e25042a5a44f31d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2017 11:49:51 -0500 Subject: Revert "Merge pull request #933 from pypa/feature/581-depend-not-bundle" This reverts commit 089cdeb489a0fa94d11b7307b54210ef9aa40511, reversing changes made to aaec654d804cb78dbb6391afff721a63f26a71cd. --- setuptools/command/alias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 35ece78d..4532b1cc 100755 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,6 +1,6 @@ from distutils.errors import DistutilsOptionError -from six.moves import map +from setuptools.extern.six.moves import map from setuptools.command.setopt import edit_config, option_base, config_file -- cgit v1.2.1 From 760e2e1df9c9c9d1fc072e7b6ad9df4c32bfc835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 27 Jul 2018 14:36:34 +0200 Subject: Remove spurious executable permissions --- setuptools/command/alias.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 setuptools/command/alias.py (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py old mode 100755 new mode 100644 -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/command/alias.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'setuptools/command/alias.py') diff --git a/setuptools/command/alias.py b/setuptools/command/alias.py index 4532b1cc..452a9244 100644 --- a/setuptools/command/alias.py +++ b/setuptools/command/alias.py @@ -1,7 +1,5 @@ from distutils.errors import DistutilsOptionError -from setuptools.extern.six.moves import map - from setuptools.command.setopt import edit_config, option_base, config_file -- cgit v1.2.1