Code Monkey home page Code Monkey logo

qtsass's People

Contributors

andvgal avatar cam-gerlach avatar ccordoba12 avatar dalthviz avatar danbradham avatar ewerybody avatar gentlegiantjgc avatar goanpeca avatar matsjoyce avatar musicinmybrain avatar regrainb avatar s-weigand avatar yann-lty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qtsass's Issues

Failure in the test suite

From https://bugs.debian.org/1009456:

============================= test session starts ==============================
platform linux -- Python 3.10.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /<>
collected 37 items

tests/test_api.py ......... [ 24%]
tests/test_cli.py ....... [ 43%]
tests/test_conformers.py ............ [ 75%]
tests/test_functions.py ..... [ 89%]
tests/test_watchers.py .Fs. [100%]

=================================== FAILURES ===================================
___________________________ test_watchers[QtWatcher] ___________________________

Watcher = <class 'qtsass.watchers.qt.QtWatcher'>
tmpdir = local('/tmp/pytest-of-user42/pytest-8/test_watchers_QtWatcher_0')

@pytest.mark.parametrize(
    'Watcher', (PollingWatcher, QtWatcher),
)
def test_watchers(Watcher, tmpdir):
    """Stress test Watcher implementations"""

    # Skip when QtWatcher is None - when Qt is not installed.
    if not Watcher:
        return

    watch_dir = tmpdir.join('src').strpath
    os.makedirs(watch_dir)
    shutil.copy2(example('dummy.scss'), watch_dir)
    input = tmpdir.join('src/dummy.scss').strpath
    output = tmpdir.join('build/dummy.css').strpath
    output_exists = lambda: exists(output)

    c = CallCounter()
    w = Watcher(
        watch_dir=watch_dir,
        compiler=compile_filename,
        args=(input, output),
    )
    w.connect(c)

    # Output should not yet exist
    assert not exists(output)

    w.start()

    touch(input)
    time.sleep(0.5)
    if not await_condition(output_exists):
        assert False, 'Output file not created...'

    # Removing the watch_dir should not kill the Watcher
    # simply stop dispatching callbacks
    shutil.rmtree(watch_dir)
    time.sleep(0.5)
    assert c.count == 1

    # Watcher should recover once the input file is there again
    os.makedirs(watch_dir)
    shutil.copy2(example('dummy.scss'), watch_dir)
    time.sleep(0.5)
  assert c.count == 2

E assert 1 == 2
E + where 1 = <tests.test_watchers.CallCounter object at 0x7f08d54935e0>.count

tests/test_watchers.py:87: AssertionError
=========================== short test summary info ============================
FAILED tests/test_watchers.py::test_watchers[QtWatcher] - assert 1 == 2
=================== 1 failed, 35 passed, 1 skipped in 11.59s ===================

Travis CI build is failing

The latest version of pytest-cov only supports pytest >= 3.6.

Update pip install in travis config to use --upgrade. This should force the latest version of pytest to be installed alongside pytest-cov.

Unsupported qradialgradient

qradialgradient is not supported. Example of typical usage:

QRadioButton::indicator:checked
{
	background-color: qradialgradient(
		cx: 0.5, cy: 0.5,
		fx: 0.5, fy: 0.5,
		radius: 1.0,
		stop: 0.25 #78879b,
		stop: 0.3 #302F2F
	);
}

setuptools/distutils integration

The python libsass library has really sweet integration with setuptools/distutils.

setup(
...
    sass_manifests={
       'package': ('/scss', '/css')
    },
)

We should be able to subclass the distutils command and hook up our own compile method.

install latest version

Hello, I am trying to install the latest version of qtsass.
When I do pip install qtsass it seems I am getting a very old version. What do I do to install the version you have tested in master?

Drop support for Python 2.7, 3.5, and 3.6

Seems like libssas-python dropped support for Python 2.7 sass/libsass-python@d333e3c (there is no release with that change for the moment but still I guess the latest release that supports Python 2.7 will be the current one 0.21.0).

Taking the opportunity, maybe removing support for others already out of date Python versions like 3.5 and 3.6 could be worty.

Also, should we release QtSASS v0.3.2 adding a constraint to libsass<=0.21.0 before proceeding with dropping the support for Python <=3.6 @ccordoba12 ?

Align api behavior with libsass?

Looking over the python libsass api, I realized that the qtsass api is not aligned. Libsass has a single compile method that performs different operations based on which mode argument is provided.

compile(string='#sass string', **kwargs) - compiles a source string
compile(filename='file.scss', **kwargs) - compiles a source file, delegates to compile_filename()
compile(dirname='./dir', **kwargs) - recursively compiles source files, delegates to compile_dirname()

PR #23 renames compile_and_save to compile_filename, and adds the compile_dirname api method. So qtsass will now have api names that align with libsass. The question is, how closely should we align the qtsass api behavior with libsass? I can imagine two options:

  1. Match behavior fully
    • compile is the only public api method
    • compile delegates to compile_filename and compile_dirname based on arguments
  2. Be more explicit
    • compile should ONLY compile a source string
    • compile, compile_filename, and compile_dirname are all public methods

