Sublime Forum

ST3: ExportHtml

#62

re: testing out the function, you can set up test suites which run only on reload as so:

[pre=#0C1021]##################################### TESTS ####################################

import unittest

class GetPackageAssetTests(unittest.TestCase):
def test_get_package_and_asset_name(self):
tc = get_package_and_asset_name
aseq = self.assertEquals

    r1 = (tc("Packages/Relative/one.py"))
    r2 = (tc("/Abs/Packages/ZipPseudo.sublime-package/nested/sort.py"))
    r3 = (tc(sublime.packages_path() + "/Absolute/Nested/asset.pth"))

    aseq(r1, ('Relative',   'one.py'))
    aseq(r2, ('ZipPseudo',  'nested/sort.py'))
    aseq(r3, ('Absolute',   'Nested/asset.pth'))

################ ONLY LOAD TESTS WHEN DEVELOPING NOT ON START UP ###############

try: times_module_has_been_reloaded += 1
except NameError: times_module_has_been_reloaded = 0 #reloaded

if times_module_has_been_reloaded:
target = name
suite = unittest.TestLoader().loadTestsFromName(target)

unittest.TextTestRunner(stream = sys.stdout,  verbosity=0).run(suite)

print ("running tests", target)
print ('\nReloads: %s' % times_module_has_been_reloaded)

################################################################################
[/pre]

0 Likes

#63

[quote=ā€œcastles_made_of_sandā€]
I think you can boil down the code to pretty much that, which will return None implicitly if nothing is found.[/quote]

Nothing wrong with simplifyingā€¦but I canā€™t stand implicit Nones. It makes it so clear that that is actually the intent to actually return a None for clarity sake. I know this is stylistic and allā€¦just sayingā€¦

0 Likes

#64

Fair enough :smile: Excuse the tasteless bike-shedding :blush:

I find it clearer in that particular case but to each their own

0 Likes

#65

This bike-shedding proven pretty constructive for me anyway, noticed some bugs in the gist code, and the edit preferences code.

Iā€™m going to merge ideas/insights from both of them and slap some unit tests on em at some point.

0 Likes

#66

There seems to be a bug with path return. If path was not recursive, you would return the path as a boolean. I have fixed it below.

[pre=#2D2D2D]def get_package_asset(package_name, file_name, get_path=False, recursive_search=False):
packages_path = sublime.packages_path()
sublime_package = package_name + ā€œ.sublime-packageā€
path = None

if os.path.exists(os.path.join(packages_path, package_name)):
    if recursive_search:
        path = _find_file(os.path.join(packages_path, package_name), file_name)
    elif os.path.exists(os.path.join(packages_path, package_name, file_name)):
        path = os.path.join(packages_path, package_name, file_name)[/pre]
0 Likes

#67

bike-shedding, that was a new one for me; had to consult google :smile:. Yeah, I try not to get too invested in my stylistic opinions. Usually, I throw it out there and if people ignore it, I shrug it off. I realize my opinion doesnā€™t govern the world :smile:.

0 Likes

#68

github.com/sublimator/PackageRe ā€¦ sources.py

My shed got purple :smile:

0 Likes

#69

[quote=ā€œcastles_made_of_sandā€]https://github.com/sublimator/PackageResources/blob/master/package_resources.py

My shed got purple :smile:[/quote]

Cool. I will give it a try.

0 Likes

#70

Send us a pull request when you find bugs or add features eh ā€¦

The globber aint finished btw ā€¦

0 Likes

#71

[quote=ā€œfacelessuserā€]I do do a number of score selectors, but not as many as you would think.

I grab the scope name from the selection and then compare all of the theme scopes with score_selector. Once I determine the best matches, I add the scope name with the best theme scope matches for foreground, background, etc. to the dictionary and never have to run score_selector on the same scope again.

I donā€™t notice much of a difference with the ST2 version and the ST3 version for this plugin.[/quote]

Thatā€™s a clever use of memoization :smiley:

0 Likes

#72

[quote=ā€œfacelessuserā€]There seems to be a bug with path return. If path was not recursive, you would return the path as a boolean. I have fixed it below.
[/quote]

Woops, that was bad. :blush:

Is it possible to have assets outside of one of the sublime text paths (as specified in the following test)

r2 = (tc("/Abs/Packages/ZipPseudo.sublime-package/nested/sort.py"))

Made a couple updates. Used walkā€™s recursion rather than my own. get_package_and_asset_name should now

0 Likes

#73

Think Iā€™ve taken everything that has been mentioned. get_package_asset now defaults to returning files UTF-8 encoded. In addition, there are two new parameters, a boolean to return the data in itā€™s binary form (default false) and a string for encoding type (default utf-8).

0 Likes

#74

[quote=ā€œskurodaā€]
Is it possible to have assets outside of one of the sublime text paths (as specified in the following test)

CODE: SELECT ALL
r2 = (tc("/Abs/Packages/ZipPseudo.sublime-package/nested/sort.py"))[/quote]

I donā€™t think so, not meaningfully anyway. If your routine relies on removing the install path prefixes just kill the test case.

In contrast to a path like Packages/Yes/no.yes

Abs there was just symbolic of an absolute path to the executable folder or installed_packages_path()

0 Likes

#75

**ā€œDeā€**coded

gist.github.com/skuroda/4965913 ā€¦ set-py-L62
Not sure if you wanted this to work on ST2 as well as ST3, but afaik, the open builtin on python2 doesnā€™t take an encoding kwarg.

I think codecs.open, on the other hand, works :smile:

encoding String representing the encoding to use when reading. Only takes affect when return_binary is True (default utf-8).
I think that was meant to be when return binary is False

0 Likes

#76

Okay fine UTF-8 decoded by default. :smile: Yup definitely should be False. Hmm I should fix that, no reason this shouldnā€™t work for ST2 and 3. I guess if I was thinking beforehand I would have written something like this earlier. I should take a closer look at your PackageResources stuff. Itā€™s probably a lot better than mine. Though if I only wrote code where it was better than everyone elseā€™s, well I wouldnā€™t be writing very much. And thatā€™s no fun. Thanks for all the feedback.

0 Likes

#77

I stole some of your ideas :smile:

Thereā€™s some other functionality in there (that I eventually want to finish ā€¦ one of these days ) re: globbing

Was doing flat globbing until you made me realize that settings / keymaps could be nested.

re: package assets:

Turn on sublime.log_commands(True) and run the menu item Preferences -> Default keybindings

Take note of the command and args.

You can use that ${packages}/Path/to.file form to open package assets, be they zipped or not. If they zipped they are open in read only mode.

Dunno if thatā€™s interesting to you for anything but I think itā€™s kinda neat.

0 Likes

#78

Everybodyā€™s stuff seems to work great for what I am doing. I didnā€™t really have to do anythingā€¦I could get used to this :smile:. I will probably roll out a new ExportHtml rev tomorrow. Got too much stuff tonight going on.

0 Likes

#79

[quote=ā€œcastles_made_of_sandā€]
Turn on sublime.log_commands(True) and run the menu item Preferences -> Default keybindings

Take note of the command and args.

You can use that ${packages}/Path/to.file form to open package assets, be they zipped or not. If they zipped they are open in read only mode.

Dunno if thatā€™s interesting to you for anything but I think itā€™s kinda neat.[/quote]

That is interesting. I have to say, Iā€™m glad ST3 was updated to make those files read only if they were read from sublime-packages.

Haha. Donā€™t tell me you want to try to do something like this person did (link)

0 Likes

#80

[quote=ā€œskurodaā€]
Haha. Donā€™t tell me you want to try to do something like this person did (link)[/quote]

That sounds awesomeā€¦if only I could get away with itā€¦ :smile:.

0 Likes

#81

New version published with the ability to find color schemes in zip files. Thanks everyone for your contributions.

0 Likes