Coder Social home page Coder Social logo

Comments (6)

cpburnz avatar cpburnz commented on July 1, 2024

Hi Robert,

This library provides methods for matching files similar to how a .gitignore functions. It does not implement additional behaviors of git such as scanning descendant directories for .gitignore files.

There is certainly room for improvement with this library. I'm not currently removing blank or commented lines.

My initial thought on how to you could use nested .gitignore files is along the lines of:

import os.path
import pathspec.util

base_path = "..."
all_files = set(pathspec.util.iter_tree_files(base_path))

# Find each ".gitignore" and the files to ignore.
ignore_files = set()
for root, _dirs, files in os.walk(base_path):
    if '.gitignore' in files:
        with open(os.path.join(root, '.gitignore'), 'r', encoding='UTF-8') as fh:
            spec = pathspec.Pathspec.from_lines(fh)

        relative_root = os.path.relpath(root, base_path)
        for path in spec.match_tree_files(root):
            ignore_files.add(os.path.join(relative_root, path))

for path in all_files - ignore_files:
    print(path)
        

from python-pathspec.

bitranox avatar bitranox commented on July 1, 2024

thanks caleb -
I used another project as base for my own solution, check it out :

https://github.com/bitranox/igittigitt
mybe we can bundle our efforts, and merge our projects ?

yours sincerely

Robert

from python-pathspec.

bitranox avatar bitranox commented on July 1, 2024

Dear Caleb,
I looked deeper into the issue, and found that it might be easier to use wcmatch patterns, instead of regexp.
I made a package that supports nested .gitignore Files, provides matching function and provides a ignore function for shutil.copytree():

>>> shutil.copytree(src, dst, ignore=parser.shutil_ignore)

Since You have deep knowledge of the issue, please take a look, and take out what You might need from it.

Thanks for the inspiration !

Robert

from python-pathspec.

cpburnz avatar cpburnz commented on July 1, 2024

@bitranox wcmatch looks interesting. The downside to using it is it would limit this library to only the glob expressions supported by wcmatch. With that in mind, I'm going to stick with regular expressions.

from python-pathspec.

cpburnz avatar cpburnz commented on July 1, 2024

@bitranox Regarding igittigitt, pathspec was a fun proof of concept for matching files using Git's wildmatch. The goal of this project is scaffolding for using different pattern styles (even though only wildmatch is implemented). The goal was not intended to fully emulate Git with .gitignore. Unfortunately, I do not have the time available to devote on another project to any meaningful capacity.

from python-pathspec.

cpburnz avatar cpburnz commented on July 1, 2024

I'm closing this because I think I've answered all of your questions.

from python-pathspec.

Related Issues (20)

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.