Home Download Buy Blog Forum Support

ST3: ExportHtml

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 12:33 pm

skuroda wrote:great how export html was only discussed on say


def _find_file(abs_dir, file_name):
for root, dirnames, filenames in os.walk(abs_dir):
if file_name in filenames:
return os.path.join(root, file_name)


I think you can boil down the code to pretty much that, which will `return None` implicitly if nothing is found.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 12:38 pm

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

##################################### 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 #<em>re</em>loaded

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)

################################################################################
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 3:00 pm

castles_made_of_sand wrote:I think you can boil down the code to pretty much that, which will `return None` implicitly if nothing is found.


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...
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 3:12 pm

facelessuser wrote:I can't stand implicit Nones.


Fair enough :) Excuse the tasteless bike-shedding :oops:

I find it clearer in that particular case but to each their own
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 3:20 pm

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.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 3:27 pm

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.

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)
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 3:36 pm

castles_made_of_sand wrote:Fair enough :) Excuse the tasteless bike-shedding :oops:


bike-shedding, that was a new one for me; had to consult google :). 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 :).
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 3:51 pm

It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 4:23 pm

castles_made_of_sand wrote:https://github.com/sublimator/PackageResources/blob/master/package_resources.py

My shed got purple :)

Cool. I will give it a try.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 4:28 pm

Send us a pull request when you find bugs or add features eh ...

The globber aint finished btw ...
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Google [Bot] and 17 guests