I think I prefer option 2.

In addition to the above, our api should allow users to pass the full breadth of keyword arguments to the underlying libsass.compile calls. Here's the documentation for libsass.compile.

What do you think? @goanpeca

Improve logging configuration

Currently qtsass is using basicConfig to configure the root logger. This is generally okay when qtsass is used only from the CLI. When used as a library this is problematic, and can propagate to other library's loggers. We should use logging best practices for a library:

# Add a null handler
import logging
logging.getLogger('qtsass').addHandler(logging.NullHandler())

We can add an enable_logging function to the api that accepts an optional logging level.

def enable_logging(level=None):
    if level is None:
        level = os.environ.get('QTSASS_DEBUG', logging.WARNING)
    logger = logging.getLogger('qtsass')
    logger.setLevel(level)

A --debug flag can be added to the cli to allow users to enable debug logging on the cli.

With that users would have the following options to configure logging:

  1. Set the QTSASS_DEBUG environment variable
  2. Use the --debug cli flag
  3. Call qtsass.enable_logging(logging.DEBUG)
  4. Add custom logging handlers to the qtsass logger

Labels in QLinearGradient value

I know to use a QLinearGradient, I need to use the special syntax.
This is compiling like explained in the readme.
But when I start my Qt Application this style is not working.
When I'm adding the labels (x1, y1, ...) manually in the qss file, it works as expected in the application.

Is there a possibility to add these labels automatically in the code?

Color mapping not supported

In the current version, simple color mapping in an scss file is not supported.

Example:

$shadow-black:              rgba(black, 0.3);
$dark-on-20:    #bcc2cc;
background-hover-primary:      rgba($dark-on-20, 0.10),

Error message for black mapping:

ERROR:qtsass.api:Failed to compile source code
Traceback (most recent call last):
  File "...\Anaconda3\Scripts\qtsass-script.py", line 9, in <module>
    sys.exit(main())
  File "...\Anaconda3\lib\site-packages\qtsass\cli.py", line 72, in main
    compile_filename(args.input, args.output)
  File "...\Anaconda3\lib\site-packages\qtsass\api.py", line 120, in compile_filename
    css = compile(string, **kwargs)
  File "...\Anaconda3\lib\site-packages\qtsass\api.py", line 94, in compile
    return qt_conform(sass.compile(**kwargs))
  File "...\Anaconda3\lib\site-packages\sass.py", line 738, in compile
    raise CompileError(v)
sass.CompileError: Error: Function rgba is missing argument $b.
        on line 46 of stdin
>> $shadow-black-secondary:    rgba(black, 0.7);

Error message for color variable mapping:

ERROR:qtsass.api:Failed to compile source code
Traceback (most recent call last):
  File "...\Anaconda3\Scripts\qtsass-script.py", line 9, in <module>
    sys.exit(main())
  File "...\Anaconda3\lib\site-packages\qtsass\cli.py", line 72, in main
    compile_filename(args.input, args.output)
  File "...\Anaconda3\lib\site-packages\qtsass\api.py", line 120, in compile_filename
    css = compile(string, **kwargs)
  File "...\Anaconda3\lib\site-packages\qtsass\api.py", line 94, in compile
    return qt_conform(sass.compile(**kwargs))
  File "...\Anaconda3\lib\site-packages\sass.py", line 738, in compile
    raise CompileError(v)
sass.CompileError: Error: Function rgba is missing argument $b.
        on line 162 of stdin
>> background-hover-primary:   rgba($dark-on-20, 0.10),

   ----------------------------^

The code currently only supports the 4argument color input here:

class SassColor(collections.namedtuple('SassColor', ('r', 'g', 'b', 'a'))):

    def __new__(cls, r, g, b, a):
        r = float(r)
        g = float(g)
        b = float(b)
        a = float(a)
        return super(SassColor, cls).__new__(cls, r, g, b, a)

qlineargradient x1,y1,x2,y2 values can be floats!

Turns out its actually not a problem to put float values into the x1,y1,x2,y2 coordinate values of a qlineargradient liek:

s = 'background: qlineargradient(x2: 0.0, y2:2.0, stop:0 rgb(80,20,20), stop:1 rgb(75,175,75));'
x.btn.setStyleSheet(s)

Unfortunately when compiling with qtsass the regular expression in conformers.py line 49 breaks on these. As soon as one replaces the floats with ints all is fine again.

Unfortunately again I have no clue how to make the re accept float values instead of the ints or anything else. It works with variables for instance.

qss_pattern = re.compile(
    r'qlineargradient\('
    r'((?:(?:\s+)?(?:x1|y1|x2|y2):(?:\s+)?[0-9A-Za-z$_-]+,?)+)'  # coords ๐Ÿคทโ€โ™‚๏ธ๐Ÿคทโ€โ™‚๏ธ๐Ÿคทโ€โ™‚๏ธ
    r'((?:(?:\s+)?stop:.*,?)+(?:\s+)?)?'  # stops
    r'\)',
    re.MULTILINE,
)

This is probably an easy one for someone who's into regular expressions?

