Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v3.0.3 #776

Merged
merged 82 commits into from
Jul 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
5d727f8
Reenable develop
evhub May 30, 2023
bfb4029
Make multiset methods return multisets
evhub May 30, 2023
a79665f
Fix flaky test
evhub May 30, 2023
27f6ad0
Fix py2
evhub May 30, 2023
ebb44f5
Enable --line-numbers by default
evhub Jun 3, 2023
20c9157
Fix coconut-run
evhub Jun 3, 2023
dbbc383
Try to fix test flakiness
evhub Jun 3, 2023
4feb0b6
Fix py36
evhub Jun 4, 2023
a08e8e7
Add and_then and and_then_await
evhub Jun 9, 2023
4966db9
Add subscript 10 unicode alt
evhub Jun 9, 2023
1cf5574
Fix py2 errors
evhub Jun 10, 2023
8de84d5
Further fix py2
evhub Jun 11, 2023
8f31d25
Disable implicit call syntax in xonsh
evhub Jun 11, 2023
375d8fd
Improve handling of missing modules
evhub Jun 12, 2023
7871542
Fix constant overhead for functions
evhub Jun 13, 2023
7439f3e
Reduce appveyor testing
evhub Jun 14, 2023
db2dc7f
Add fat lambda support
evhub Jun 14, 2023
dc44521
Support 3.12 f str syntax
evhub Jun 20, 2023
00a4afc
Add testing for deprecated versions
evhub Jun 20, 2023
86ee301
Fix broken tests
evhub Jun 20, 2023
f148091
Remove broken tests
evhub Jun 20, 2023
d0baeb3
Fix py34
evhub Jun 20, 2023
518b57e
Update setup-python
evhub Jun 20, 2023
bd63677
Further fix py34
evhub Jun 21, 2023
6ade946
Merge branch 'develop' of https://github.com/evhub/coconut into develop
evhub Jun 21, 2023
2aceb21
Fix passthrough
evhub Jun 21, 2023
1e1f0e4
Fix low py3 vers
evhub Jun 21, 2023
28036f1
Fix py2
evhub Jun 21, 2023
6eb1c77
Fix py34
evhub Jun 22, 2023
185f001
Fix py2
evhub Jun 22, 2023
54cdffa
Fix import testing
evhub Jun 22, 2023
17735e1
Add incremental parsing support
evhub Jul 5, 2023
5eaaf4c
Improve jupyter installation, fix incremental parsing
evhub Jul 6, 2023
6ee0d04
Use incremental mode for integrations
evhub Jul 6, 2023
740b928
Improve incremental parsing usage
evhub Jul 6, 2023
66c8ad3
Use newest cPyparsing
evhub Jul 7, 2023
5ea526b
Fix jupyter, improve watching
evhub Jul 8, 2023
7c2b724
Fix ipython extension
evhub Jul 8, 2023
63403b0
Add psf target
evhub Jul 8, 2023
f84276d
Fix tests
evhub Jul 9, 2023
c891114
Fix imports test
evhub Jul 9, 2023
bac9488
Use --no-wrap-types in auto comp
evhub Jul 12, 2023
a74fb8a
Better document coconut-run
evhub Jul 15, 2023
a858e55
fix: the target name has been changed in fe648bd9
kxmh42 Jul 15, 2023
a71efdd
Merge branch 'develop' into fix/test-basic-to-test-univ-target
evhub Jul 15, 2023
4369325
Fix make target in the docs: test-basic -> test-univ (#770)
evhub Jul 15, 2023
5eed433
Allow setting auto comp args
evhub Jul 16, 2023
35efe56
Automatically set auto comp args
evhub Jul 16, 2023
cfd7709
Improve import hook testing
evhub Jul 16, 2023
162dd82
Improve auto comp
evhub Jul 16, 2023
5831223
Add comments
evhub Jul 16, 2023
f77ea72
Use cache_dir for coconut-run and auto comp
evhub Jul 16, 2023
a44b424
Fix command
evhub Jul 16, 2023
928755d
Clarify docs
evhub Jul 16, 2023
4b143e3
Add 3.13 support
evhub Jul 16, 2023
9c99cb9
Improve api, integrations
evhub Jul 16, 2023
65c470f
Fix lots of bugs
evhub Jul 16, 2023
325cd85
Fix more bugs
evhub Jul 16, 2023
0851ecf
Document fat lambdas
evhub Jul 16, 2023
234eb2f
Improve docs, types
evhub Jul 18, 2023
b851ed0
Bump reqs with cpyparsing
evhub Jul 18, 2023
ecbaf82
Fix warnings
evhub Jul 19, 2023
4adb6b4
Fix pypy error
evhub Jul 20, 2023
1d2da9a
Improve wrapping
evhub Jul 20, 2023
773be62
Improve docs
evhub Jul 20, 2023
b7d8588
Check for f-strings w/o exprs
evhub Jul 21, 2023
13fed05
Overhaul exception formatting
evhub Jul 21, 2023
1367992
Further improve exceptions
evhub Jul 21, 2023
590e28f
Fix exception test
evhub Jul 21, 2023
d70886b
Overhaul exc formatting again
evhub Jul 22, 2023
46610fb
Upgrade to new cPyparsing
evhub Jul 25, 2023
aa21691
Upgrade to newer cPyparsing
evhub Jul 25, 2023
847629a
Fix imports, exceptions
evhub Jul 26, 2023
7f13c92
Fix mypy stub installation
evhub Jul 27, 2023
e583890
Fix tests
evhub Jul 27, 2023
3012657
Further fix tests
evhub Jul 27, 2023
6927048
Fix semicolons in xonsh
evhub Jul 28, 2023
9a465eb
Clean up code
evhub Jul 28, 2023
5b82a18
Attempt to fix test setup
evhub Jul 28, 2023
1ffca4a
Add docstrings to stubs
evhub Jul 29, 2023
ea5a899
Fix appveyor
evhub Jul 29, 2023
6b6c174
Prepare for v3.0.3 release
evhub Jul 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up code
evhub committed Jul 28, 2023
commit 9a465ebf53c9af2e5c809d2ff59e762be3363e3b
20 changes: 10 additions & 10 deletions coconut/command/command.py
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ class Command(object):
exit_code = 0 # exit status to return
errmsg = None # error message to display

show = False # corresponds to --display flag
display = False # corresponds to --display flag
jobs = 0 # corresponds to --jobs flag
mypy_args = None # corresponds to --mypy flag
argv_args = None # corresponds to --argv flag
@@ -274,14 +274,16 @@ def execute_args(self, args, interact=True, original_args=None):
self.set_jobs(args.jobs, args.profile)
if args.recursion_limit is not None:
set_recursion_limit(args.recursion_limit)
if args.display:
self.show = True
self.display = args.display
self.prompt.vi_mode = args.vi_mode
if args.style is not None:
self.prompt.set_style(args.style)
if args.history_file is not None:
self.prompt.set_history_file(args.history_file)
if args.vi_mode:
self.prompt.vi_mode = True
if args.argv is not None:
self.argv_args = list(args.argv)

# execute non-compilation tasks
if args.docs:
launch_documentation()
if args.tutorial:
@@ -290,8 +292,6 @@ def execute_args(self, args, interact=True, original_args=None):
self.site_uninstall()
if args.site_install:
self.site_install()
if args.argv is not None:
self.argv_args = list(args.argv)

# process general compiler args
if args.line_numbers:
@@ -576,7 +576,7 @@ def compile(self, codepath, destpath=None, package=False, run=False, force=False
if foundhash:
if show_unchanged:
logger.show_tabulated("Left unchanged", showpath(destpath), "(pass --force to overwrite).")
if self.show:
if self.display:
logger.print(foundhash)
if run:
self.execute_file(destpath, argv_source_path=codepath)
@@ -591,7 +591,7 @@ def callback(compiled):
with univ_open(destpath, "w") as opened:
writefile(opened, compiled)
logger.show_tabulated("Compiled to", showpath(destpath), ".")
if self.show:
if self.display:
logger.print(compiled)
if run:
if destpath is None:
@@ -804,7 +804,7 @@ def execute(self, compiled=None, path=None, use_eval=False, allow_show=True):
self.check_runner()
if compiled is not None:

if allow_show and self.show:
if allow_show and self.display:
logger.print(compiled)

if path is None: # header is not included
123 changes: 71 additions & 52 deletions coconut/compiler/util.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
# Table of Contents:
# - Imports
# - Computation Graph
# - Parsing Introspection
# - Targets
# - Parse Elements
# - Utilities
@@ -400,17 +401,6 @@ def force_reset_packrat_cache():
ParserElement.enablePackrat(packrat_cache_size)


def enable_incremental_parsing(force=False):
"""Enable incremental parsing mode where prefix parses are reused."""
if SUPPORTS_INCREMENTAL or force:
try:
ParserElement.enableIncremental(incremental_cache_size, still_reset_cache=False)
except ImportError as err:
raise CoconutException(str(err))
else:
logger.log("Incremental parsing mode enabled.")


@contextmanager
def parsing_context(inner_parse=True):
"""Context to manage the packrat cache across parse calls."""
@@ -504,9 +494,78 @@ def transform(grammar, text, inner=True):


# -----------------------------------------------------------------------------------------------------------------------
# TARGETS:
# PARSING INTROSPECTION:
# -----------------------------------------------------------------------------------------------------------------------


def get_func_closure(func):
"""Get variables in func's closure."""
if PY2:
varnames = func.func_code.co_freevars
cells = func.func_closure
else:
varnames = func.__code__.co_freevars
cells = func.__closure__
return {v: c.cell_contents for v, c in zip(varnames, cells)}


def get_pyparsing_cache():
"""Extract the underlying pyparsing packrat cache."""
packrat_cache = ParserElement.packrat_cache
if isinstance(packrat_cache, dict): # if enablePackrat is never called
return packrat_cache
elif hasattr(packrat_cache, "cache"): # cPyparsing adds this
return packrat_cache.cache
else: # on pyparsing we have to do this
try:
# this is sketchy, so errors should only be complained
return get_func_closure(packrat_cache.get.__func__)["cache"]
except Exception as err:
complain(err)
return {}


def add_to_cache(new_cache_items):
"""Add the given items directly to the pyparsing packrat cache."""
packrat_cache = ParserElement.packrat_cache
for lookup, value in new_cache_items:
packrat_cache.set(lookup, value)


def get_cache_items_for(original):
"""Get items from the pyparsing cache filtered to only from parsing original."""
cache = get_pyparsing_cache()
for lookup, value in cache.items():
got_orig = lookup[1]
if got_orig == original:
yield lookup, value


def get_highest_parse_loc(original):
"""Get the highest observed parse location."""
# find the highest observed parse location
highest_loc = 0
for item, _ in get_cache_items_for(original):
loc = item[2]
if loc > highest_loc:
highest_loc = loc
return highest_loc


def enable_incremental_parsing(force=False):
"""Enable incremental parsing mode where prefix parses are reused."""
if SUPPORTS_INCREMENTAL or force:
try:
ParserElement.enableIncremental(incremental_cache_size, still_reset_cache=False)
except ImportError as err:
raise CoconutException(str(err))
else:
logger.log("Incremental parsing mode enabled.")


# -----------------------------------------------------------------------------------------------------------------------
# TARGETS:
# -----------------------------------------------------------------------------------------------------------------------
on_new_python = False

raw_sys_target = str(sys.version_info[0]) + str(sys.version_info[1])
@@ -1300,46 +1359,6 @@ def handle_indentation(inputstr, add_newline=False, extra_indent=0):
return out


def get_func_closure(func):
"""Get variables in func's closure."""
if PY2:
varnames = func.func_code.co_freevars
cells = func.func_closure
else:
varnames = func.__code__.co_freevars
cells = func.__closure__
return {v: c.cell_contents for v, c in zip(varnames, cells)}


def get_highest_parse_loc(original):
"""Get the highest observed parse location."""
try:
# extract the actual cache object (pyparsing does not make this easy)
packrat_cache = ParserElement.packrat_cache
if isinstance(packrat_cache, dict): # if enablePackrat is never called
cache = packrat_cache
elif hasattr(packrat_cache, "cache"): # cPyparsing adds this
cache = packrat_cache.cache
else: # on pyparsing we have to do this
cache = get_func_closure(packrat_cache.get.__func__)["cache"]

# find the highest observed parse location
highest_loc = 0
for item in cache:
item_orig = item[1]
# this check is always necessary as sometimes we're currently looking at an old cache
if item_orig == original:
loc = item[2]
if loc > highest_loc:
highest_loc = loc
return highest_loc

# everything here is sketchy, so errors should only be complained
except Exception as err:
complain(err)
return 0


def literal_eval(py_code):
"""Version of ast.literal_eval that attempts to be version-independent."""
try:
2 changes: 2 additions & 0 deletions coconut/tests/main_test.py
Original file line number Diff line number Diff line change
@@ -801,6 +801,8 @@ def test_xontrib(self):
p.expect("$")
p.sendline("!(ls -la) |> bool")
p.expect("True")
p.sendline("'1; 2' |> print")
p.expect("1; 2")
p.sendline('$ENV_VAR = "ABC"')
p.expect("$")
p.sendline('echo f"{$ENV_VAR}"; echo f"{$ENV_VAR}"')