mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-26 01:03:35 +05:00
Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit 90081a6
git-subtree-dir: kiauh/core/submodules/simple_config_parser git-subtree-split: 90081a6539ec38adf6a1a5bb707a0e9934567c7f
This commit is contained in:
13
.editorconfig
Normal file
13
.editorconfig
Normal file
@@ -0,0 +1,13 @@
|
||||
# see https://editorconfig.org/
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
|
||||
[*.py]
|
||||
max_line_length = 88
|
||||
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
*.py[cod]
|
||||
*.pyc
|
||||
__pycache__
|
||||
.pytest_cache/
|
||||
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
.venv*/
|
||||
venv*/
|
||||
|
||||
.coverage
|
||||
htmlcov/
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Simple Config Parser
|
||||
|
||||
A custom config parser inspired by Python's configparser module.
|
||||
Specialized for handling Klipper style config files.
|
||||
|
||||
|
||||
66
pyproject.toml
Normal file
66
pyproject.toml
Normal file
@@ -0,0 +1,66 @@
|
||||
[project]
|
||||
name = "simple-config-parser"
|
||||
version = "0.0.1"
|
||||
description = "A simple config parser for Python"
|
||||
authors = [
|
||||
{name = "Dominik Willner", email = "th33xitus@gmail.com"},
|
||||
]
|
||||
readme = "README.md"
|
||||
license = {text = "GPL-3.0-only"}
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.urls]
|
||||
homepage = "https://github.com/dw-0/simple-config-parser"
|
||||
repository = "https://github.com/dw-0/simple-config-parser"
|
||||
documentation = "https://github.com/dw-0/simple-config-parser"
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev=["ruff"]
|
||||
|
||||
[tool.ruff]
|
||||
required-version = ">=0.3.4"
|
||||
respect-gitignore = true
|
||||
exclude = [".git",".github", "./docs"]
|
||||
line-length = 88
|
||||
indent-width = 4
|
||||
output-format = "full"
|
||||
|
||||
[tool.ruff.format]
|
||||
indent-style = "space"
|
||||
line-ending = "lf"
|
||||
quote-style = "double"
|
||||
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["I"]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "8.2.1"
|
||||
testpaths = ["tests/**/*.py"]
|
||||
addopts = "--cov --cov-config=pyproject.toml --cov-report=html"
|
||||
|
||||
[tool.coverage.run]
|
||||
branch = true
|
||||
source = ["src.simple_config_parser"]
|
||||
|
||||
[tool.coverage.report]
|
||||
# Regexes for lines to exclude from consideration
|
||||
exclude_also = [
|
||||
# Don't complain about missing debug-only code:
|
||||
"def __repr__",
|
||||
"if self\\.debug",
|
||||
|
||||
# Don't complain if tests don't hit defensive assertion code:
|
||||
"raise AssertionError",
|
||||
"raise NotImplementedError",
|
||||
|
||||
# Don't complain if non-runnable code isn't run:
|
||||
"if 0:",
|
||||
"if __name__ == .__main__.:",
|
||||
|
||||
# Don't complain about abstract methods, they aren't run:
|
||||
"@(abc\\.)?abstractmethod",
|
||||
]
|
||||
|
||||
[tool.coverage.html]
|
||||
title = "SimpleConfigParser Coverage Report"
|
||||
directory = "htmlcov"
|
||||
3
requirements-dev.txt
Normal file
3
requirements-dev.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
ruff >= 0.3.4
|
||||
pytest >= 8.2.1
|
||||
pytest-cov >= 5.0.0
|
||||
0
src/simple_config_parser/__init__.py
Normal file
0
src/simple_config_parser/__init__.py
Normal file
62
src/simple_config_parser/constants.py
Normal file
62
src/simple_config_parser/constants.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
import re
|
||||
|
||||
# definition of section line:
|
||||
# - then line MUST start with an opening square bracket - it is the first section marker
|
||||
# - the section marker MUST be followed by at least one character - it is the section name
|
||||
# - the section name MUST be followed by a closing square bracket - it is the second section marker
|
||||
# - the second section marker MAY be followed by any amount of whitespace characters
|
||||
# - the second section marker MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
SECTION_RE = re.compile(r"^\[(\S.*\S|\S)]\s*([#;].*)?$")
|
||||
|
||||
# definition of option line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the value MAY be of any length and character
|
||||
# - the value MAY contain any amount of trailing whitespaces
|
||||
# - the value MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTION_RE = re.compile(r"^([^;#:=\s]+)\s?[:=]\s*([^;#:=\s][^;#]*?)\s*([#;].*)?$")
|
||||
# definition of options block start line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST NOT be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the separator MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
OPTIONS_BLOCK_START_RE = re.compile(r"^([^;#:=\s]+)\s*[:=]\s*([#;].*)?$")
|
||||
|
||||
# definition of comment line:
|
||||
# - the line MAY start with any amount of whitespace characters
|
||||
# - the line MUST contain a # or ; - it is the comment marker
|
||||
# - the comment marker MAY be followed by any amount of whitespace characters
|
||||
# - the comment MAY be of any length and character
|
||||
LINE_COMMENT_RE = re.compile(r"^\s*[#;].*")
|
||||
|
||||
# definition of empty line:
|
||||
# - the line MUST contain only whitespace characters
|
||||
EMPTY_LINE_RE = re.compile(r"^\s*$")
|
||||
|
||||
BOOLEAN_STATES = {
|
||||
"1": True,
|
||||
"yes": True,
|
||||
"true": True,
|
||||
"on": True,
|
||||
"0": False,
|
||||
"no": False,
|
||||
"false": False,
|
||||
"off": False,
|
||||
}
|
||||
|
||||
HEADER_IDENT = "#_header"
|
||||
312
src/simple_config_parser/simple_config_parser.py
Normal file
312
src/simple_config_parser/simple_config_parser.py
Normal file
@@ -0,0 +1,312 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
import string
|
||||
from pathlib import Path
|
||||
from typing import Callable, Dict, List
|
||||
|
||||
from ..simple_config_parser.constants import (
|
||||
BOOLEAN_STATES,
|
||||
EMPTY_LINE_RE,
|
||||
HEADER_IDENT,
|
||||
LINE_COMMENT_RE,
|
||||
OPTION_RE,
|
||||
OPTIONS_BLOCK_START_RE,
|
||||
SECTION_RE,
|
||||
)
|
||||
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
class NoSectionError(Exception):
|
||||
"""Raised when a section is not defined"""
|
||||
|
||||
def __init__(self, section: str):
|
||||
msg = f"Section '{section}' is not defined"
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
class DuplicateSectionError(Exception):
|
||||
"""Raised when a section is defined more than once"""
|
||||
|
||||
def __init__(self, section: str):
|
||||
msg = f"Section '{section}' is defined more than once"
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
class NoOptionError(Exception):
|
||||
"""Raised when an option is not defined in a section"""
|
||||
|
||||
def __init__(self, option: str, section: str):
|
||||
msg = f"Option '{option}' in section '{section}' is not defined"
|
||||
super().__init__(msg)
|
||||
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
class SimpleConfigParser:
|
||||
"""A customized config parser targeted at handling Klipper style config files"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.header: List[str] = []
|
||||
self.config: Dict = {}
|
||||
self.current_section: str | None = None
|
||||
self.current_opt_block: str | None = None
|
||||
self.current_collector: str | None = None
|
||||
self.in_option_block: bool = False
|
||||
|
||||
def _match_section(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a section"""
|
||||
return SECTION_RE.match(line) is not None
|
||||
|
||||
def _match_option(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of an option"""
|
||||
return OPTION_RE.match(line) is not None
|
||||
|
||||
def _match_options_block_start(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a multiline option"""
|
||||
return OPTIONS_BLOCK_START_RE.match(line) is not None
|
||||
|
||||
def _match_line_comment(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of a comment"""
|
||||
return LINE_COMMENT_RE.match(line) is not None
|
||||
|
||||
def _match_empty_line(self, line: str) -> bool:
|
||||
"""Wheter or not the given line matches the definition of an empty line"""
|
||||
return EMPTY_LINE_RE.match(line) is not None
|
||||
|
||||
def _parse_line(self, line: str) -> None:
|
||||
"""Parses a line and determines its type"""
|
||||
if self._match_section(line):
|
||||
self.current_collector = None
|
||||
self.current_opt_block = None
|
||||
self.current_section = SECTION_RE.match(line).group(1)
|
||||
self.config[self.current_section] = {"_raw": line}
|
||||
|
||||
elif self._match_option(line):
|
||||
self.current_collector = None
|
||||
self.current_opt_block = None
|
||||
option = OPTION_RE.match(line).group(1)
|
||||
value = OPTION_RE.match(line).group(2)
|
||||
self.config[self.current_section][option] = {"_raw": line, "value": value}
|
||||
|
||||
elif self._match_options_block_start(line):
|
||||
self.current_collector = None
|
||||
option = OPTIONS_BLOCK_START_RE.match(line).group(1)
|
||||
self.current_opt_block = option
|
||||
self.config[self.current_section][option] = {"_raw": line, "value": []}
|
||||
|
||||
elif self.current_opt_block is not None:
|
||||
self.config[self.current_section][self.current_opt_block]["value"].append(
|
||||
line
|
||||
)
|
||||
|
||||
elif self._match_empty_line(line) or self._match_line_comment(line):
|
||||
self.current_opt_block = None
|
||||
|
||||
# if current_section is None, we are at the beginning of the file,
|
||||
# so we consider the part up to the first section as the file header
|
||||
if not self.current_section:
|
||||
self.config.setdefault(HEADER_IDENT, []).append(line)
|
||||
else:
|
||||
section = self.config[self.current_section]
|
||||
|
||||
# set the current collector to a new value, so that continuous
|
||||
# empty lines or comments are collected into the same collector
|
||||
if not self.current_collector:
|
||||
self.current_collector = self._generate_rand_id()
|
||||
section[self.current_collector] = []
|
||||
|
||||
section[self.current_collector].append(line)
|
||||
|
||||
def read_file(self, file: Path) -> None:
|
||||
"""Read and parse a config file"""
|
||||
with open(file, "r") as file:
|
||||
for line in file:
|
||||
self._parse_line(line)
|
||||
|
||||
# print(json.dumps(self.config, indent=4))
|
||||
|
||||
def write_file(self, file: Path) -> None:
|
||||
"""Write the current config to the config file"""
|
||||
if not file:
|
||||
raise ValueError("No config file specified")
|
||||
|
||||
with open(file, "w") as file:
|
||||
self._write_header(file)
|
||||
self._write_sections(file)
|
||||
|
||||
def _write_header(self, file) -> None:
|
||||
"""Write the header to the config file"""
|
||||
for line in self.config.get(HEADER_IDENT, []):
|
||||
file.write(line)
|
||||
|
||||
def _write_sections(self, file) -> None:
|
||||
"""Write the sections to the config file"""
|
||||
for section in self.get_sections():
|
||||
for key, value in self.config[section].items():
|
||||
self._write_section_content(file, key, value)
|
||||
|
||||
def _write_section_content(self, file, key, value) -> None:
|
||||
"""Write the content of a section to the config file"""
|
||||
if key == "_raw":
|
||||
file.write(value)
|
||||
elif key.startswith("#_"):
|
||||
for line in value:
|
||||
file.write(line)
|
||||
elif isinstance(value["value"], list):
|
||||
file.write(value["_raw"])
|
||||
for line in value["value"]:
|
||||
file.write(line)
|
||||
else:
|
||||
file.write(value["_raw"])
|
||||
|
||||
def get_sections(self) -> List[str]:
|
||||
"""Return a list of all section names, but exclude any section starting with '#_'"""
|
||||
return list(
|
||||
filter(
|
||||
lambda section: not section.startswith("#_"),
|
||||
self.config.keys(),
|
||||
)
|
||||
)
|
||||
|
||||
def has_section(self, section: str) -> bool:
|
||||
"""Check if a section exists"""
|
||||
return section in self.get_sections()
|
||||
|
||||
def add_section(self, section: str) -> None:
|
||||
"""Add a new section to the config"""
|
||||
if section in self.get_sections():
|
||||
raise DuplicateSectionError(section)
|
||||
|
||||
if len(self.get_sections()) >= 1:
|
||||
self._check_set_section_spacing()
|
||||
|
||||
self.config[section] = {"_raw": f"[{section}]\n"}
|
||||
|
||||
def _check_set_section_spacing(self):
|
||||
prev_section: str = self.get_sections()[-1]
|
||||
prev_section_content: Dict = self.config[prev_section]
|
||||
last_item: str = list(prev_section_content.keys())[-1]
|
||||
if last_item.startswith("#_") and prev_section_content[last_item][-1] != "\n":
|
||||
prev_section_content[last_item].append("\n")
|
||||
else:
|
||||
prev_section_content[self._generate_rand_id()] = ["\n"]
|
||||
|
||||
def remove_section(self, section: str) -> None:
|
||||
"""Remove a section from the config"""
|
||||
self.config.pop(section, None)
|
||||
|
||||
def get_options(self, section: str) -> List[str]:
|
||||
"""Return a list of all option names for a given section"""
|
||||
return list(
|
||||
filter(
|
||||
lambda option: option != "_raw" and not option.startswith("#_"),
|
||||
self.config[section].keys(),
|
||||
)
|
||||
)
|
||||
|
||||
def has_option(self, section: str, option: str) -> bool:
|
||||
"""Check if an option exists in a section"""
|
||||
return self.has_section(section) and option in self.get_options(section)
|
||||
|
||||
def set_option(self, section: str, option: str, value: str | List[str]) -> None:
|
||||
"""
|
||||
Set the value of an option in a section. If the section does not exist,
|
||||
it is created. If the option does not exist, it is created.
|
||||
"""
|
||||
if not self.has_section(section):
|
||||
self.add_section(section)
|
||||
|
||||
if not self.has_option(section, option):
|
||||
self.config[section][option] = {
|
||||
"_raw": f"{option}:\n"
|
||||
if isinstance(value, list)
|
||||
else f"{option}: {value}\n",
|
||||
"value": value,
|
||||
}
|
||||
else:
|
||||
opt = self.config[section][option]
|
||||
if not isinstance(value, list):
|
||||
opt["_raw"] = opt["_raw"].replace(opt["value"], value)
|
||||
opt["value"] = value
|
||||
|
||||
def remove_option(self, section: str, option: str) -> None:
|
||||
"""Remove an option from a section"""
|
||||
self.config[section].pop(option, None)
|
||||
|
||||
def getval(
|
||||
self, section: str, option: str, fallback: str | _UNSET = _UNSET
|
||||
) -> str | List[str]:
|
||||
"""
|
||||
Return the value of the given option in the given section
|
||||
|
||||
If the key is not found and 'fallback' is provided, it is used as
|
||||
a fallback value.
|
||||
"""
|
||||
try:
|
||||
if section not in self.get_sections():
|
||||
raise NoSectionError(section)
|
||||
if option not in self.get_options(section):
|
||||
raise NoOptionError(option, section)
|
||||
return self.config[section][option]["value"]
|
||||
except (NoSectionError, NoOptionError):
|
||||
if fallback is _UNSET:
|
||||
raise
|
||||
return fallback
|
||||
|
||||
def getint(self, section: str, option: str, fallback: int | _UNSET = _UNSET) -> int:
|
||||
"""Return the value of the given option in the given section as an int"""
|
||||
return self._get_conv(section, option, int, fallback=fallback)
|
||||
|
||||
def getfloat(
|
||||
self, section: str, option: str, fallback: float | _UNSET = _UNSET
|
||||
) -> float:
|
||||
"""Return the value of the given option in the given section as a float"""
|
||||
return self._get_conv(section, option, float, fallback=fallback)
|
||||
|
||||
def getboolean(
|
||||
self, section: str, option: str, fallback: bool | _UNSET = _UNSET
|
||||
) -> bool:
|
||||
"""Return the value of the given option in the given section as a boolean"""
|
||||
return self._get_conv(
|
||||
section, option, self._convert_to_boolean, fallback=fallback
|
||||
)
|
||||
|
||||
def _convert_to_boolean(self, value: str) -> bool:
|
||||
"""Convert a string to a boolean"""
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if value.lower() not in BOOLEAN_STATES:
|
||||
raise ValueError("Not a boolean: %s" % value)
|
||||
return BOOLEAN_STATES[value.lower()]
|
||||
|
||||
def _get_conv(
|
||||
self,
|
||||
section: str,
|
||||
option: str,
|
||||
conv: Callable[[str], int | float | bool],
|
||||
fallback: _UNSET = _UNSET,
|
||||
) -> int | float | bool:
|
||||
"""Return the value of the given option in the given section as a converted value"""
|
||||
try:
|
||||
return conv(self.getval(section, option, fallback))
|
||||
except ValueError as e:
|
||||
if fallback is not _UNSET:
|
||||
return fallback
|
||||
raise ValueError(
|
||||
f"Cannot convert {self.getval(section, option)} to {conv.__name__}"
|
||||
) from e
|
||||
|
||||
def _generate_rand_id(self) -> str:
|
||||
"""Generate a random id with 6 characters"""
|
||||
chars = string.ascii_letters + string.digits
|
||||
rand_string = "".join(secrets.choice(chars) for _ in range(12))
|
||||
return f"#_{rand_string}"
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
1337
tests/assets/klipper_config.txt
Normal file
1337
tests/assets/klipper_config.txt
Normal file
File diff suppressed because it is too large
Load Diff
32
tests/assets/test_config_1.cfg
Normal file
32
tests/assets/test_config_1.cfg
Normal file
@@ -0,0 +1,32 @@
|
||||
# a comment at the very top
|
||||
# should be treated as the file header
|
||||
|
||||
# up to the first section, including all blank lines
|
||||
|
||||
[section_1]
|
||||
option_1: value_1
|
||||
option_1_1: True # this is a boolean
|
||||
option_1_2: 5 ; this is an integer
|
||||
option_1_3: 1.123 #;this is a float
|
||||
|
||||
[section_2] ; comment
|
||||
option_2: value_2
|
||||
|
||||
; comment
|
||||
|
||||
[section_3]
|
||||
option_3: value_3 # comment
|
||||
|
||||
[section_4]
|
||||
# comment
|
||||
option_4: value_4
|
||||
|
||||
[section number 5]
|
||||
#option_5: value_5
|
||||
option_5 = this.is.value-5
|
||||
multi_option:
|
||||
# these are multi-line values
|
||||
value_5_1
|
||||
value_5_2 ; here is a comment
|
||||
value_5_3
|
||||
option_5_1: value_5_1
|
||||
33
tests/assets/test_config_2.cfg
Normal file
33
tests/assets/test_config_2.cfg
Normal file
@@ -0,0 +1,33 @@
|
||||
# a comment at the very top
|
||||
# should be treated as the file header
|
||||
|
||||
# up to the first section, including all blank lines
|
||||
|
||||
[section_1]
|
||||
option_1: value_1
|
||||
option_1_1: True # this is a boolean
|
||||
option_1_2: 5 ; this is an integer
|
||||
option_1_3: 1.123 #;this is a float
|
||||
|
||||
[section_2] ; comment
|
||||
option_2: value_2
|
||||
|
||||
; comment
|
||||
|
||||
[section_3]
|
||||
option_3: value_3 # comment
|
||||
|
||||
[section_4]
|
||||
# comment
|
||||
option_4: value_4
|
||||
|
||||
[section number 5]
|
||||
#option_5: value_5
|
||||
option_5 = this.is.value-5
|
||||
multi_option:
|
||||
# these are multi-line values
|
||||
value_5_1
|
||||
value_5_2 ; here is a comment
|
||||
value_5_3
|
||||
option_5_1: value_5_1
|
||||
# config ending with a comment
|
||||
94
tests/assets/test_config_3.cfg
Normal file
94
tests/assets/test_config_3.cfg
Normal file
@@ -0,0 +1,94 @@
|
||||
# a comment at the very top
|
||||
# should be treated as the file header
|
||||
|
||||
# up to the first section, including all blank lines
|
||||
|
||||
[section_1]
|
||||
option_1: value_1
|
||||
option_1_1: True # this is a boolean
|
||||
option_1_2: 5 ; this is an integer
|
||||
option_1_3: 1.123 #;this is a float
|
||||
|
||||
[section_2] ; comment
|
||||
option_2: value_2
|
||||
|
||||
; comment
|
||||
|
||||
[section_3]
|
||||
option_3: value_3 # comment
|
||||
|
||||
[section_4]
|
||||
# comment
|
||||
option_4: value_4
|
||||
|
||||
[section number 5]
|
||||
#option_5: value_5
|
||||
option_5 = this.is.value-5
|
||||
multi_option:
|
||||
# these are multi-line values
|
||||
value_5_1
|
||||
value_5_2 ; here is a comment
|
||||
value_5_3
|
||||
option_5_1: value_5_1
|
||||
|
||||
[gcode_macro M117]
|
||||
rename_existing: M117.1
|
||||
gcode:
|
||||
{% if rawparams %}
|
||||
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
|
||||
SET_DISPLAY_TEXT MSG="{escaped_msg}"
|
||||
RESPOND TYPE=command MSG="{escaped_msg}"
|
||||
{% else %}
|
||||
SET_DISPLAY_TEXT
|
||||
{% endif %}
|
||||
|
||||
# SDCard 'looping' (aka Marlin M808 commands) support
|
||||
#
|
||||
# Support SDCard looping
|
||||
[sdcard_loop]
|
||||
[gcode_macro M486]
|
||||
gcode:
|
||||
# Parameters known to M486 are as follows:
|
||||
# [C<flag>] Cancel the current object
|
||||
# [P<index>] Cancel the object with the given index
|
||||
# [S<index>] Set the index of the current object.
|
||||
# If the object with the given index has been canceled, this will cause
|
||||
# the firmware to skip to the next object. The value -1 is used to
|
||||
# indicate something that isn’t an object and shouldn’t be skipped.
|
||||
# [T<count>] Reset the state and set the number of objects
|
||||
# [U<index>] Un-cancel the object with the given index. This command will be
|
||||
# ignored if the object has already been skipped
|
||||
|
||||
{% if 'exclude_object' not in printer %}
|
||||
{action_raise_error("[exclude_object] is not enabled")}
|
||||
{% endif %}
|
||||
|
||||
{% if 'T' in params %}
|
||||
EXCLUDE_OBJECT RESET=1
|
||||
|
||||
{% for i in range(params.T | int) %}
|
||||
EXCLUDE_OBJECT_DEFINE NAME={i}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if 'C' in params %}
|
||||
EXCLUDE_OBJECT CURRENT=1
|
||||
{% endif %}
|
||||
|
||||
{% if 'P' in params %}
|
||||
EXCLUDE_OBJECT NAME={params.P}
|
||||
{% endif %}
|
||||
|
||||
{% if 'S' in params %}
|
||||
{% if params.S == '-1' %}
|
||||
{% if printer.exclude_object.current_object %}
|
||||
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
EXCLUDE_OBJECT_START NAME={params.S}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if 'U' in params %}
|
||||
EXCLUDE_OBJECT RESET=1 NAME={params.U}
|
||||
{% endif %}
|
||||
0
tests/line_matching/__init__.py
Normal file
0
tests/line_matching/__init__.py
Normal file
0
tests/line_matching/match_empty_line/__init__.py
Normal file
0
tests/line_matching/match_empty_line/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
not_empty
|
||||
[also_not_empty]
|
||||
#
|
||||
;
|
||||
;
|
||||
#
|
||||
option: value
|
||||
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_line_comment(parser, line):
|
||||
"""Test that a line matches the definition of a line comment"""
|
||||
assert (
|
||||
parser._match_empty_line(line) is True
|
||||
), f"Expected line '{line}' to match line comment definition!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_line_comment(parser, line):
|
||||
"""Test that a line does not match the definition of a line comment"""
|
||||
assert (
|
||||
parser._match_empty_line(line) is False
|
||||
), f"Expected line '{line}' to not match line comment definition!"
|
||||
0
tests/line_matching/match_line_comment/__init__.py
Normal file
0
tests/line_matching/match_line_comment/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
;[example_section]
|
||||
#[example_section]
|
||||
# [example_section]
|
||||
; [example_section]
|
||||
;[gcode_macro CANCEL_PRINT]
|
||||
#[gcode_macro CANCEL_PRINT]
|
||||
# [gcode_macro CANCEL_PRINT]
|
||||
; [gcode_macro CANCEL_PRINT]
|
||||
;[gcode_macro SET_PAUSE_NEXT_LAYER]
|
||||
#[gcode_macro SET_PAUSE_NEXT_LAYER]
|
||||
# [gcode_macro SET_PAUSE_NEXT_LAYER]
|
||||
; [gcode_macro SET_PAUSE_NEXT_LAYER]
|
||||
;[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
#[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
# [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
; [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
;[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
#[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
# [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
; [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
;[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
#[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
# [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
; [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
;[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
#[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
# [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
; [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
@@ -0,0 +1,5 @@
|
||||
not_a_comment: nono
|
||||
|
||||
[also not a comment]
|
||||
not_a_comment: ; comment
|
||||
not_a_comment: # comment
|
||||
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_line_comment(parser, line):
|
||||
"""Test that a line matches the definition of a line comment"""
|
||||
assert (
|
||||
parser._match_line_comment(line) is True
|
||||
), f"Expected line '{line}' to match line comment definition!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_line_comment(parser, line):
|
||||
"""Test that a line does not match the definition of a line comment"""
|
||||
assert (
|
||||
parser._match_line_comment(line) is False
|
||||
), f"Expected line '{line}' to not match line comment definition!"
|
||||
0
tests/line_matching/match_option/__init__.py
Normal file
0
tests/line_matching/match_option/__init__.py
Normal file
461
tests/line_matching/match_option/test_data/matching_data.txt
Normal file
461
tests/line_matching/match_option/test_data/matching_data.txt
Normal file
@@ -0,0 +1,461 @@
|
||||
baud: 250000
|
||||
minimum_cruise_ratio: 0.5
|
||||
square_corner_velocity: 5.0
|
||||
full_steps_per_rotation: 200
|
||||
position_min: 0
|
||||
homing_speed: 5.0
|
||||
homing_retract_dist: 5.0
|
||||
kinematics: cartesian
|
||||
kinematics: delta
|
||||
minimum_z_position: 0
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
kinematics: deltesian
|
||||
minimum_z_position: 0
|
||||
min_angle: 5
|
||||
slow_ratio: 3
|
||||
kinematics: corexy
|
||||
kinematics: corexz
|
||||
kinematics: hybrid_corexy
|
||||
kinematics: hybrid_corexz
|
||||
kinematics: polar
|
||||
kinematics: rotary_delta
|
||||
minimum_z_position: 0
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
kinematics: winch
|
||||
kinematics: none
|
||||
max_velocity: 1
|
||||
max_accel: 1
|
||||
instantaneous_corner_velocity: 1.000
|
||||
max_extrude_only_distance: 50.0
|
||||
pressure_advance: 0.0
|
||||
pressure_advance_smooth_time: 0.040
|
||||
max_power: 1.0
|
||||
pullup_resistor: 4700
|
||||
smooth_time: 1.0
|
||||
max_delta: 2.0
|
||||
pwm_cycle_time: 0.100
|
||||
min_extrude_temp: 170
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
probe_count: 3, 3
|
||||
round_probe_count: 5
|
||||
fade_start: 1.0
|
||||
fade_end: 0.0
|
||||
split_delta_z: .025
|
||||
move_check_distance: 5.0
|
||||
mesh_pps: 2, 2
|
||||
algorithm: lagrange
|
||||
bicubic_tension: .2
|
||||
x_adjust: 0
|
||||
y_adjust: 0
|
||||
z_adjust: 0
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
horizontal_move_z: 5
|
||||
probe_height: 0
|
||||
speed: 50
|
||||
probe_speed: 5
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
screw_thread: CW-M3
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
retries: 0
|
||||
retry_tolerance: 0
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
max_adjust: 4
|
||||
retries: 0
|
||||
retry_tolerance: 0
|
||||
speed: 50.0
|
||||
z_hop_speed: 15.0
|
||||
move_to_previous: False
|
||||
axes: xyz
|
||||
endstop_align_zero: False
|
||||
description: G-Code macro
|
||||
initial_duration: 0.0
|
||||
timeout: 600
|
||||
enable_force_move: False
|
||||
recover_velocity: 50.
|
||||
retract_length: 0
|
||||
retract_speed: 20
|
||||
unretract_extra_length: 0
|
||||
unretract_speed: 10
|
||||
resolution: 1.0
|
||||
default_type: echo
|
||||
default_prefix: echo:
|
||||
shaper_freq_x: 0
|
||||
shaper_freq_y: 0
|
||||
shaper_type: mzv
|
||||
damping_ratio_x: 0.1
|
||||
damping_ratio_y: 0.1
|
||||
spi_speed: 5000000
|
||||
axes_map: x, y, z
|
||||
rate: 3200
|
||||
spi_speed: 5000000
|
||||
axes_map: x, y, z
|
||||
i2c_speed: 400000
|
||||
axes_map: x, y, z
|
||||
min_freq: 5
|
||||
max_freq: 133.33
|
||||
accel_per_hz: 75
|
||||
hz_per_sec: 1
|
||||
mcu: mcu
|
||||
deactivate_on_each_sample: True
|
||||
x_offset: 0.0
|
||||
y_offset: 0.0
|
||||
speed: 5.0
|
||||
samples: 1
|
||||
sampleretract_dist: 2.0
|
||||
samples_result: average
|
||||
samples_tolerance: 0.100
|
||||
samples_toleranceretries: 0
|
||||
pin_move_time: 0.680
|
||||
stow_on_each_sample: True
|
||||
probe_with_touch_mode: False
|
||||
pin_up_reports_not_triggered: True
|
||||
pin_up_touch_modereports_triggered: True
|
||||
recovery_time: 0.4
|
||||
sensor_type: ldc1612
|
||||
speed: 50
|
||||
horizontal_move_z: 5
|
||||
calibrate_start_x: 20
|
||||
calibrate_end_x: 200
|
||||
calibrate_y: 112.5
|
||||
max_error: 120
|
||||
hysteresis: 5
|
||||
heating_gain: 2
|
||||
extruder_heating_z: 50.
|
||||
max_validation_temp: 60.
|
||||
pullup_resistor: 4700
|
||||
inlineresistor: 0
|
||||
adc_voltage: 5.0
|
||||
voltage_offset: 0
|
||||
sensor_type: PT1000
|
||||
pullup_resistor: 4700
|
||||
spi_speed: 4000000
|
||||
tc_type: K
|
||||
tc_use_50Hz_filter: False
|
||||
tc_averaging_count: 1
|
||||
rtd_nominal_r: 100
|
||||
rtd_referencer: 430
|
||||
rtd_num_of_wires: 2
|
||||
rtd_use_50Hz_filter: False
|
||||
sensor_type: BME280
|
||||
sensor_type: AHT10
|
||||
sensor_type: temperature_mcu
|
||||
sensor_mcu: mcu
|
||||
sensor_type: temperature_host
|
||||
sensor_type: DS18B20
|
||||
sensor_type: temperature_combined
|
||||
max_power: 1.0
|
||||
shutdown_speed: 0
|
||||
cycle_time: 0.010
|
||||
hardware_pwm: False
|
||||
kick_start_time: 0.100
|
||||
off_below: 0.0
|
||||
tachometer_ppr: 2
|
||||
tachometer_poll_interval: 0.0015
|
||||
heater: extruder
|
||||
heater_temp: 50.0
|
||||
fan_speed: 1.0
|
||||
fan_speed: 1.0
|
||||
pid_deriv_time: 2.0
|
||||
target_temp: 40.0
|
||||
max_speed: 1.0
|
||||
min_speed: 0.3
|
||||
cycle_time: 0.010
|
||||
hardware_pwm: False
|
||||
initial_RED: 0.0
|
||||
initial_GREEN: 0.0
|
||||
initial_BLUE: 0.0
|
||||
initial_WHITE: 0.0
|
||||
color_order: GRB
|
||||
initial_RED: 0.0
|
||||
initial_GREEN: 0.0
|
||||
initial_BLUE: 0.0
|
||||
initial_WHITE: 0.0
|
||||
initial_RED: 0.0
|
||||
initial_GREEN: 0.0
|
||||
initial_BLUE: 0.0
|
||||
i2c_address: 98
|
||||
initial_RED: 0.0
|
||||
initial_GREEN: 0.0
|
||||
initial_BLUE: 0.0
|
||||
initial_WHITE: 0.0
|
||||
i2c_address: 98
|
||||
color_order: RGBW
|
||||
initial_RED: 0.0
|
||||
initial_GREEN: 0.0
|
||||
initial_BLUE: 0.0
|
||||
initial_WHITE: 0.0
|
||||
maximum_servo_angle: 180
|
||||
minimum_pulse_width: 0.001
|
||||
maximum_pulse_width: 0.002
|
||||
pwm: False
|
||||
cycle_time: 0.100
|
||||
hardware_pwm: False
|
||||
cycle_time: 0.100
|
||||
hardware_pwm: False
|
||||
cycle_time: 0.100
|
||||
interpolate: True
|
||||
senseresistor: 0.110
|
||||
stealthchop_threshold: 0
|
||||
driver_MSLUT0: 2863314260
|
||||
driver_MSLUT1: 1251300522
|
||||
driver_MSLUT2: 608774441
|
||||
driver_MSLUT3: 269500962
|
||||
driver_MSLUT4: 4227858431
|
||||
driver_MSLUT5: 3048961917
|
||||
driver_MSLUT6: 1227445590
|
||||
driver_MSLUT7: 4211234
|
||||
driver_W0: 2
|
||||
driver_W1: 1
|
||||
driver_W2: 1
|
||||
driver_W3: 1
|
||||
driver_X1: 128
|
||||
driver_X2: 255
|
||||
driver_X3: 255
|
||||
driver_START_SIN: 0
|
||||
driver_START_SIN90: 247
|
||||
driver_IHOLDDELAY: 8
|
||||
driver_TPOWERDOWN: 0
|
||||
driver_TBL: 1
|
||||
driver_TOFF: 4
|
||||
driver_HEND: 7
|
||||
driver_HSTRT: 0
|
||||
driver_VHIGHFS: 0
|
||||
driver_VHIGHCHM: 0
|
||||
driver_PWM_AUTOSCALE: True
|
||||
driver_PWM_FREQ: 1
|
||||
driver_PWM_GRAD: 4
|
||||
driver_PWM_AMPL: 128
|
||||
driver_SGT: 0
|
||||
driver_SEMIN: 0
|
||||
driver_SEUP: 0
|
||||
driver_SEMAX: 0
|
||||
driver_SEDN: 0
|
||||
driver_SEIMIN: 0
|
||||
driver_SFILT: 0
|
||||
interpolate: True
|
||||
sense_resistor: 0.110
|
||||
stealthchop_threshold: 0
|
||||
driver_MULTISTEP_FILT: True
|
||||
driver_IHOLDDELAY: 8
|
||||
driver_TPOWERDOWN: 20
|
||||
driver_TBL: 2
|
||||
driver_TOFF: 3
|
||||
driver_HEND: 0
|
||||
driver_HSTRT: 5
|
||||
driver_PWM_AUTOGRAD: True
|
||||
driver_PWM_AUTOSCALE: True
|
||||
driver_PWM_LIM: 12
|
||||
driver_PWM_REG: 8
|
||||
driver_PWM_FREQ: 1
|
||||
driver_PWM_GRAD: 14
|
||||
driver_PWM_OFS: 36
|
||||
interpolate: True
|
||||
sense_resistor: 0.110
|
||||
stealthchop_threshold: 0
|
||||
driver_MULTISTEP_FILT: True
|
||||
driver_IHOLDDELAY: 8
|
||||
driver_TPOWERDOWN: 20
|
||||
driver_TBL: 2
|
||||
driver_TOFF: 3
|
||||
driver_HEND: 0
|
||||
driver_HSTRT: 5
|
||||
driver_PWM_AUTOGRAD: True
|
||||
driver_PWM_AUTOSCALE: True
|
||||
driver_PWM_LIM: 12
|
||||
driver_PWM_REG: 8
|
||||
driver_PWM_FREQ: 1
|
||||
driver_PWM_GRAD: 14
|
||||
driver_PWM_OFS: 36
|
||||
driver_SGTHRS: 0
|
||||
driver_SEMIN: 0
|
||||
driver_SEUP: 0
|
||||
driver_SEMAX: 0
|
||||
driver_SEDN: 0
|
||||
driver_SEIMIN: 0
|
||||
spi_speed: 4000000
|
||||
interpolate: True
|
||||
idle_current_percent: 100
|
||||
driver_TBL: 2
|
||||
driver_RNDTF: 0
|
||||
driver_HDEC: 0
|
||||
driver_CHM: 0
|
||||
driver_HEND: 3
|
||||
driver_HSTRT: 3
|
||||
driver_TOFF: 4
|
||||
driver_SEIMIN: 0
|
||||
driver_SEDN: 0
|
||||
driver_SEMAX: 0
|
||||
driver_SEUP: 0
|
||||
driver_SEMIN: 0
|
||||
driver_SFILT: 0
|
||||
driver_SGT: 0
|
||||
driver_SLPH: 0
|
||||
driver_SLPL: 0
|
||||
driver_DISS2G: 0
|
||||
driver_TS2G: 3
|
||||
interpolate: True
|
||||
rref: 12000
|
||||
stealthchop_threshold: 0
|
||||
driver_MSLUT0: 2863314260
|
||||
driver_MSLUT1: 1251300522
|
||||
driver_MSLUT2: 608774441
|
||||
driver_MSLUT3: 269500962
|
||||
driver_MSLUT4: 4227858431
|
||||
driver_MSLUT5: 3048961917
|
||||
driver_MSLUT6: 1227445590
|
||||
driver_MSLUT7: 4211234
|
||||
driver_W0: 2
|
||||
driver_W1: 1
|
||||
driver_W2: 1
|
||||
driver_W3: 1
|
||||
driver_X1: 128
|
||||
driver_X2: 255
|
||||
driver_X3: 255
|
||||
driver_START_SIN: 0
|
||||
driver_START_SIN90: 247
|
||||
driver_OFFSET_SIN90: 0
|
||||
driver_MULTISTEP_FILT: True
|
||||
driver_IHOLDDELAY: 6
|
||||
driver_IRUNDELAY: 4
|
||||
driver_TPOWERDOWN: 10
|
||||
driver_TBL: 2
|
||||
driver_TOFF: 3
|
||||
driver_HEND: 2
|
||||
driver_HSTRT: 5
|
||||
driver_FD3: 0
|
||||
driver_TPFD: 4
|
||||
driver_CHM: 0
|
||||
driver_VHIGHFS: 0
|
||||
driver_VHIGHCHM: 0
|
||||
driver_DISS2G: 0
|
||||
driver_DISS2VS: 0
|
||||
driver_PWM_AUTOSCALE: True
|
||||
driver_PWM_AUTOGRAD: True
|
||||
driver_PWM_FREQ: 0
|
||||
driver_FREEWHEEL: 0
|
||||
driver_PWM_GRAD: 0
|
||||
driver_PWM_OFS: 29
|
||||
driver_PWM_REG: 4
|
||||
driver_PWM_LIM: 12
|
||||
driver_SGT: 0
|
||||
driver_SEMIN: 0
|
||||
driver_SEUP: 0
|
||||
driver_SEMAX: 0
|
||||
driver_SEDN: 0
|
||||
driver_SEIMIN: 0
|
||||
driver_SFILT: 0
|
||||
driver_SG4_ANGLE_OFFSET: 1
|
||||
interpolate: True
|
||||
sense_resistor: 0.075
|
||||
stealthchop_threshold: 0
|
||||
driver_MSLUT0: 2863314260
|
||||
driver_MSLUT1: 1251300522
|
||||
driver_MSLUT2: 608774441
|
||||
driver_MSLUT3: 269500962
|
||||
driver_MSLUT4: 4227858431
|
||||
driver_MSLUT5: 3048961917
|
||||
driver_MSLUT6: 1227445590
|
||||
driver_MSLUT7: 4211234
|
||||
driver_W0: 2
|
||||
driver_W1: 1
|
||||
driver_W2: 1
|
||||
driver_W3: 1
|
||||
driver_X1: 128
|
||||
driver_X2: 255
|
||||
driver_X3: 255
|
||||
driver_START_SIN: 0
|
||||
driver_START_SIN90: 247
|
||||
driver_MULTISTEP_FILT: True
|
||||
driver_IHOLDDELAY: 6
|
||||
driver_TPOWERDOWN: 10
|
||||
driver_TBL: 2
|
||||
driver_TOFF: 3
|
||||
driver_HEND: 2
|
||||
driver_HSTRT: 5
|
||||
driver_FD3: 0
|
||||
driver_TPFD: 4
|
||||
driver_CHM: 0
|
||||
driver_VHIGHFS: 0
|
||||
driver_VHIGHCHM: 0
|
||||
driver_DISS2G: 0
|
||||
driver_DISS2VS: 0
|
||||
driver_PWM_AUTOSCALE: True
|
||||
driver_PWM_AUTOGRAD: True
|
||||
driver_PWM_FREQ: 0
|
||||
driver_FREEWHEEL: 0
|
||||
driver_PWM_GRAD: 0
|
||||
driver_PWM_OFS: 30
|
||||
driver_PWM_REG: 4
|
||||
driver_PWM_LIM: 12
|
||||
driver_SGT: 0
|
||||
driver_SEMIN: 0
|
||||
driver_SEUP: 0
|
||||
driver_SEMAX: 0
|
||||
driver_SEDN: 0
|
||||
driver_SEIMIN: 0
|
||||
driver_SFILT: 0
|
||||
driver_DRVSTRENGTH: 0
|
||||
driver_BBMCLKS: 4
|
||||
driver_BBMTIME: 0
|
||||
driver_FILT_ISENSE: 0
|
||||
i2c_address: 96
|
||||
analog_pullup_resistor: 4700
|
||||
lcd_type: hd44780
|
||||
hd44780_protocol_init: True
|
||||
lcd_type: hd44780_spi
|
||||
hd44780_protocol_init: True
|
||||
lcd_type: st7920
|
||||
lcd_type: emulated_st7920
|
||||
lcd_type: uc1701
|
||||
vcomh: 0
|
||||
invert: False
|
||||
x_offset: 0
|
||||
type: disabled
|
||||
type: list
|
||||
type: command
|
||||
type: input
|
||||
pause_on_runout: True
|
||||
event_delay: 3.0
|
||||
pause_delay: 0.5
|
||||
detection_length: 7.0
|
||||
default_nominal_filament_diameter: 1.75
|
||||
max_difference: 0.2
|
||||
measurement_delay: 100
|
||||
cal_dia1: 1.50
|
||||
cal_dia2: 2.00
|
||||
raw_dia1: 9500
|
||||
raw_dia2: 10500
|
||||
default_nominal_filament_diameter: 1.75
|
||||
max_difference: 0.200
|
||||
measurement_delay: 70
|
||||
enable: False
|
||||
measurement_interval: 10
|
||||
logging: False
|
||||
min_diameter: 1.0
|
||||
use_current_dia_while_delay: False
|
||||
sensor_type: hx711
|
||||
gain: A-128
|
||||
sample_rate: 80
|
||||
sensor_type: hx717
|
||||
gain: A-128
|
||||
sample_rate: 320
|
||||
sensor_type: ads1220
|
||||
spi_speed: 512000
|
||||
gain: 128
|
||||
sample_rate: 660
|
||||
smooth_time: 2.0
|
||||
enable_pin: !gpio0_20
|
||||
standstill_power_down: False
|
||||
baud: 115200
|
||||
feedrate_splice: 0.8
|
||||
feedrate_normal: 1.0
|
||||
auto_load_speed: 2
|
||||
auto_cancel_variation: 0.1
|
||||
sample_period: 0.000400
|
||||
@@ -0,0 +1,37 @@
|
||||
[section]
|
||||
[section with spaces]
|
||||
[section with spaces and comments] ; comment 1
|
||||
[section with spaces and comments] # comment 2
|
||||
indented_option: value
|
||||
option_with_no_value:
|
||||
another_option_with_no_value:
|
||||
indented_option_with_no_value:
|
||||
# position_min: 0
|
||||
# homing_speed: 5.0
|
||||
|
||||
### this is a comment
|
||||
; this is also a comment
|
||||
# [section]
|
||||
# [section with spaces]
|
||||
# [section with spaces and comments] ; comment 1
|
||||
;[section]
|
||||
;[section with spaces]
|
||||
;[section with spaces and comments] ; comment 1
|
||||
# commented_option: value
|
||||
#commented_option: value
|
||||
;commented_option: value
|
||||
; commented_option: value
|
||||
#
|
||||
;
|
||||
option_1 :: value
|
||||
option_1:: value
|
||||
option_1 ::value
|
||||
option_2 == value
|
||||
option_2== value
|
||||
option_2 ==value
|
||||
option_1 := value
|
||||
option_1:= value
|
||||
option_1 :=value
|
||||
option_2 := value
|
||||
option_2:= value
|
||||
option_2 :=value
|
||||
39
tests/line_matching/match_option/test_match_option.py
Normal file
39
tests/line_matching/match_option/test_match_option.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_option(parser, line):
|
||||
"""Test that a line matches the definition of an option"""
|
||||
assert (
|
||||
parser._match_option(line) is True
|
||||
), f"Expected line '{line}' to match option definition!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_option(parser, line):
|
||||
"""Test that a line does not match the definition of an option"""
|
||||
assert (
|
||||
parser._match_option(line) is False
|
||||
), f"Expected line '{line}' to not match option definition!"
|
||||
@@ -0,0 +1,15 @@
|
||||
trusted_clients:
|
||||
gcode:
|
||||
cors_domains:
|
||||
an_options_block_start_with_comment: ; this is a comment
|
||||
an_options_block_start_with_comment: # this is a comment
|
||||
options_block_start_with_comment:;this is a comment
|
||||
options_block_start_with_comment :;this is a comment
|
||||
options_block_start_with_comment:#this is a comment
|
||||
options_block_start_with_comment :#this is a comment
|
||||
parameter_temperature_(°C):
|
||||
parameter_temperature_(°C)=
|
||||
parameter_humidity_(%_RH):
|
||||
parameter_humidity_(%_RH) :
|
||||
parameter_spool_weight_(%):
|
||||
parameter_spool_weight_(%) =
|
||||
@@ -0,0 +1,31 @@
|
||||
type: jsonfile
|
||||
path: /dev/shm/drying_box.json
|
||||
baud: 250000
|
||||
minimum_cruise_ratio: 0.5
|
||||
square_corner_velocity: 5.0
|
||||
full_steps_per_rotation: 200
|
||||
position_min: 0
|
||||
homing_speed: 5.0
|
||||
# baud: 250000
|
||||
# minimum_cruise_ratio: 0.5
|
||||
# square_corner_velocity: 5.0
|
||||
# full_steps_per_rotation: 200
|
||||
# position_min: 0
|
||||
# homing_speed: 5.0
|
||||
|
||||
### this is a comment
|
||||
; this is also a comment
|
||||
;
|
||||
#
|
||||
homing_speed::
|
||||
homing_speed::
|
||||
homing_speed ::
|
||||
homing_speed ::
|
||||
homing_speed==
|
||||
homing_speed==
|
||||
homing_speed ==
|
||||
homing_speed ==
|
||||
homing_speed :=
|
||||
homing_speed :=
|
||||
homing_speed =:
|
||||
homing_speed =:
|
||||
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_options_block_start(parser, line):
|
||||
"""Test that a line matches the definition of an options block start"""
|
||||
assert (
|
||||
parser._match_options_block_start(line) is True
|
||||
), f"Expected line '{line}' to match options block start definition!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_options_block_start(parser, line):
|
||||
"""Test that a line does not match the definition of an options block start"""
|
||||
assert (
|
||||
parser._match_options_block_start(line) is False
|
||||
), f"Expected line '{line}' to not match options block start definition!"
|
||||
0
tests/line_matching/match_section/__init__,py.py
Normal file
0
tests/line_matching/match_section/__init__,py.py
Normal file
127
tests/line_matching/match_section/test_data/matching_data.txt
Normal file
127
tests/line_matching/match_section/test_data/matching_data.txt
Normal file
@@ -0,0 +1,127 @@
|
||||
[example_section]
|
||||
[gcode_macro CANCEL_PRINT]
|
||||
[gcode_macro SET_PAUSE_NEXT_LAYER]
|
||||
[gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
|
||||
[update_manager moonraker-obico]
|
||||
[include moonraker_obico_macros.cfg]
|
||||
[include moonraker-obico-update.cfg]
|
||||
[example_section two]
|
||||
[valid_content]
|
||||
[valid content]
|
||||
[content123]
|
||||
[a]
|
||||
[valid_content] # comment
|
||||
[something];comment
|
||||
[mcu]
|
||||
[printer]
|
||||
[printer]
|
||||
[stepper_x]
|
||||
[stepper_y]
|
||||
[stepper_z]
|
||||
[printer]
|
||||
[stepper_a]
|
||||
[stepper_b]
|
||||
[stepper_c]
|
||||
[delta_calibrate]
|
||||
[printer]
|
||||
[stepper_left]
|
||||
[stepper_right]
|
||||
[stepper_bed]
|
||||
[stepper_arm]
|
||||
[delta_calibrate]
|
||||
[extruder]
|
||||
[heater_bed]
|
||||
[bed_mesh]
|
||||
[bed_tilt]
|
||||
[bed_screws]
|
||||
[screws_tilt_adjust]
|
||||
[z_tilt]
|
||||
[quad_gantry_level]
|
||||
[skew_correction]
|
||||
[z_thermal_adjust]
|
||||
[safe_z_home]
|
||||
[homing_override]
|
||||
[endstop_phase stepper_z]
|
||||
[gcode_macro my_cmd]
|
||||
[delayed_gcode my_delayed_gcode]
|
||||
[save_variables]
|
||||
[idle_timeout]
|
||||
[virtual_sdcard]
|
||||
[sdcard_loop]
|
||||
[force_move]
|
||||
[pause_resume]
|
||||
[firmware_retraction]
|
||||
[gcode_arcs]
|
||||
[respond]
|
||||
[exclude_object]
|
||||
[input_shaper]
|
||||
[adxl345]
|
||||
[lis2dw]
|
||||
[mpu9250 my_accelerometer]
|
||||
[resonance_tester]
|
||||
[board_pins my_aliases]
|
||||
[duplicate_pin_override]
|
||||
[probe]
|
||||
[bltouch]
|
||||
[smart_effector]
|
||||
[probe_eddy_current my_eddy_probe]
|
||||
[axis_twist_compensation]
|
||||
[stepper_z1]
|
||||
[extruder1]
|
||||
[dual_carriage]
|
||||
[extruder_stepper my_extra_stepper]
|
||||
[manual_stepper my_stepper]
|
||||
[verify_heater heater_config_name]
|
||||
[homing_heaters]
|
||||
[thermistor my_thermistor]
|
||||
[adc_temperature my_sensor]
|
||||
[heater_generic my_generic_heater]
|
||||
[temperature_sensor my_sensor]
|
||||
[temperature_probe my_probe]
|
||||
[fan]
|
||||
[heater_fan heatbreak_cooling_fan]
|
||||
[controller_fan my_controller_fan]
|
||||
[temperature_fan my_temp_fan]
|
||||
[fan_generic extruder_partfan]
|
||||
[led my_led]
|
||||
[neopixel my_neopixel]
|
||||
[dotstar my_dotstar]
|
||||
[pca9533 my_pca9533]
|
||||
[pca9632 my_pca9632]
|
||||
[servo my_servo]
|
||||
[gcode_button my_gcode_button]
|
||||
[output_pin my_pin]
|
||||
[pwm_tool my_tool]
|
||||
[pwm_cycle_time my_pin]
|
||||
[static_digital_output my_output_pins]
|
||||
[multi_pin my_multi_pin]
|
||||
[tmc2130 stepper_x]
|
||||
[tmc2208 stepper_x]
|
||||
[tmc2209 stepper_x]
|
||||
[tmc2660 stepper_x]
|
||||
[tmc2240 stepper_x]
|
||||
[tmc5160 stepper_x]
|
||||
[ad5206 my_digipot]
|
||||
[mcp4451 my_digipot]
|
||||
[mcp4728 my_dac]
|
||||
[mcp4018 my_digipot]
|
||||
[display]
|
||||
[display_data my_group_name my_data_name]
|
||||
[display_template my_template_name]
|
||||
[display_glyph my_display_glyph]
|
||||
[menu __some_list __some_name]
|
||||
[menu some_name]
|
||||
[menu some_list]
|
||||
[menu some_list some_command]
|
||||
[menu some_list some_input]
|
||||
[filament_switch_sensor my_sensor]
|
||||
[filament_motion_sensor my_sensor]
|
||||
[tsl1401cl_filament_width_sensor]
|
||||
[hall_filament_width_sensor]
|
||||
[load_cell]
|
||||
[sx1509 my_sx1509]
|
||||
[samd_sercom my_sercom]
|
||||
[adc_scaled my_name]
|
||||
[replicape]
|
||||
[palette2]
|
||||
[angle my_angle_sensor]
|
||||
@@ -0,0 +1,19 @@
|
||||
section: invalid
|
||||
not_a_valid_section
|
||||
[missing_square_bracket
|
||||
missing_square_bracket]
|
||||
[]
|
||||
[ ]
|
||||
[indented_section]
|
||||
[indented_section] # comment
|
||||
[indented_section] ; comment
|
||||
;[commented_section]
|
||||
#[another_commented_section]
|
||||
; [commented_section]
|
||||
# [another_commented_section]
|
||||
this_is_an_option: 123
|
||||
this_is_an_indented_option: 123
|
||||
this_is_an_option_block_start:
|
||||
|
||||
#
|
||||
;
|
||||
39
tests/line_matching/match_section/test_match_section.py
Normal file
39
tests/line_matching/match_section/test_match_section.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.joinpath("test_data")
|
||||
MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("matching_data.txt")
|
||||
NON_MATCHING_TEST_DATA_PATH = BASE_DIR.joinpath("non_matching_data.txt")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(MATCHING_TEST_DATA_PATH))
|
||||
def test_match_section(parser, line):
|
||||
"""Test that a line matches the definition of a section"""
|
||||
assert (
|
||||
parser._match_section(line) is True
|
||||
), f"Expected line '{line}' to match section definition!"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("line", load_testdata_from_file(NON_MATCHING_TEST_DATA_PATH))
|
||||
def test_non_matching_section(parser, line):
|
||||
"""Test that a line does not match the definition of a section"""
|
||||
assert (
|
||||
parser._match_section(line) is False
|
||||
), f"Expected line '{line}' to not match section definition!"
|
||||
0
tests/line_parsing/__init__.py
Normal file
0
tests/line_parsing/__init__.py
Normal file
62
tests/line_parsing/test_line_parsing.py
Normal file
62
tests/line_parsing/test_line_parsing.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.constants import HEADER_IDENT
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
parser = SimpleConfigParser()
|
||||
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def test_section_parsing(parser):
|
||||
expected_keys = {"section_1", "section_2", "section_3", "section_4"}
|
||||
assert expected_keys.issubset(
|
||||
parser.config.keys()
|
||||
), f"Expected keys: {expected_keys}, got: {parser.config.keys()}"
|
||||
assert parser.in_option_block is False
|
||||
assert parser.current_section == parser.get_sections()[-1]
|
||||
assert parser.config["section_2"]["_raw"] == "[section_2] ; comment"
|
||||
|
||||
|
||||
def test_option_parsing(parser):
|
||||
assert parser.config["section_1"]["option_1"]["value"] == "value_1"
|
||||
assert parser.config["section_1"]["option_1"]["_raw"] == "option_1: value_1"
|
||||
assert parser.config["section_3"]["option_3"]["value"] == "value_3"
|
||||
assert (
|
||||
parser.config["section_3"]["option_3"]["_raw"] == "option_3: value_3 # comment"
|
||||
)
|
||||
|
||||
|
||||
def test_header_parsing(parser):
|
||||
header = parser.config[HEADER_IDENT]
|
||||
assert isinstance(header, list)
|
||||
assert len(header) > 0
|
||||
|
||||
|
||||
def test_collector_parsing(parser):
|
||||
section = "section_2"
|
||||
section_content = list(parser.config[section].keys())
|
||||
coll_name = [name for name in section_content if name.startswith("#_")][0]
|
||||
collector = parser.config[section][coll_name]
|
||||
assert collector is not None
|
||||
assert isinstance(collector, list)
|
||||
assert len(collector) > 0
|
||||
assert "; comment" in collector
|
||||
0
tests/public_api/__init__.py
Normal file
0
tests/public_api/__init__.py
Normal file
26
tests/public_api/conftest.py
Normal file
26
tests/public_api/conftest.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg"]
|
||||
|
||||
|
||||
@pytest.fixture(params=CONFIG_FILES)
|
||||
def parser(request):
|
||||
parser = SimpleConfigParser()
|
||||
file_path = BASE_DIR.joinpath(request.param)
|
||||
for line in load_testdata_from_file(file_path):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
return parser
|
||||
174
tests/public_api/test_options_api.py
Normal file
174
tests/public_api/test_options_api.py
Normal file
@@ -0,0 +1,174 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
NoOptionError,
|
||||
NoSectionError,
|
||||
)
|
||||
|
||||
|
||||
def test_get_options(parser):
|
||||
expected_options = {
|
||||
"section_1": {"option_1"},
|
||||
"section_2": {"option_2"},
|
||||
"section_3": {"option_3"},
|
||||
"section_4": {"option_4"},
|
||||
"section number 5": {"option_5", "multi_option", "option_5_1"},
|
||||
}
|
||||
|
||||
for section, options in expected_options.items():
|
||||
assert options.issubset(
|
||||
parser.get_options(section)
|
||||
), f"Expected options: {options} in section: {section}, got: {parser.get_options(section)}"
|
||||
assert "_raw" not in parser.get_options(section)
|
||||
assert all(
|
||||
not option.startswith("#_") for option in parser.get_options(section)
|
||||
)
|
||||
|
||||
|
||||
def test_has_option(parser):
|
||||
assert parser.has_option("section_1", "option_1") is True
|
||||
assert parser.has_option("section_1", "option_128") is False
|
||||
# section does not exist:
|
||||
assert parser.has_option("section_128", "option_1") is False
|
||||
|
||||
|
||||
def test_getval(parser):
|
||||
# test regular option values
|
||||
assert parser.getval("section_1", "option_1") == "value_1"
|
||||
assert parser.getval("section_3", "option_3") == "value_3"
|
||||
assert parser.getval("section_4", "option_4") == "value_4"
|
||||
assert parser.getval("section number 5", "option_5") == "this.is.value-5"
|
||||
assert parser.getval("section number 5", "option_5_1") == "value_5_1"
|
||||
assert parser.getval("section_2", "option_2") == "value_2"
|
||||
|
||||
# test multiline option values
|
||||
ml_val = parser.getval("section number 5", "multi_option")
|
||||
assert isinstance(ml_val, list)
|
||||
assert len(ml_val) > 0
|
||||
|
||||
|
||||
def test_getval_fallback(parser):
|
||||
assert parser.getval("section_1", "option_128", "fallback") == "fallback"
|
||||
|
||||
|
||||
def test_getval_exceptions(parser):
|
||||
with pytest.raises(NoSectionError):
|
||||
parser.getval("section_128", "option_1")
|
||||
|
||||
with pytest.raises(NoOptionError):
|
||||
parser.getval("section_1", "option_128")
|
||||
|
||||
|
||||
def test_getint(parser):
|
||||
value = parser.getint("section_1", "option_1_2")
|
||||
assert isinstance(value, int)
|
||||
|
||||
|
||||
def test_getint_from_val(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getint_from_float(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1_3")
|
||||
|
||||
|
||||
def test_getint_from_boolean(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getint("section_1", "option_1_1")
|
||||
|
||||
|
||||
def test_getint_fallback(parser):
|
||||
assert parser.getint("section_1", "option_128", 128) == 128
|
||||
|
||||
|
||||
def test_getboolean(parser):
|
||||
value = parser.getboolean("section_1", "option_1_1")
|
||||
assert isinstance(value, bool)
|
||||
assert value is True or value is False
|
||||
|
||||
|
||||
def test_getboolean_from_val(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getboolean_from_int(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1_2")
|
||||
|
||||
|
||||
def test_getboolean_from_float(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getboolean("section_1", "option_1_3")
|
||||
|
||||
|
||||
def test_getboolean_fallback(parser):
|
||||
assert parser.getboolean("section_1", "option_128", True) is True
|
||||
assert parser.getboolean("section_1", "option_128", False) is False
|
||||
|
||||
|
||||
def test_getfloat(parser):
|
||||
value = parser.getfloat("section_1", "option_1_3")
|
||||
assert isinstance(value, float)
|
||||
|
||||
|
||||
def test_getfloat_from_val(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getfloat("section_1", "option_1")
|
||||
|
||||
|
||||
def test_getfloat_from_int(parser):
|
||||
value = parser.getfloat("section_1", "option_1_2")
|
||||
assert isinstance(value, float)
|
||||
|
||||
|
||||
def test_getfloat_from_boolean(parser):
|
||||
with pytest.raises(ValueError):
|
||||
parser.getfloat("section_1", "option_1_1")
|
||||
|
||||
|
||||
def test_getfloat_fallback(parser):
|
||||
assert parser.getfloat("section_1", "option_128", 1.234) == 1.234
|
||||
|
||||
|
||||
def test_set_existing_option(parser):
|
||||
parser.set_option("section_1", "new_option", "new_value")
|
||||
assert parser.getval("section_1", "new_option") == "new_value"
|
||||
assert parser.config["section_1"]["new_option"]["_raw"] == "new_option: new_value\n"
|
||||
|
||||
parser.set_option("section_1", "new_option", "new_value_2")
|
||||
assert parser.getval("section_1", "new_option") == "new_value_2"
|
||||
assert (
|
||||
parser.config["section_1"]["new_option"]["_raw"] == "new_option: new_value_2\n"
|
||||
)
|
||||
|
||||
|
||||
def test_set_new_option(parser):
|
||||
parser.set_option("new_section", "very_new_option", "very_new_value")
|
||||
assert (
|
||||
parser.has_section("new_section") is True
|
||||
), f"Expected 'new_section' in {parser.get_sections()}"
|
||||
assert parser.getval("new_section", "very_new_option") == "very_new_value"
|
||||
|
||||
parser.set_option("section_2", "array_option", ["value_1", "value_2", "value_3"])
|
||||
assert parser.getval("section_2", "array_option") == [
|
||||
"value_1",
|
||||
"value_2",
|
||||
"value_3",
|
||||
]
|
||||
assert parser.config["section_2"]["array_option"]["_raw"] == "array_option:\n"
|
||||
|
||||
|
||||
def test_remove_option(parser):
|
||||
parser.remove_option("section_1", "option_1")
|
||||
assert parser.has_option("section_1", "option_1") is False
|
||||
22
tests/public_api/test_read_file.py
Normal file
22
tests/public_api/test_read_file.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
|
||||
|
||||
def test_read_file():
|
||||
parser = SimpleConfigParser()
|
||||
parser.read_file(TEST_DATA_PATH)
|
||||
assert parser.config is not None
|
||||
assert parser.config.keys() is not None
|
||||
66
tests/public_api/test_sections_api.py
Normal file
66
tests/public_api/test_sections_api.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
DuplicateSectionError,
|
||||
)
|
||||
|
||||
|
||||
def test_get_sections(parser):
|
||||
expected_keys = {
|
||||
"section_1",
|
||||
"section_2",
|
||||
"section_3",
|
||||
"section_4",
|
||||
"section number 5",
|
||||
}
|
||||
assert expected_keys.issubset(
|
||||
parser.get_sections()
|
||||
), f"Expected keys: {expected_keys}, got: {parser.get_sections()}"
|
||||
|
||||
|
||||
def test_has_section(parser):
|
||||
assert parser.has_section("section_1") is True
|
||||
assert parser.has_section("not_available") is False
|
||||
|
||||
|
||||
def test_add_section(parser):
|
||||
pre_add_count = len(parser.get_sections())
|
||||
parser.add_section("new_section")
|
||||
parser.add_section("new_section2")
|
||||
assert parser.has_section("new_section") is True
|
||||
assert parser.has_section("new_section2") is True
|
||||
assert len(parser.get_sections()) == pre_add_count + 2
|
||||
|
||||
new_section = parser.config["new_section"]
|
||||
assert isinstance(new_section, dict)
|
||||
assert new_section["_raw"] == "[new_section]\n"
|
||||
|
||||
# this should be the collector, added by the parser before
|
||||
# then second section was added
|
||||
assert list(new_section.keys())[-1].startswith("#_")
|
||||
assert "\n" in new_section[list(new_section.keys())[-1]]
|
||||
|
||||
new_section2 = parser.config["new_section2"]
|
||||
assert isinstance(new_section2, dict)
|
||||
assert new_section2["_raw"] == "[new_section2]\n"
|
||||
|
||||
|
||||
def test_add_section_duplicate(parser):
|
||||
with pytest.raises(DuplicateSectionError):
|
||||
parser.add_section("section_1")
|
||||
|
||||
|
||||
def test_remove_section(parser):
|
||||
pre_remove_count = len(parser.get_sections())
|
||||
parser.remove_section("section_1")
|
||||
assert parser.has_section("section_1") is False
|
||||
assert len(parser.get_sections()) == pre_remove_count - 1
|
||||
assert "section_1" not in parser.config
|
||||
41
tests/public_api/test_write_file.py
Normal file
41
tests/public_api/test_write_file.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
# TEST_DATA_PATH_2 = BASE_DIR.joinpath("test_config_1_write.cfg")
|
||||
|
||||
|
||||
def test_write_file_exception():
|
||||
parser = SimpleConfigParser()
|
||||
with pytest.raises(ValueError):
|
||||
parser.write_file(None) # noqa
|
||||
|
||||
|
||||
def test_write_to_file(tmp_path):
|
||||
tmp_file = Path(tmp_path).joinpath("tmp_config.cfg")
|
||||
parser1 = SimpleConfigParser()
|
||||
parser1.read_file(TEST_DATA_PATH)
|
||||
# parser1.write_file(TEST_DATA_PATH_2)
|
||||
parser1.write_file(tmp_file)
|
||||
|
||||
parser2 = SimpleConfigParser()
|
||||
parser2.read_file(tmp_file)
|
||||
|
||||
assert tmp_file.exists()
|
||||
assert parser2.config is not None
|
||||
|
||||
with open(TEST_DATA_PATH, "r") as original, open(tmp_file, "r") as written:
|
||||
assert original.read() == written.read()
|
||||
15
tests/utils.py
Normal file
15
tests/utils.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def load_testdata_from_file(file_path: Path):
|
||||
"""Helper function to load test data from a text file"""
|
||||
|
||||
with open(file_path, "r") as f:
|
||||
return [line.replace("\n", "") for line in f]
|
||||
0
tests/value_conversion/__init__.py
Normal file
0
tests/value_conversion/__init__.py
Normal file
74
tests/value_conversion/test_get_conv.py
Normal file
74
tests/value_conversion/test_get_conv.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# ======================================================================= #
|
||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
||||
# #
|
||||
# https://github.com/dw-0/simple-config-parser #
|
||||
# #
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||
# ======================================================================= #
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
||||
from tests.utils import load_testdata_from_file
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def parser():
|
||||
parser = SimpleConfigParser()
|
||||
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||
parser._parse_line(line) # noqa
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def test_get_conv(parser):
|
||||
# Test conversion to int
|
||||
should_be_int = parser._get_conv("section_1", "option_1_2", int)
|
||||
assert isinstance(should_be_int, int)
|
||||
|
||||
# Test conversion to float
|
||||
should_be_float = parser._get_conv("section_1", "option_1_3", float)
|
||||
assert isinstance(should_be_float, float)
|
||||
|
||||
# Test conversion to boolean
|
||||
should_be_bool = parser._get_conv(
|
||||
"section_1", "option_1_1", parser._convert_to_boolean
|
||||
)
|
||||
assert isinstance(should_be_bool, bool)
|
||||
|
||||
# Test fallback for int
|
||||
should_be_fallback_int = parser._get_conv(
|
||||
"section_1", "option_128", int, fallback=128
|
||||
)
|
||||
assert isinstance(should_be_fallback_int, int)
|
||||
assert should_be_fallback_int == 128
|
||||
|
||||
# Test fallback for float
|
||||
should_be_fallback_float = parser._get_conv(
|
||||
"section_1", "option_128", float, fallback=1.234
|
||||
)
|
||||
assert isinstance(should_be_fallback_float, float)
|
||||
assert should_be_fallback_float == 1.234
|
||||
|
||||
# Test fallback for boolean
|
||||
should_be_fallback_bool = parser._get_conv(
|
||||
"section_1", "option_128", parser._convert_to_boolean, fallback=True
|
||||
)
|
||||
assert isinstance(should_be_fallback_bool, bool)
|
||||
assert should_be_fallback_bool is True
|
||||
|
||||
# Test ValueError exception for invalid int conversion
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", int)
|
||||
|
||||
# Test ValueError exception for invalid float conversion
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", float)
|
||||
|
||||
# Test ValueError exception for invalid boolean conversion
|
||||
with pytest.raises(ValueError):
|
||||
parser._get_conv("section_1", "option_1", parser._convert_to_boolean)
|
||||
Reference in New Issue
Block a user