Update 'collections' imports for Python 3.3+

Hi, from our tests in qdarkstyle, some warnings have been raised asking to change the imports of collections to the new package hierarchy, Python >= 3.3.

lib\site-packages\qtsass\api.py:13: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
    from collections import Sequence, Mapping

-- Docs: https://docs.pytest.org/en/latest/warnings.html

At line:

from collections import Mapping, Sequence

More info: https://docs.python.org/3.4/library/collections.abc.html

If wanted, I can submit a PR :) Tks

QLinear Gradient compilation error

I used this module to build the QT theme engine here https://github.com/KhamisiKibet/QT-PyQt-PySide-Custom-Widgets
Now am trying to add gradient themes but am getting this error:

Traceback (most recent call last):
  File "E:\Spinn TV Tut\modern dashboard\main.py", line 68, in <module>
    window = MainWindow()
  File "E:\Spinn TV Tut\modern dashboard\main.py", line 53, in __init__
    QAppSettings.updateAppSettings(self)
  File "C:\Users\user\anaconda3\lib\site-packages\Custom_Widgets\Widgets.py", line 3048, in updateAppSettings
    CompileStyleSheet.applyCompiledSass(self)
  File "C:\Users\user\anaconda3\lib\site-packages\Custom_Widgets\Qss\SassCompiler.py", line 80, in applyCompiledSass
    qtsass.compile_filename(main_sass_path, css_path)
  File "C:\Users\user\anaconda3\lib\site-packages\qtsass\api.py", line 125, in compile_filename
    css = compile(string, **kwargs)
  File "C:\Users\user\anaconda3\lib\site-packages\qtsass\api.py", line 99, in compile
    return qt_conform(sass.compile(**kwargs))
  File "C:\Users\user\anaconda3\lib\site-packages\sass.py", line 738, in compile
    raise CompileError(v)
sass.CompileError: Error: Invalid CSS after "...gradient(spread": expected expression (e.g. 1px, bold), was ":reflect, x1:0, y1:"
        on line 15:39 of defaultStyle
        from line 5:9 of stdin
>>     background-color: qlineargradient(spread:reflect, x1:0, y1:0, x2:1, y2:1
   --------------------------------------^

[Finished in 1.5s]

My SCSS

background-color: qlineargradient(spread:reflect, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(56, 28, 70, 255), stop:0.522727 rgba(22, 27, 30, 255), stop:1 rgba(36, 33, 100, 255));

Maintainer

Hi @yann-lty thanks for this project. Now, this project seems unmaintained.

I am core developer for spyder-ide and we are planning to use QSS with SASS for version 4.0 (under development) I would really like to update the current library and maintain it.

Would you be ok with this? in which case could we transfer ownership to spyder-ide organization?

Move primary maintainer back to spyder contributors?

At this point I should probably bow out as primary maintainer of this project. I never had time to make a release and probably won't have much time going forward to address issues that may arise.

@goanpeca or someone else who is more familiar with spyder projects generally would make a better primary maintainer. What do you think @goanpeca?

I never felt comfortable making a release as someone peripheral to the spyder organization.

Changelog since 2.2

Now we have version 3.0 released, but I can't find any changelog or summary of the changes since then.
Is there somewhere I can see this without going through years of commit history?

rgba function breaks on incoming 8bit ints

If you write QSS right away you might also want 0 to 255 values as alpha which is not CSS conform!

So the rgba function will turn 128 to 12800%.

... oh while writing this I fixed it already. Had problems with the debugger first. But this is solved now as well ๐ŸŒˆ.
By that way I separated the rgba test functions...

This might also be in the PR, right?

Reorganize qtsass package

QtSass centers around the sass.compile command, I think the organization of the package should reflect this. Going forward this would also provide obvious locations for additional components.

qtsass/
  __init__.py
  __main__.py
  api.py
  conformers.py
  events.py
  functions.py
  importers.py

CLI - build/watch directory

The current CLI only supports building and watching a single sass file. This may be suitable for small projects, but, large projects tend to have more varied structures. For example, a project may have a base stylesheet with dark and light variants.

  • /scss
    • _base.scss
    • dark.scss
    • light.scss

To support the above scenario we should add a CLI option -d/--directory that will compile and watch for changes in all the scss files contained in the directory except for those starting with an underscore. The -d/--directory and the -f/--file options should be mutually exclusive raising an error when both are provided. When using the -d flag the -o flag specifies an output directory for the compiled css.

Valid usages

qtsass -d scss -o css
qtsass -d scss -o css -w
qtsass -f scss/dark.scss -o css/dark.css
qtsass -f scss/dark.scss -o css/dark.css -w

libsass is deprecated

I see that this package depends on sass (which has not been updated since 2014), which in turn depends on libsass. But https://sass-lang.com/libsass says that libsass is deprecated in favour of Dart Sass. So I guess it would be a good long-term plan to migrate this package to use Dart Sass instead (though I don't know whether a Dart Sass version of the Python sass package yet exists).

Just flagging this in case it hadn't been noticed.

Best wishes,

Julian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.