Comments (9)
Dear @echoix, when reporting a bug, please remove the unused parts of the bug report template, otherwise the important stuff gets lost in the template noise.
from grass.
no worries, all good! You're doing an amazing job fixing a lot of things here and there! 🚀 It's just my ocd 🤦♀️
from grass.
We need a new or better pattern for grass.script.core.parser usage in modules.
Currently, something like this is suggested
if __name__ == "__main__":
options, flags = grass.parser()
main()
Lets take one of the newly-failing modules, that would need to pass a Pylint version >2.12 to upgrade the pytest-pylint plugin version, t.vect.observe.strds
When the module is called, grass.script.core.parser is called before main, and sets options
and flags
in the global scope, then calls main
.
grass/temporal/t.vect.observe.strds/t.vect.observe.strds.py
Lines 363 to 365 in 5b2460a
Then in main
, these options
and flags
variables are used
grass/temporal/t.vect.observe.strds/t.vect.observe.strds.py
Lines 83 to 93 in 5b2460a
The problem is that options
and flags
aren't really defined before use, except if main is called ONLY when the script is ran as a file. The file can't be imported and call the function.
Some possibilities to fix this:
- Declare global variables in all the files to hold this (I don't suggest this)
- Add
options
andflags
as arguments to themain
functions of the modules, and callmain(options, flags)
- Add options and flags keys used as arguments, along with
*args, **kwargs
and callmain(**options, **flags)
on all the modules.
In the middle, there's the possibility of making some things optional or doing a check if something global exists, but having a function explicitly naming its requirements is a good thing, and it allows to test it way better.
I also suggest starting using types annotations, and the
_parse_opts
grass/python/grass/script/core.py
Line 822 in 5b2460a
Used by
grass/python/grass/script/core.py
Line 854 in 5b2460a
Is a good candidate, as we know for sure that it returns a tuple of two dicts (mappings), one is a mapping of string to string (for options), and the second one (flags) is a mapping of string to bool. After that tools and IDEs can start helping out, since then calling parser has the types known, and then the return variables have type info, that can be used for the modules, etc...
What are the thoughts of Python knowledgable members? @wenzeslaus maybe?
from grass.
Other warnings I see are ones that would have been fixed with a newer black 23 version, but Friday black 24.1.0 with a new style was published, and last night/ this morning black 24.1.1 was released with a fix for long path names of their cache paths for systems (like Windows) which doesn't have long path names enabled by default.
Something like where previously the string was split into two lines, then later on it fit on a single line, but the two double quotes joining them together are still there.
So I'm fixing both at the same time.
from grass.
I also saw that the g.parser docs have a Python example, saying it was Python 3, but it is clearly Python 2 syntax, since it uses print as a language keyword instead of a function
from grass.
I understand, I cleaned now. I know how to fill out complete bug reports, but that was only a really quick note to flag a just broken pipeline, and acknowledge it. I was afterwards working urgently on patching it, and I didn't finish the real fix as of yesterday night.
from grass.
Part of the solution for this and #3205 that I was working on is to bump Pylint, pytest, and pytest-pylint versions, and my nearly month-old quick PR #3331 is kind of becoming a requirement, since there are newer rules that doesn't make sense to ignore them when the fixes are available. I'm sure there will be more found later but I just hope it won't take another month when they are ready to solve
from grass.
We have been trying to use this, but it hasn't become part of documentation yet:
def main():
options, flags = gs.parser()
...
if __name__ == "__main__":
main()
from grass.
Still open, since version pinning isn't solving the problem itself
from grass.
Related Issues (20)
- [Bug] CI on main failing due to dependencies HOT 4
- Grass GIS version 8.3.2.1 problem HOT 8
- [Bug] CI: Bandit: 1 configuration not found (python-code-quality.yml) HOT 3
- [Bug] PATH setting discrepancy between the main exectable and Python API for scripts on Windows
- [Bug] wxGUI: Nonsense commands end in Success in gconsole OnCmdDone method
- [Bug] Windows CI builds fail to compile r.flow HOT 6
- Renovate naming convention issue HOT 2
- Raster layers cannot be displayed[Bug] HOT 1
- [Bug] wxGUI/history: update cross to green check after updating to current region
- Tests are failing in CI with an ISO format error HOT 6
- r.recode results in integer when floating numbers are expected [Bug] HOT 6
- [Bug] Windows GUI can't launch for 8.4.0dev (nightly) HOT 7
- [Build] Exclude specific module (r.geomorphon) at compilation HOT 17
- [Feat] temporal: revert #3723 (fix for SQLite version < 3.33)
- [Bug] [Windows] Crash of the GRASS-GIS 8.3 `v.surf.rst.exe` (OSGeo4W) and Windows module `ntdll.dll` HOT 14
- [Bug] Windows 8.4.0dev cannot launch GUI with error in `gui\wxpython\lmgr\statusbar.py` HOT 12
- [Bug] Windows OSGeo4W builds seem to report outdated build info HOT 2
- import nc file in grass gis HOT 2
- [Feat] library: Add Standard parser options for date and time HOT 1
- [Feat] i.group: print image group content with semantic_labels in JSON HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grass.