pyscaffold.contrib package¶
Subpackages¶
- pyscaffold.contrib.setuptools_scm package
- Submodules
- pyscaffold.contrib.setuptools_scm.config module
- pyscaffold.contrib.setuptools_scm.discover module
- pyscaffold.contrib.setuptools_scm.file_finder module
- pyscaffold.contrib.setuptools_scm.file_finder_git module
- pyscaffold.contrib.setuptools_scm.file_finder_hg module
- pyscaffold.contrib.setuptools_scm.git module
- pyscaffold.contrib.setuptools_scm.hacks module
- pyscaffold.contrib.setuptools_scm.hg module
- pyscaffold.contrib.setuptools_scm.integration module
- pyscaffold.contrib.setuptools_scm.utils module
- pyscaffold.contrib.setuptools_scm.version module
- pyscaffold.contrib.setuptools_scm.win_py31_compat module
- Module contents
Submodules¶
pyscaffold.contrib.configupdater module¶
Configuration file updater.
A configuration file consists of sections, lead by a “[section]” header, and followed by “name: value” entries, with continuations and such in the style of RFC 822.
The basic idea of ConfigUpdater is that a configuration file consists of three kinds of building blocks: sections, comments and spaces for separation. A section itself consists of three kinds of blocks: options, comments and spaces. This gives us the corresponding data structures to describe a configuration file.
A general block object contains the lines which were parsed and make up the block. If a block object was not changed then during writing the same lines that were parsed will be used to express the block. In case a block, e.g. an option, was changed, it is marked as updated and its values will be transformed into a corresponding string during an update of a configuration file.
Note
ConfigUpdater was created by starting from Python’s ConfigParser source code and changing it according to my needs. Thus this source code is subject to the PSF License in a way but I am not a lawyer.
-
exception
pyscaffold.contrib.configupdater.
NoSectionError
(section)[source]¶ Bases:
configparser.Error
Raised when no section matches a requested option.
-
exception
pyscaffold.contrib.configupdater.
DuplicateOptionError
(section, option, source=None, lineno=None)[source]¶ Bases:
configparser.Error
Raised by strict parsers when an option is repeated in an input source.
Current implementation raises this exception only when an option is found more than once in a single file, string or dictionary.
-
exception
pyscaffold.contrib.configupdater.
DuplicateSectionError
(section, source=None, lineno=None)[source]¶ Bases:
configparser.Error
Raised when a section is repeated in an input source.
Possible repetitions that raise this exception are: multiple creation using the API or in strict parsers when a section is found more than once in a single input file, string or dictionary.
-
exception
pyscaffold.contrib.configupdater.
NoOptionError
(option, section)[source]¶ Bases:
configparser.Error
A requested option was not found.
-
exception
pyscaffold.contrib.configupdater.
NoConfigFileReadError
[source]¶ Bases:
configparser.Error
Raised when no configuration file was read but update requested.
-
exception
pyscaffold.contrib.configupdater.
ParsingError
(source=None, filename=None)[source]¶ Bases:
configparser.Error
Raised when a configuration file does not follow legal syntax.
-
exception
pyscaffold.contrib.configupdater.
MissingSectionHeaderError
(filename, lineno, line)[source]¶ Bases:
configparser.ParsingError
Raised when a key-value pair is found before any section header.
-
class
pyscaffold.contrib.configupdater.
ConfigUpdater
(allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, space_around_delimiters=True)[source]¶ Bases:
pyscaffold.contrib.configupdater.Container
,collections.abc.MutableMapping
Parser for updating configuration files.
- ConfigUpdater follows the API of ConfigParser with some differences:
- inline comments are treated as part of a key’s value,
- only a single config file can be updated at a time,
- empty lines in values are not valid,
- the original case of sections and keys are kept,
- control over the position of a new section/key.
Following features are deliberately not implemented:
- interpolation of values,
- propagation of parameters from the default section,
- conversions of values,
- passing key/value-pairs with
default
argument, - non-strict mode allowing duplicate sections and keys.
-
NONSPACECRE
= re.compile('\\S')¶
-
OPTCRE
= re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?P<vi>=|:)\\s* # any number of space/tab,\n # followed by any of t, re.VERBOSE)¶
-
OPTCRE_NV
= re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?: # any number of space/tab,\n (?P<vi>=|:)\\s* # optionally followed , re.VERBOSE)¶
-
SECTCRE
= re.compile('\n \\[ # [\n (?P<header>[^]]+) # very permissive!\n \\] # ]\n ', re.VERBOSE)¶
-
add_section
(section)[source]¶ Create a new section in the configuration.
Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT.
Parameters: section (str or Section
) – name or Section type
-
get
(section, option)[source]¶ Gets an option value for a given section.
Parameters: Returns: Option object holding key/value pair
Return type: Option
-
has_option
(section, option)[source]¶ Checks for the existence of a given option in a given section.
Parameters: Returns: whether the option exists in the given section
Return type:
-
has_section
(section)[source]¶ Returns whether the given section exists.
Parameters: section (str) – name of section Returns: wether the section exists Return type: bool
-
items
(section=<object object>)[source]¶ Return a list of (name, value) tuples for options or sections.
If section is given, return a list of tuples with (name, value) for each option in the section. Otherwise, return a list of tuples with (section_name, section_type) for each section.
Parameters: section (str) – optional section name, default UNSET Returns: list of Section
orOption
objectsReturn type: list
-
options
(section)[source]¶ Returns list of configuration options for the named section.
Parameters: section (str) – name of section Returns: list of option names Return type: list
-
optionxform
(optionstr)[source]¶ Converts an option key to lower case for unification
Parameters: optionstr (str) – key name Returns: unified option name Return type: str
-
read_file
(f, source=None)[source]¶ Like read() but the argument must be a file-like object.
The
f
argument must be iterable, returning one line at a time. Optional second argument is thesource
specifying the name of the file being read. If not given, it is taken from f.name. Iff
has noname
attribute,<???>
is used.Parameters: - f – file like object
- source (str) – reference name for file object, default None
-
remove_option
(section, option)[source]¶ Remove an option.
Parameters: Returns: whether the option was actually removed
Return type:
-
remove_section
(name)[source]¶ Remove a file section.
Parameters: name – name of the section Returns: whether the section was actually removed Return type: bool
-
sections_blocks
()[source]¶ Returns all section blocks
Returns: list of Section
blocksReturn type: list
-
validate_format
(**kwargs)[source]¶ Call ConfigParser to validate config
Parameters: kwargs – are passed to configparser.ConfigParser
pyscaffold.contrib.ptr module¶
Implementation
-
class
pyscaffold.contrib.ptr.
CustomizedDist
(attrs=None)[source]¶ Bases:
setuptools.dist.Distribution
-
allow_hosts
= None¶
-
fetch_build_egg
(req)[source]¶ Specialized version of Distribution.fetch_build_egg that respects respects allow_hosts and index_url.
-
index_url
= None¶
-
-
class
pyscaffold.contrib.ptr.
PyTest
(dist, **kw)[source]¶ Bases:
setuptools.command.test.test
>>> import setuptools >>> dist = setuptools.Distribution() >>> cmd = PyTest(dist)
-
static
ensure_setuptools_version
()[source]¶ Due to the fact that pytest-runner is often required (via setup-requires directive) by toolchains that never invoke it (i.e. they’re only installing the package, not testing it), instead of declaring the dependency in the package metadata, assert the requirement at run time.
-
finalize_options
()[source]¶ Set final values for all the options that this command supports. This is always called as late as possible, ie. after any option assignments from the command-line or from other commands have been done. Thus, this is the place to code option dependencies: if ‘foo’ depends on ‘bar’, then it is safe to set ‘foo’ from ‘bar’ as long as ‘foo’ still has the same value it was assigned in ‘initialize_options()’.
This method must be implemented by all command classes.
-
initialize_options
()[source]¶ Set default values for all the options that this command supports. Note that these defaults may be overridden by other commands, by the setup script, by config files, or by the command-line. Thus, this is not the place to code dependencies between options; generally, ‘initialize_options()’ implementations are just a bunch of “self.foo = None” assignments.
This method must be implemented by all command classes.
-
install_extra_dists
(dist)[source]¶ Install extras that are indicated by markers or install all extras if ‘–extras’ is indicated.
-
static
marker_passes
(marker)[source]¶ Given an environment marker, return True if the marker is valid and matches this environment.
-
run
()[source]¶ Override run to ensure requirements are available in this session (but don’t install them anywhere).
-
user_options
= [('extras', None, 'Install (all) setuptools extras when running tests'), ('index-url=', None, 'Specify an index url from which to retrieve dependencies'), ('allow-hosts=', None, 'Whitelist of comma-separated hosts to allow when retrieving dependencies'), ('addopts=', None, 'Additional options to be passed verbatim to the pytest runner')]¶
-
static
Module contents¶
Contribution packages used by PyScaffold
All packages inside contrib
are external packages that come with their
own licences and are not part of the PyScaffold source code itself.
The reason for shipping these dependencies directly is to avoid problems in
the resolution of setup_requires
dependencies that occurred more often
than not, see issues #71 and #72.
Currently the contrib packages are:
- setuptools_scm v3.1
- pytest-runner 4.2
- configupdater 0.3
The packages/modules were just copied over.